Commit | Line | Data |
---|---|---|
897ce52e KB |
1 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
11 | */ | |
12 | ||
13 | #ifndef lint | |
80a47e22 | 14 | static char sccsid[] = "@(#)terminal.c 1.12 (Berkeley) %G%"; |
897ce52e KB |
15 | #endif /* not lint */ |
16 | ||
674388c7 | 17 | #include <arpa/telnet.h> |
115a5494 GM |
18 | #include <sys/types.h> |
19 | ||
20 | #include "ring.h" | |
674388c7 GM |
21 | |
22 | #include "externs.h" | |
23 | #include "types.h" | |
24 | ||
b307f09e GM |
25 | Ring ttyoring, ttyiring; |
26 | char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ]; | |
674388c7 GM |
27 | |
28 | char | |
29 | termEofChar, | |
30 | termEraseChar, | |
31 | termFlushChar, | |
32 | termIntChar, | |
33 | termKillChar, | |
80a47e22 | 34 | #if defined(MSDOS) |
674388c7 | 35 | termLiteralNextChar, |
80a47e22 | 36 | #endif /* defined(MSDOS) */ |
674388c7 GM |
37 | termQuitChar; |
38 | ||
39 | /* | |
40 | * initialize the terminal data structures. | |
41 | */ | |
42 | ||
43 | init_terminal() | |
44 | { | |
80a47e22 GM |
45 | if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) { |
46 | exit(1); | |
47 | } | |
48 | if (ring_init(&ttyiring, ttyibuf, sizeof ttyibuf) != 1) { | |
49 | exit(1); | |
50 | } | |
674388c7 GM |
51 | autoflush = TerminalAutoFlush(); |
52 | } | |
53 | ||
54 | ||
55 | /* | |
56 | * Send as much data as possible to the terminal. | |
57 | * | |
58 | * The return value indicates whether we did any | |
59 | * useful work. | |
60 | */ | |
61 | ||
62 | ||
63 | int | |
d732be39 GM |
64 | ttyflush(drop) |
65 | int drop; | |
674388c7 | 66 | { |
ad1c581e | 67 | register int n, n0, n1; |
674388c7 | 68 | |
ad1c581e GM |
69 | n0 = ring_full_count(&ttyoring); |
70 | if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) { | |
d732be39 | 71 | if (drop) { |
674388c7 GM |
72 | TerminalFlushOutput(); |
73 | /* we leave 'n' alone! */ | |
d732be39 | 74 | } else { |
448f9c06 | 75 | n = TerminalWrite(ttyoring.consume, n); |
674388c7 GM |
76 | } |
77 | } | |
ad1c581e GM |
78 | if (n > 0) { |
79 | /* | |
80 | * If we wrote everything, and the full count is | |
81 | * larger than what we wrote, then write the | |
82 | * rest of the buffer. | |
83 | */ | |
84 | if (n1 == n && n0 > n) { | |
85 | n1 = n0 - n; | |
86 | if (!drop) | |
448f9c06 | 87 | n1 = TerminalWrite(ttyoring.bottom, n1); |
ad1c581e GM |
88 | n += n1; |
89 | } | |
8b6750f5 | 90 | ring_consumed(&ttyoring, n); |
674388c7 GM |
91 | } |
92 | return n > 0; | |
93 | } | |
94 | ||
674388c7 | 95 | \f |
674388c7 GM |
96 | /* |
97 | * These routines decides on what the mode should be (based on the values | |
98 | * of various global variables). | |
99 | */ | |
100 | ||
101 | ||
102 | int | |
103 | getconnmode() | |
104 | { | |
105 | static char newmode[16] = | |
106 | { 4, 5, 3, 3, 2, 2, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6 }; | |
107 | int modeindex = 0; | |
108 | ||
109 | if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) { | |
110 | modeindex += 1; | |
111 | } | |
112 | if (hisopts[TELOPT_ECHO]) { | |
113 | modeindex += 2; | |
114 | } | |
115 | if (hisopts[TELOPT_SGA]) { | |
116 | modeindex += 4; | |
117 | } | |
118 | if (In3270) { | |
119 | modeindex += 8; | |
120 | } | |
121 | return newmode[modeindex]; | |
122 | } | |
123 | ||
124 | void | |
125 | setconnmode() | |
126 | { | |
448f9c06 | 127 | TerminalNewMode(getconnmode()); |
674388c7 GM |
128 | } |
129 | ||
130 | ||
131 | void | |
132 | setcommandmode() | |
133 | { | |
448f9c06 | 134 | TerminalNewMode(0); |
674388c7 | 135 | } |