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 | |
14 | static char sccsid[] = "@(#)terminal.c 1.11 (Berkeley) %G%"; | |
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, | |
34 | termLiteralNextChar, | |
35 | termQuitChar; | |
36 | ||
37 | /* | |
38 | * initialize the terminal data structures. | |
39 | */ | |
40 | ||
41 | init_terminal() | |
42 | { | |
115a5494 | 43 | ring_init(&ttyoring, ttyobuf, sizeof ttyobuf); |
b307f09e | 44 | ring_init(&ttyiring, ttyibuf, sizeof ttyibuf); |
674388c7 GM |
45 | autoflush = TerminalAutoFlush(); |
46 | } | |
47 | ||
48 | ||
49 | /* | |
50 | * Send as much data as possible to the terminal. | |
51 | * | |
52 | * The return value indicates whether we did any | |
53 | * useful work. | |
54 | */ | |
55 | ||
56 | ||
57 | int | |
d732be39 GM |
58 | ttyflush(drop) |
59 | int drop; | |
674388c7 | 60 | { |
ad1c581e | 61 | register int n, n0, n1; |
674388c7 | 62 | |
ad1c581e GM |
63 | n0 = ring_full_count(&ttyoring); |
64 | if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) { | |
d732be39 | 65 | if (drop) { |
674388c7 GM |
66 | TerminalFlushOutput(); |
67 | /* we leave 'n' alone! */ | |
d732be39 | 68 | } else { |
448f9c06 | 69 | n = TerminalWrite(ttyoring.consume, n); |
674388c7 GM |
70 | } |
71 | } | |
ad1c581e GM |
72 | if (n > 0) { |
73 | /* | |
74 | * If we wrote everything, and the full count is | |
75 | * larger than what we wrote, then write the | |
76 | * rest of the buffer. | |
77 | */ | |
78 | if (n1 == n && n0 > n) { | |
79 | n1 = n0 - n; | |
80 | if (!drop) | |
448f9c06 | 81 | n1 = TerminalWrite(ttyoring.bottom, n1); |
ad1c581e GM |
82 | n += n1; |
83 | } | |
8b6750f5 | 84 | ring_consumed(&ttyoring, n); |
674388c7 GM |
85 | } |
86 | return n > 0; | |
87 | } | |
88 | ||
674388c7 | 89 | \f |
674388c7 GM |
90 | /* |
91 | * These routines decides on what the mode should be (based on the values | |
92 | * of various global variables). | |
93 | */ | |
94 | ||
95 | ||
96 | int | |
97 | getconnmode() | |
98 | { | |
99 | static char newmode[16] = | |
100 | { 4, 5, 3, 3, 2, 2, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6 }; | |
101 | int modeindex = 0; | |
102 | ||
103 | if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) { | |
104 | modeindex += 1; | |
105 | } | |
106 | if (hisopts[TELOPT_ECHO]) { | |
107 | modeindex += 2; | |
108 | } | |
109 | if (hisopts[TELOPT_SGA]) { | |
110 | modeindex += 4; | |
111 | } | |
112 | if (In3270) { | |
113 | modeindex += 8; | |
114 | } | |
115 | return newmode[modeindex]; | |
116 | } | |
117 | ||
118 | void | |
119 | setconnmode() | |
120 | { | |
448f9c06 | 121 | TerminalNewMode(getconnmode()); |
674388c7 GM |
122 | } |
123 | ||
124 | ||
125 | void | |
126 | setcommandmode() | |
127 | { | |
448f9c06 | 128 | TerminalNewMode(0); |
674388c7 | 129 | } |