Commit | Line | Data |
---|---|---|
674388c7 | 1 | #include <arpa/telnet.h> |
115a5494 GM |
2 | #include <sys/types.h> |
3 | ||
4 | #include "ring.h" | |
674388c7 GM |
5 | |
6 | #include "externs.h" | |
7 | #include "types.h" | |
8 | ||
b307f09e GM |
9 | Ring ttyoring, ttyiring; |
10 | char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ]; | |
674388c7 GM |
11 | |
12 | char | |
13 | termEofChar, | |
14 | termEraseChar, | |
15 | termFlushChar, | |
16 | termIntChar, | |
17 | termKillChar, | |
18 | termLiteralNextChar, | |
19 | termQuitChar; | |
20 | ||
21 | /* | |
22 | * initialize the terminal data structures. | |
23 | */ | |
24 | ||
25 | init_terminal() | |
26 | { | |
115a5494 | 27 | ring_init(&ttyoring, ttyobuf, sizeof ttyobuf); |
b307f09e | 28 | ring_init(&ttyiring, ttyibuf, sizeof ttyibuf); |
674388c7 GM |
29 | autoflush = TerminalAutoFlush(); |
30 | } | |
31 | ||
32 | ||
33 | /* | |
34 | * Send as much data as possible to the terminal. | |
35 | * | |
36 | * The return value indicates whether we did any | |
37 | * useful work. | |
38 | */ | |
39 | ||
40 | ||
41 | int | |
d732be39 GM |
42 | ttyflush(drop) |
43 | int drop; | |
674388c7 | 44 | { |
ad1c581e | 45 | register int n, n0, n1; |
674388c7 | 46 | |
ad1c581e GM |
47 | n0 = ring_full_count(&ttyoring); |
48 | if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) { | |
d732be39 | 49 | if (drop) { |
674388c7 GM |
50 | TerminalFlushOutput(); |
51 | /* we leave 'n' alone! */ | |
d732be39 | 52 | } else { |
448f9c06 | 53 | n = TerminalWrite(ttyoring.consume, n); |
674388c7 GM |
54 | } |
55 | } | |
ad1c581e GM |
56 | if (n > 0) { |
57 | /* | |
58 | * If we wrote everything, and the full count is | |
59 | * larger than what we wrote, then write the | |
60 | * rest of the buffer. | |
61 | */ | |
62 | if (n1 == n && n0 > n) { | |
63 | n1 = n0 - n; | |
64 | if (!drop) | |
448f9c06 | 65 | n1 = TerminalWrite(ttyoring.bottom, n1); |
ad1c581e GM |
66 | n += n1; |
67 | } | |
8b6750f5 | 68 | ring_consumed(&ttyoring, n); |
674388c7 GM |
69 | } |
70 | return n > 0; | |
71 | } | |
72 | ||
674388c7 | 73 | \f |
674388c7 GM |
74 | /* |
75 | * These routines decides on what the mode should be (based on the values | |
76 | * of various global variables). | |
77 | */ | |
78 | ||
79 | ||
80 | int | |
81 | getconnmode() | |
82 | { | |
83 | static char newmode[16] = | |
84 | { 4, 5, 3, 3, 2, 2, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6 }; | |
85 | int modeindex = 0; | |
86 | ||
87 | if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) { | |
88 | modeindex += 1; | |
89 | } | |
90 | if (hisopts[TELOPT_ECHO]) { | |
91 | modeindex += 2; | |
92 | } | |
93 | if (hisopts[TELOPT_SGA]) { | |
94 | modeindex += 4; | |
95 | } | |
96 | if (In3270) { | |
97 | modeindex += 8; | |
98 | } | |
99 | return newmode[modeindex]; | |
100 | } | |
101 | ||
102 | void | |
103 | setconnmode() | |
104 | { | |
448f9c06 | 105 | TerminalNewMode(getconnmode()); |
674388c7 GM |
106 | } |
107 | ||
108 | ||
109 | void | |
110 | setcommandmode() | |
111 | { | |
448f9c06 | 112 | TerminalNewMode(0); |
674388c7 | 113 | } |