register int i;
register int i, time_select;
in_put(void){    register TScreen *screen = &term->screen;    register int i;    static struct timeval select_timeout;    for( ; ; ) {#ifndef AMOEBA	if (FD_ISSET (screen->respond, &select_mask) && eventMode == NORMAL)#else	if ((bcnt = cb_full(screen->tty_outq)) > 0 && eventMode == NORMAL)#endif	{#ifdef ALLOWLOGGING	    if (screen->logging)		FlushLog(screen);#endif#ifndef AMOEBA	    bcnt = read(screen->respond, (char *)(bptr = VTbuffer), BUF_SIZE);#else	    bptr = VTbuffer;	    if ((bcnt = cb_gets(screen->tty_outq, bptr, bcnt, BUF_SIZE)) == 0) {		errno = EIO;		bcnt = -1;	    }#endif	    if (bcnt <= 0) {/* * Yes, I know this is a majorly f*ugly hack, however it seems to be * necessary for Solaris x86.   DWH 11/15/94 * Dunno why though.. */#if defined(i386) && defined(SVR4) && defined(sun)		if (errno == EIO || errno == 0 )#else		if (errno == EIO)#endif		    Cleanup (0);		else if (!E_TEST(errno))		    Panic(			  "input: read returned unexpected error (%d)\n",			  errno);	    } else if (bcnt == 0)#if defined(MINIX) || defined(__EMX__)		Cleanup(0);#else		Panic("input: read returned zero\n", 0);#endif	    else {		/* read from pty was successful */		if (!screen->output_eight_bits) {		    register int bc = bcnt;		    register Char *b = bptr;		    for (; bc > 0; bc--, b++) {			*b &= (Char) 0x7f;		    }		}		if ( screen->scrollWidget && screen->scrollttyoutput &&		     screen->topline < 0)		    WindowScroll(screen, 0);  /* Scroll to bottom */		pty_read_bytes += bcnt;		/* stop speed reading at some point to look for X stuff */		/* (4096 is just a random large number.) */		if (pty_read_bytes > 4096)		    FD_CLR (screen->respond, &select_mask);		break;	    }	}	pty_read_bytes = 0;	/* update the screen */	if (screen->scroll_amt)	    FlushScroll(screen);	if (screen->cursor_set && (screen->cursor_col != screen->cur_col				   || screen->cursor_row != screen->cur_row)) {	    if (screen->cursor_state)		HideCursor();	    ShowCursor();	} else if (screen->cursor_set != screen->cursor_state) {	    if (screen->cursor_set)		ShowCursor();	    else		HideCursor();	}	XFlush(screen->display); /* always flush writes before waiting */#ifndef AMOEBA	/* Update the masks and, unless X events are already in the queue,	   wait for I/O to be possible. */	XFD_COPYSET (&Select_mask, &select_mask);	if (v_bufptr > v_bufstr) {	    XFD_COPYSET (&pty_mask, &write_mask);	} else	    FD_ZERO (&write_mask);	select_timeout.tv_sec = 0;	/*	 * if there's either an XEvent or an XtTimeout pending, just take	 * a quick peek, i.e. timeout from the select() immediately.  If	 * there's nothing pending, let select() block a little while, but	 * for a shorter interval than the arrow-style scrollbar timeout.	 * The blocking is optional, because it tends to increase the load	 * on the host.	 */	if (XtAppPending(app_con)#if OPT_BLINK_CURS	 || (screen->cursor_blink > 0	  && (screen->select || screen->always_highlight))	 || screen->cursor_state == BLINKED_OFF#endif	 )		select_timeout.tv_usec = 0;	else		select_timeout.tv_usec = 50000;	i = select(max_plus1, &select_mask, &write_mask, 0,			(select_timeout.tv_usec == 0) || screen->awaitInput			? &select_timeout			: 0);	if (i < 0) {	    if (errno != EINTR)		SysError(ERROR_SELECT);	    continue;	}	/* if there is room to write more data to the pty, go write more */	if (FD_ISSET (screen->respond, &write_mask)) {	    v_write(screen->respond, (char *)0, 0); /* flush buffer */	}	/* if there are X events already in our queue, it	   counts as being readable */	if (XtAppPending(app_con) ||	    FD_ISSET (ConnectionNumber(screen->display), &select_mask)) {	    xevents();	}#else  /* AMOEBA */	i = _X11TransAmSelect(ConnectionNumber(screen->display), 1);	/* if there are X events already in our queue,	   it counts as being readable */	if (XtAppPending(app_con) || i > 0) {	    xevents();	    continue;	} else if (i < 0) {	    extern int exiting;	    if (errno != EINTR && !exiting)		SysError(ERROR_SELECT);	}	if (cb_full(screen->tty_outq) <= 0)	    SleepMainThread();#endif /* AMOENA */    }    bcnt--;    return(*bptr++);}