insert mode bug fix and cleanup
[unix-history] / usr / src / usr.bin / window / tth19.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 1983 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 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.
16 */
17
18#ifndef lint
19static char sccsid[] = "@(#)tth19.c 3.22 (Berkeley) %G%";
20#endif /* not lint */
21
22#include "ww.h"
23#include "tt.h"
24
25/*
26kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
27 cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:
28 cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB:
29 ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms:
30 ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:
31 kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:
32 kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:
33 l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:
34 es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
35*/
36
37#define NCOL 80
38#define NROW 24
39
40#define G (WWM_GRP << WWC_MSHIFT)
41short h19_frame[16] = {
42 ' ', '`'|G, 'a'|G, 'e'|G,
43 '`'|G, '`'|G, 'f'|G, 'v'|G,
44 'a'|G, 'd'|G, 'a'|G, 'u'|G,
45 'c'|G, 't'|G, 's'|G, 'b'|G
46};
47
48extern struct tt_str *gen_VS;
49extern struct tt_str *gen_VE;
50
51int h19_msp10c;
52
53#define pc(c) ttputc(c)
54#define esc() pc('\033')
55#define PAD(ms10) { \
56 register i; \
57 for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
58 pc('\0'); \
59}
60#define ICPAD() PAD((NCOL - tt.tt_col) * 1) /* 0.1 ms per char */
61#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
62
63#define H19_SETINSERT(m) (esc(), (tt.tt_insert = (m)) ? pc('@') : pc('O'))
64
65h19_setmodes(new)
66register new;
67{
68 register diff;
69
70 diff = new ^ tt.tt_modes;
71 if (diff & WWM_REV) {
72 esc();
73 if (new & WWM_REV)
74 pc('p');
75 else
76 pc('q');
77 }
78 if (diff & WWM_GRP) {
79 esc();
80 if (new & WWM_GRP)
81 pc('F');
82 else
83 pc('G');
84 }
85 tt.tt_modes = new;
86}
87
88h19_insline(n)
89{
90 while (--n >= 0) {
91 esc();
92 pc('L');
93 ILPAD();
94 }
95}
96
97h19_delline(n)
98{
99 while (--n >= 0) {
100 esc();
101 pc('M');
102 ILPAD();
103 }
104}
105
106h19_putc(c)
107register char c;
108{
109 if (tt.tt_nmodes != tt.tt_modes)
110 (*tt.tt_setmodes)(tt.tt_nmodes);
111 if (tt.tt_insert)
112 H19_SETINSERT(0);
113 pc(c);
114 if (++tt.tt_col == NCOL)
115 tt.tt_col = NCOL - 1;
116}
117
118h19_write(p, n)
119register char *p;
120register n;
121{
122 if (tt.tt_nmodes != tt.tt_modes)
123 (*tt.tt_setmodes)(tt.tt_nmodes);
124 if (tt.tt_insert)
125 H19_SETINSERT(0);
126 ttwrite(p, n);
127 tt.tt_col += n;
128 if (tt.tt_col == NCOL)
129 tt.tt_col = NCOL - 1;
130}
131
132h19_move(row, col)
133register char row, col;
134{
135 if (tt.tt_row == row) {
136 if (tt.tt_col == col)
137 return;
138 if (col == 0) {
139 pc('\r');
140 goto out;
141 }
142 if (tt.tt_col == col - 1) {
143 esc();
144 pc('C');
145 goto out;
146 }
147 if (tt.tt_col == col + 1) {
148 pc('\b');
149 goto out;
150 }
151 }
152 if (tt.tt_col == col) {
153 if (tt.tt_row == row + 1) {
154 esc();
155 pc('A');
156 goto out;
157 }
158 if (tt.tt_row == row - 1) {
159 pc('\n');
160 goto out;
161 }
162 }
163 if (col == 0 && row == 0) {
164 esc();
165 pc('H');
166 goto out;
167 }
168 esc();
169 pc('Y');
170 pc(' ' + row);
171 pc(' ' + col);
172out:
173 tt.tt_col = col;
174 tt.tt_row = row;
175}
176
177h19_start()
178{
179 if (gen_VS)
180 ttxputs(gen_VS);
181 esc();
182 pc('w');
183 esc();
184 pc('E');
185 tt.tt_col = tt.tt_row = 0;
186 tt.tt_insert = 0;
187 tt.tt_nmodes = tt.tt_modes = 0;
188}
189
190h19_end()
191{
192 if (tt.tt_insert)
193 H19_SETINSERT(0);
194 if (gen_VE)
195 ttxputs(gen_VE);
196 esc();
197 pc('v');
198}
199
200h19_clreol()
201{
202 esc();
203 pc('K');
204}
205
206h19_clreos()
207{
208 esc();
209 pc('J');
210}
211
212h19_clear()
213{
214 esc();
215 pc('E');
216}
217
218h19_inschar(c)
219register char c;
220{
221 if (tt.tt_nmodes != tt.tt_modes)
222 (*tt.tt_setmodes)(tt.tt_nmodes);
223 if (!tt.tt_insert)
224 H19_SETINSERT(1);
225 pc(c);
226 if (tt.tt_insert)
227 ICPAD();
228 if (++tt.tt_col == NCOL)
229 tt.tt_col = NCOL - 1;
230}
231
232h19_delchar(n)
233{
234 while (--n >= 0) {
235 esc();
236 pc('N');
237 }
238}
239
240h19_scroll_down(n)
241{
242 h19_move(NROW - 1, 0);
243 while (--n >= 0)
244 pc('\n');
245}
246
247h19_scroll_up(n)
248{
249 h19_move(0, 0);
250 while (--n >= 0) {
251 esc();
252 pc('I');
253 }
254}
255
256tt_h19()
257{
258 float cpms = (float) wwbaud / 10000; /* char per ms */
259
260 h19_msp10c = 10 / cpms; /* ms per 10 char */
261 gen_VS = ttxgetstr("vs");
262 gen_VE = ttxgetstr("ve");
263
264 tt.tt_start = h19_start;
265 tt.tt_end = h19_end;
266
267 tt.tt_insline = h19_insline;
268 tt.tt_delline = h19_delline;
269 tt.tt_inschar = h19_inschar;
270 tt.tt_delchar = h19_delchar;
271 tt.tt_clreol = h19_clreol;
272 tt.tt_clreos = h19_clreos;
273 tt.tt_clear = h19_clear;
274 tt.tt_move = h19_move;
275 tt.tt_write = h19_write;
276 tt.tt_putc = h19_putc;
277 tt.tt_scroll_down = h19_scroll_down;
278 tt.tt_scroll_up = h19_scroll_up;
279 tt.tt_setmodes = h19_setmodes;
280
281 tt.tt_ncol = NCOL;
282 tt.tt_nrow = NROW;
283 tt.tt_availmodes = WWM_REV|WWM_GRP;
284 tt.tt_frame = h19_frame;
285 return 0;
286}