1*33686Sbostic /* 2*33686Sbostic * Copyright (c) 1988 Regents of the University of California. 3*33686Sbostic * All rights reserved. 4*33686Sbostic * 5*33686Sbostic * Redistribution and use in source and binary forms are permitted 6*33686Sbostic * provided that this notice is preserved and that due credit is given 7*33686Sbostic * to the University of California at Berkeley. The name of the University 8*33686Sbostic * may not be used to endorse or promote products derived from this 9*33686Sbostic * software without specific prior written permission. This software 10*33686Sbostic * is provided ``as is'' without express or implied warranty. 11*33686Sbostic */ 12*33686Sbostic 13*33686Sbostic #ifndef lint 14*33686Sbostic static char sccsid[] = "@(#)terminal.c 1.11 (Berkeley) 03/08/88"; 15*33686Sbostic #endif /* not lint */ 16*33686Sbostic 1732148Sminshall #include <arpa/telnet.h> 1832381Sminshall #include <sys/types.h> 1932148Sminshall 2032381Sminshall #include "ring.h" 2132381Sminshall 2232148Sminshall #include "externs.h" 2332148Sminshall #include "types.h" 2432148Sminshall 2532531Sminshall Ring ttyoring, ttyiring; 2632531Sminshall char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ]; 2732148Sminshall 2832148Sminshall char 2932148Sminshall termEofChar, 3032148Sminshall termEraseChar, 3132148Sminshall termFlushChar, 3232148Sminshall termIntChar, 3332148Sminshall termKillChar, 3432148Sminshall termLiteralNextChar, 3532148Sminshall termQuitChar; 3632148Sminshall 3732148Sminshall /* 3832148Sminshall * initialize the terminal data structures. 3932148Sminshall */ 4032148Sminshall 4132148Sminshall init_terminal() 4232148Sminshall { 4332381Sminshall ring_init(&ttyoring, ttyobuf, sizeof ttyobuf); 4432531Sminshall ring_init(&ttyiring, ttyibuf, sizeof ttyibuf); 4532148Sminshall autoflush = TerminalAutoFlush(); 4632148Sminshall } 4732148Sminshall 4832148Sminshall 4932148Sminshall /* 5032148Sminshall * Send as much data as possible to the terminal. 5132148Sminshall * 5232148Sminshall * The return value indicates whether we did any 5332148Sminshall * useful work. 5432148Sminshall */ 5532148Sminshall 5632148Sminshall 5732148Sminshall int 5832257Sminshall ttyflush(drop) 5932257Sminshall int drop; 6032148Sminshall { 6132667Sminshall register int n, n0, n1; 6232148Sminshall 6332667Sminshall n0 = ring_full_count(&ttyoring); 6432667Sminshall if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) { 6532257Sminshall if (drop) { 6632148Sminshall TerminalFlushOutput(); 6732148Sminshall /* we leave 'n' alone! */ 6832257Sminshall } else { 6933286Sminshall n = TerminalWrite(ttyoring.consume, n); 7032148Sminshall } 7132148Sminshall } 7232667Sminshall if (n > 0) { 7332667Sminshall /* 7432667Sminshall * If we wrote everything, and the full count is 7532667Sminshall * larger than what we wrote, then write the 7632667Sminshall * rest of the buffer. 7732667Sminshall */ 7832667Sminshall if (n1 == n && n0 > n) { 7932667Sminshall n1 = n0 - n; 8032667Sminshall if (!drop) 8133286Sminshall n1 = TerminalWrite(ttyoring.bottom, n1); 8232667Sminshall n += n1; 8332667Sminshall } 8432528Sminshall ring_consumed(&ttyoring, n); 8532148Sminshall } 8632148Sminshall return n > 0; 8732148Sminshall } 8832148Sminshall 8932148Sminshall 9032148Sminshall /* 9132148Sminshall * These routines decides on what the mode should be (based on the values 9232148Sminshall * of various global variables). 9332148Sminshall */ 9432148Sminshall 9532148Sminshall 9632148Sminshall int 9732148Sminshall getconnmode() 9832148Sminshall { 9932148Sminshall static char newmode[16] = 10032148Sminshall { 4, 5, 3, 3, 2, 2, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6 }; 10132148Sminshall int modeindex = 0; 10232148Sminshall 10332148Sminshall if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) { 10432148Sminshall modeindex += 1; 10532148Sminshall } 10632148Sminshall if (hisopts[TELOPT_ECHO]) { 10732148Sminshall modeindex += 2; 10832148Sminshall } 10932148Sminshall if (hisopts[TELOPT_SGA]) { 11032148Sminshall modeindex += 4; 11132148Sminshall } 11232148Sminshall if (In3270) { 11332148Sminshall modeindex += 8; 11432148Sminshall } 11532148Sminshall return newmode[modeindex]; 11632148Sminshall } 11732148Sminshall 11832148Sminshall void 11932148Sminshall setconnmode() 12032148Sminshall { 12133286Sminshall TerminalNewMode(getconnmode()); 12232148Sminshall } 12332148Sminshall 12432148Sminshall 12532148Sminshall void 12632148Sminshall setcommandmode() 12732148Sminshall { 12833286Sminshall TerminalNewMode(0); 12932148Sminshall } 130