if(Tbcnt-- <= 0) {
if(Tbuffer->cnt-- <= 0) {
static int Tinput(void){	register TScreen *screen = &term->screen;	register int i;	register TekLink *tek;	if(Tpushback > Tpushb)		return(*--Tpushback);	if(TekRefresh) {		if(rcnt-- > 0)			return(*rptr++);		if ((tek = TekRefresh->next) != 0) {			TekRefresh = tek;			rptr = tek->data;			rcnt = tek->count - 1;			TekSetFontSize(tek->fontsize);			return(*rptr++);		}		TekRefresh = (TekLink *)0;		longjmp(Tekjump, 1);	}again:	if(Tbcnt-- <= 0) {		if(nplot > 0)	/* flush line Tbuffer */			TekFlush();		XFD_COPYSET (&pty_mask, &Tselect_mask);		for( ; ; ) {#ifdef CRAY			struct timeval crocktimeout;			crocktimeout.tv_sec = 0;			crocktimeout.tv_usec = 0;			(void) Select (max_plus1, 				       &Tselect_mask, NULL, NULL, 				       &crocktimeout);#endif#ifndef AMOEBA			if(FD_ISSET (screen->respond, &Tselect_mask))#else			/* XXX resolve polling since it wastes CPU cycles */			if ((Tbcnt = cb_full(screen->tty_outq)) > 0)#endif /* AMOEBA */			{#ifdef ALLOWLOGGING				if(screen->logging)					FlushLog(screen);#endif#ifndef AMOEBA				Tbcnt = read(screen->respond, (char *)(Tbptr = Tbuffer), BUF_SIZE);#else				Tbptr = Tbuffer;				if ((Tbcnt = cb_gets(screen->tty_outq, Tbptr, Tbcnt, BUF_SIZE)) == 0) {					errno = EIO;					Tbcnt = -1;				}#endif /* AMOEBA */				if(Tbcnt < 0) {					if(errno == EIO)						Cleanup (0);					else if(!E_TEST(errno))						Panic(				 "Tinput:read returned unexpected error (%d)\n",						 errno);				} else if(Tbcnt == 0)#ifdef MINIX					Cleanup (0);#else					Panic("input: read returned zero\n", 0);#endif				else {				    if (!screen->output_eight_bits) {					register int bc = Tbcnt;					register Char *b = Tbptr;					for (; bc > 0; bc--, b++) {					    *b &= (Char) 0x7f;					}				    }					break;				}			}			if (Ttoggled && curstate == Talptable) {				TCursorToggle(TOGGLE);				Ttoggled = FALSE;			}#ifndef AMOEBA			if(XtAppPending(app_con) & XtIMXEvent) {				XFD_COPYSET (&X_mask, &Tselect_mask);			} else {				XFlush(screen->display);				XFD_COPYSET (&Select_mask, &Tselect_mask);				if((i = Select(max_plus1, 					       &Tselect_mask, NULL, NULL, 					       NULL)) < 0){					if (errno != EINTR)						SysError(ERROR_TSELECT);					continue;				}			}#else			XFlush(screen->display);			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 (Tbcnt > 0)				goto again;			if (cb_full(screen->tty_outq) <= 0)				SleepMainThread();#endif /* AMOEBA */			if(FD_ISSET (ConnectionNumber (screen->display), &Tselect_mask)) {				xevents();				if(Tbcnt > 0)					goto again;			}		}		Tbcnt--;		if (!Ttoggled && curstate == Talptable) {			TCursorToggle(TOGGLE);			Ttoggled = TRUE;		}	}	tek = TekRecord;	if(tek->count >= TEK_LINK_BLOCK_SIZE	   || tek->fontsize != screen->cur.fontsize) {		if((TekRecord = tek->next = (TekLink *)malloc(sizeof(TekLink)))		 == (TekLink *)0)			Panic("Tinput: malloc error (%d)\n", errno);		tek = tek->next;		tek->next = (TekLink *)0;		tek->fontsize = screen->cur.fontsize;		tek->count = 0;		tek->ptr = tek->data;	}	tek->count++;	return(*tek->ptr++ = *Tbptr++);}