]> git.saurik.com Git - apple/shell_cmds.git/blob - window/tth19.c
fa16b68ca781e88c7efb5b5f3cf2676189b57e84
[apple/shell_cmds.git] / window / tth19.c
1 /* $NetBSD: tth19.c,v 1.4 1997/11/21 08:36:30 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 #ifndef lint
41 #if 0
42 static char sccsid[] = "@(#)tth19.c 8.1 (Berkeley) 6/6/93";
43 #else
44 __RCSID("$NetBSD: tth19.c,v 1.4 1997/11/21 08:36:30 lukem Exp $");
45 #endif
46 #endif /* not lint */
47
48 #include "ww.h"
49 #include "tt.h"
50 #include "char.h"
51
52 /*
53 kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
54 cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:
55 cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB:
56 ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms:
57 ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:
58 kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:
59 kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:
60 l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:
61 es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
62 */
63
64 #define NCOL 80
65 #define NROW 24
66
67 #define G (WWM_GRP << WWC_MSHIFT)
68 short h19_frame[16] = {
69 ' ', '`'|G, 'a'|G, 'e'|G,
70 '`'|G, '`'|G, 'f'|G, 'v'|G,
71 'a'|G, 'd'|G, 'a'|G, 'u'|G,
72 'c'|G, 't'|G, 's'|G, 'b'|G
73 };
74
75 extern struct tt_str *gen_VS;
76 extern struct tt_str *gen_VE;
77
78 int h19_msp10c;
79
80 #define PAD(ms10) { \
81 int i; \
82 for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
83 ttputc('\0'); \
84 }
85 #define ICPAD() PAD((NCOL - tt.tt_col) * 1) /* 0.1 ms per char */
86 #define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
87
88 #define H19_SETINSERT(m) ttesc((tt.tt_insert = (m)) ? '@' : 'O')
89
90 void h19_clear __P((void));
91 void h19_clreol __P((void));
92 void h19_clreos __P((void));
93 void h19_delchar __P((int));
94 void h19_delline __P((int));
95 void h19_end __P((void));
96 void h19_inschar __P((char));
97 void h19_insline __P((int));
98 void h19_move __P((int, int));
99 void h19_putc __P((char));
100 void h19_scroll_up __P((int));
101 void h19_scroll_down __P((int));
102 void h19_setmodes __P((int));
103 void h19_start __P((void));
104 void h19_write __P((char *, int));
105
106 void
107 h19_setmodes(new)
108 int new;
109 {
110 int diff;
111
112 diff = new ^ tt.tt_modes;
113 if (diff & WWM_REV)
114 ttesc(new & WWM_REV ? 'p' : 'q');
115 if (diff & WWM_GRP)
116 ttesc(new & WWM_REV ? 'F' : 'G');
117 tt.tt_modes = new;
118 }
119
120 void
121 h19_insline(n)
122 int n;
123 {
124 while (--n >= 0) {
125 ttesc('L');
126 ILPAD();
127 }
128 }
129
130 void
131 h19_delline(n)
132 int n;
133 {
134 while (--n >= 0) {
135 ttesc('M');
136 ILPAD();
137 }
138 }
139
140 void
141 h19_putc(c)
142 char c;
143 {
144 if (tt.tt_nmodes != tt.tt_modes)
145 (*tt.tt_setmodes)(tt.tt_nmodes);
146 if (tt.tt_insert)
147 H19_SETINSERT(0);
148 ttputc(c);
149 if (++tt.tt_col == NCOL)
150 tt.tt_col = NCOL - 1;
151 }
152
153 void
154 h19_write(p, n)
155 char *p;
156 int n;
157 {
158 if (tt.tt_nmodes != tt.tt_modes)
159 (*tt.tt_setmodes)(tt.tt_nmodes);
160 if (tt.tt_insert)
161 H19_SETINSERT(0);
162 ttwrite(p, n);
163 tt.tt_col += n;
164 if (tt.tt_col == NCOL)
165 tt.tt_col = NCOL - 1;
166 }
167
168 void
169 h19_move(row, col)
170 int row, col;
171 {
172 if (tt.tt_row == row) {
173 if (tt.tt_col == col)
174 return;
175 if (col == 0) {
176 ttctrl('m');
177 goto out;
178 }
179 if (tt.tt_col == col - 1) {
180 ttesc('C');
181 goto out;
182 }
183 if (tt.tt_col == col + 1) {
184 ttctrl('h');
185 goto out;
186 }
187 }
188 if (tt.tt_col == col) {
189 if (tt.tt_row == row + 1) {
190 ttesc('A');
191 goto out;
192 }
193 if (tt.tt_row == row - 1) {
194 ttctrl('j');
195 goto out;
196 }
197 }
198 if (col == 0 && row == 0) {
199 ttesc('H');
200 goto out;
201 }
202 ttesc('Y');
203 ttputc(' ' + row);
204 ttputc(' ' + col);
205 out:
206 tt.tt_col = col;
207 tt.tt_row = row;
208 }
209
210 void
211 h19_start()
212 {
213 if (gen_VS)
214 ttxputs(gen_VS);
215 ttesc('w');
216 ttesc('E');
217 tt.tt_col = tt.tt_row = 0;
218 tt.tt_insert = 0;
219 tt.tt_nmodes = tt.tt_modes = 0;
220 }
221
222 void
223 h19_end()
224 {
225 if (tt.tt_insert)
226 H19_SETINSERT(0);
227 if (gen_VE)
228 ttxputs(gen_VE);
229 ttesc('v');
230 }
231
232 void
233 h19_clreol()
234 {
235 ttesc('K');
236 }
237
238 void
239 h19_clreos()
240 {
241 ttesc('J');
242 }
243
244 void
245 h19_clear()
246 {
247 ttesc('E');
248 }
249
250 void
251 h19_inschar(c)
252 char c;
253 {
254 if (tt.tt_nmodes != tt.tt_modes)
255 (*tt.tt_setmodes)(tt.tt_nmodes);
256 if (!tt.tt_insert)
257 H19_SETINSERT(1);
258 ttputc(c);
259 if (tt.tt_insert)
260 ICPAD();
261 if (++tt.tt_col == NCOL)
262 tt.tt_col = NCOL - 1;
263 }
264
265 void
266 h19_delchar(n)
267 int n;
268 {
269 while (--n >= 0)
270 ttesc('N');
271 }
272
273 void
274 h19_scroll_down(n)
275 int n;
276 {
277 h19_move(NROW - 1, 0);
278 while (--n >= 0)
279 ttctrl('j');
280 }
281
282 void
283 h19_scroll_up(n)
284 int n;
285 {
286 h19_move(0, 0);
287 while (--n >= 0)
288 ttesc('I');
289 }
290
291 int
292 tt_h19()
293 {
294 float cpms = (float) wwbaud / 10000; /* char per ms */
295
296 h19_msp10c = 10 / cpms; /* ms per 10 char */
297 gen_VS = ttxgetstr("vs");
298 gen_VE = ttxgetstr("ve");
299
300 tt.tt_start = h19_start;
301 tt.tt_end = h19_end;
302
303 tt.tt_insline = h19_insline;
304 tt.tt_delline = h19_delline;
305 tt.tt_inschar = h19_inschar;
306 tt.tt_delchar = h19_delchar;
307 tt.tt_clreol = h19_clreol;
308 tt.tt_clreos = h19_clreos;
309 tt.tt_clear = h19_clear;
310 tt.tt_move = h19_move;
311 tt.tt_write = h19_write;
312 tt.tt_putc = h19_putc;
313 tt.tt_scroll_down = h19_scroll_down;
314 tt.tt_scroll_up = h19_scroll_up;
315 tt.tt_setmodes = h19_setmodes;
316
317 tt.tt_ncol = NCOL;
318 tt.tt_nrow = NROW;
319 tt.tt_availmodes = WWM_REV|WWM_GRP;
320 tt.tt_frame = h19_frame;
321 return 0;
322 }