Example #1
0
static int Fetch_Buf()
{
	REBCNT len = LEN_BYTES(inbuf);

	Std_IO_Req.common.data = inbuf + len;
	Std_IO_Req.length = inbuf_len - len - 1;
	Std_IO_Req.actual = 0;

	OS_Do_Device(&Std_IO_Req, RDC_READ);

	// If error, don't crash, just ignore it:
	if (Std_IO_Req.error) return 0; //Host_Crash("stdio read");

	// Terminate (LF) last line?
	if (len > 0 && Std_IO_Req.actual == 0) {
		inbuf[len++] = LF;
		inbuf[len] = 0;
		return TRUE;
	}

	// Null terminate buffer:
	len = Std_IO_Req.actual;
	Std_IO_Req.common.data[len] = 0;
	return len > 0;
}
Example #2
0
*/	void Put_Str(REBYTE *buf)
/*
**		Outputs a null terminated UTF-8 string.
**		If buf is larger than StdIO Device allows, error out.
**		OS dependent line termination must be done prior to call.
**
**		!!! A request should ideally have a way to enforce that it is not
**		going to modify the data.  We currently require the caller to
**		pass us data that could be written to, but "promise not to"
**		since it is a RDC_WRITE operation.  To stay on the right side
**		of the compiler, use a strdup()/free() instead of an m_cast.
**
***********************************************************************/
{
	/* This function could be called by signal handler and inside of Fetch_Buf */
	REBREQ req;
	memcpy(&req, &Std_IO_Req, sizeof(req));

	req.length = LEN_BYTES(buf);
	req.common.data = buf;
	req.actual = 0;

	OS_Do_Device(&req, RDC_WRITE);

	if (req.error) Host_Crash("stdio write");
}
Example #3
0
*/	void Put_Str(REBYTE *buf)
/*
**		Outputs a null terminated UTF-8 string.
**		If buf is larger than StdIO Device allows, error out.
**		OS dependent line termination must be done prior to call.
**
***********************************************************************/
{
	Std_IO_Req.length = strlen(buf);
	Std_IO_Req.data = (REBYTE*)buf;
	Std_IO_Req.actual = 0;

	OS_Do_Device(&Std_IO_Req, RDC_WRITE);

	if (Std_IO_Req.error) Host_Crash("stdio write");
}
Example #4
0
*/	REBINT OS_Wait(REBCNT millisec, REBCNT res)
/*
**		Check if devices need attention, and if not, then wait.
**		The wait can be interrupted by a GUI event, otherwise
**		the timeout will wake it.
**
**		Res specifies resolution. (No wait if less than this.)
**
**		Returns:
**			-1: Devices have changed state.
**		     0: past given millsecs
**			 1: wait in timer
**
**		The time it takes for the devices to be scanned is
**		subtracted from the timer value.
**
***********************************************************************/
{
	REBREQ req;		// OK: QUERY below does not store it
	REBCNT delta;
	i64 base;

	// printf("OS_Wait %d\n", millisec);

	base = OS_Delta_Time(0, 0); // start timing

	// Setup for timing:
	CLEARS(&req);
	req.device = RDI_EVENT;

	// Let any pending device I/O have a chance to run:
	if (OS_Poll_Devices()) return -1;

	// Nothing, so wait for period of time
	delta = (REBCNT)OS_Delta_Time(base, 0)/1000 + res;
	if (delta >= millisec) return 0;
	millisec -= delta;  // account for time lost above
	req.length = millisec;

	// printf("Wait: %d ms\n", millisec);
	OS_Do_Device(&req, RDC_QUERY); // wait for timer or other event

	return 1;  // layer above should check delta again
}
Example #5
0
*/	void Open_StdIO(void)
/*
**		Open REBOL's standard IO device. This same device is used
**		by both the host code and the R3 DLL itself.
**
**		This must be done before any other initialization is done
**		in order to output banners or errors.
**
***********************************************************************/
{
	CLEARS(&Std_IO_Req);
	Std_IO_Req.clen = sizeof(Std_IO_Req);
	Std_IO_Req.device = RDI_STDIO;

	OS_Do_Device(&Std_IO_Req, RDC_OPEN);

	if (Std_IO_Req.error) Host_Crash("stdio open");

	inbuf = OS_ALLOC_ARRAY(REBYTE, inbuf_len);
	inbuf[0] = 0;
}