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