Exemplo n.º 1
0
/*
**	spin_flush()
**
**	Wait for the input stream to stop.
**	Throw away all input characters.
*/
void
spin_flush(void)
{
	unsigned char buf[64];

	fflush(stdout);
	event_start(TIME_FLUSH);	/* start the timer */
	do {
		if (char_ready()) {
			(void) read(fileno(stdin), &buf, sizeof(buf));
		}
	} while (event_time(TIME_FLUSH) < 400000);
}
Exemplo n.º 2
0
/*
**	read_key(input-buffer, length-of-buffer)
**
**	read one function key from the input stream.
**	A null character is converted to 0x80.
*/
void 
read_key(char *buf, int max)
{
	int got, ask, i, l;
	char *s;

	*buf = '\0';
	s = buf;
	fflush(stdout);
	/* ATT unix may return 0 or 1, Berkeley Unix should be 1 */
	while (read(fileno(stdin), s, 1) == 0);
	++s;
	--max;
	while (max > 0 && (ask = char_ready())) {
		if (ask > max) {
			ask = max;
		}
		if ((got = read(fileno(stdin), s, (unsigned) ask))) {
			s += got;
		} else {
			break;
		}
		max -= got;
	}
	*s = '\0';
	l = s - buf;
	for (s = buf, i = 0; i < l; i++) {
		if ((*s & 0x7f) == 0) {
			/* convert nulls to 0x80 */
			*(unsigned char *)s = 128;
		} else {
			/* strip high order bits (if any) */
			*s &= char_mask;
		}
	}
}
Exemplo n.º 3
0
void get_nowait( void )
{
	extern char * const init_source[];
	static char * const *source_block = init_source;
	static char *source_char;
	static char inbuf[INBUFSZ];
	static char *ibp;
	static char *const inbuf_source[] = { inbuf, 0 };
	
	flag = 1;	/* assume success */
	
	if( abort_input ) {
		have_ungotten = 0;
		source_block = inbuf_source + 1;	/* null */
		ibp = 0;
		abort_input = 0;
	}
	
	if( have_ungotten ) {
		*--sp = ungotten;
		have_ungotten = 0;
		return;
	}
	
	while( *source_block ) {		/* get input from memory */
	
		if( !source_char ) {		/* point to start of block */
			source_char = *source_block;
		}
		
		if( *source_char ) {		/* hey, we got one! */
			*--sp = *source_char++;
			return;
		}
		
		/* 
		at this point, we have a null character, so
		attempt to move to next block.
		*/
		
		source_block += 1;
		source_char = 0;
	}
	
		
	/* If we get here, there is no more input in memory,
	so grab a line from the input stream */
				
	if( ibp == 0 ) {	/* start new line */
		ibp = inbuf;
		if( FlowPrompt >= 0 ) writechar( FlowPrompt );
	}
	
	if( char_ready() ) {
		char c = readchar();
			
		if( c == '\n' ) {	/* end of line */
			*ibp++ = c;
			*ibp++ = 0;
			ibp = 0;
			source_block = inbuf_source;
			get_nowait();	/* tail recursion */
			return;
		}
		
		/* if we reach here, we won't have a char to return */
		
		flag = 0;
			
		if( c == '\b' ) {
			writechar( ' ' );
			if( ibp > inbuf ) {	/* backspace, erase last */
				writechar( '\b' );
				ibp -= 1;
			}
			return;
		}
			
		if( ibp >= inbuf + INBUFSZ - 3 ) {	/* buffer full */
			writechar( 7 );			/* bell */
			return;
		}
			
		*ibp++ = c;
	}
	
	flag = 0;	/* fail */
}