Commit | Line | Data |
---|---|---|
674388c7 GM |
1 | #include <arpa/telnet.h> |
2 | ||
3 | #include "externs.h" | |
4 | #include "types.h" | |
5 | ||
6 | char ttyobuf[2*BUFSIZ], *tfrontp, *tbackp; | |
7 | ||
8 | char | |
9 | termEofChar, | |
10 | termEraseChar, | |
11 | termFlushChar, | |
12 | termIntChar, | |
13 | termKillChar, | |
14 | termLiteralNextChar, | |
15 | termQuitChar; | |
16 | ||
17 | /* | |
18 | * initialize the terminal data structures. | |
19 | */ | |
20 | ||
21 | init_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 | ||
36 | int | |
d732be39 GM |
37 | ttyflush(drop) |
38 | int 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 | ||
65 | void | |
66 | deadpeer() | |
67 | { | |
68 | setcommandmode(); | |
69 | longjmp(peerdied, -1); | |
70 | } | |
71 | ||
72 | void | |
73 | intr() | |
74 | { | |
75 | if (localchars) { | |
76 | intp(); | |
77 | return; | |
78 | } | |
79 | setcommandmode(); | |
80 | longjmp(toplevel, -1); | |
81 | } | |
82 | ||
83 | void | |
84 | intr2() | |
85 | { | |
86 | if (localchars) { | |
87 | sendbrk(); | |
88 | return; | |
89 | } | |
90 | } | |
91 | ||
92 | void | |
93 | doescape() | |
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 | ||
105 | int | |
106 | getconnmode() | |
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 | ||
127 | void | |
128 | setconnmode() | |
129 | { | |
130 | TerminalNewMode(tin, tout, getconnmode()); | |
131 | } | |
132 | ||
133 | ||
134 | void | |
135 | setcommandmode() | |
136 | { | |
137 | TerminalNewMode(tin, tout, 0); | |
138 | } |