Cut down on number of extern's.
[unix-history] / usr / src / usr.bin / telnet / terminal.c
CommitLineData
674388c7
GM
1#include <arpa/telnet.h>
2
3#include "externs.h"
4#include "types.h"
5
6char ttyobuf[2*BUFSIZ], *tfrontp, *tbackp;
7
8char
9 termEofChar,
10 termEraseChar,
11 termFlushChar,
12 termIntChar,
13 termKillChar,
14 termLiteralNextChar,
15 termQuitChar;
16
17/*
18 * initialize the terminal data structures.
19 */
20
21init_terminal()
22{
23 tfrontp = tbackp = ttyobuf;
24 autoflush = TerminalAutoFlush();
25}
26
27
28/*
29 * Send as much data as possible to the terminal.
30 *
31 * The return value indicates whether we did any
32 * useful work.
33 */
34
35
36int
d732be39
GM
37ttyflush(drop)
38int drop;
674388c7
GM
39{
40 int n;
41
42 if ((n = tfrontp - tbackp) > 0) {
d732be39 43 if (drop) {
674388c7
GM
44 TerminalFlushOutput();
45 /* we leave 'n' alone! */
d732be39
GM
46 } else {
47 n = TerminalWrite(tout, tbackp, n);
674388c7
GM
48 }
49 }
50 if (n >= 0) {
51 tbackp += n;
52 if (tbackp == tfrontp) {
53 tbackp = tfrontp = ttyobuf;
54 }
55 }
56 return n > 0;
57}
58
674388c7
GM
59\f
60#if defined(unix)
61/*
62 * Various signal handling routines.
63 */
64
65void
66deadpeer()
67{
68 setcommandmode();
69 longjmp(peerdied, -1);
70}
71
72void
73intr()
74{
75 if (localchars) {
76 intp();
77 return;
78 }
79 setcommandmode();
80 longjmp(toplevel, -1);
81}
82
83void
84intr2()
85{
86 if (localchars) {
87 sendbrk();
88 return;
89 }
90}
91
92void
93doescape()
94{
95 command(0);
96}
97#endif /* defined(unix) */
98\f
99/*
100 * These routines decides on what the mode should be (based on the values
101 * of various global variables).
102 */
103
104
105int
106getconnmode()
107{
108 static char newmode[16] =
109 { 4, 5, 3, 3, 2, 2, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6 };
110 int modeindex = 0;
111
112 if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
113 modeindex += 1;
114 }
115 if (hisopts[TELOPT_ECHO]) {
116 modeindex += 2;
117 }
118 if (hisopts[TELOPT_SGA]) {
119 modeindex += 4;
120 }
121 if (In3270) {
122 modeindex += 8;
123 }
124 return newmode[modeindex];
125}
126
127void
128setconnmode()
129{
130 TerminalNewMode(tin, tout, getconnmode());
131}
132
133
134void
135setcommandmode()
136{
137 TerminalNewMode(tin, tout, 0);
138}