Commit | Line | Data |
---|---|---|
73f690a1 | 1 | #ifndef lint |
ff3a53e4 | 2 | static char sccsid[] = "@(#)ttgeneric.c 3.30 %G%"; |
73f690a1 EW |
3 | #endif |
4 | ||
60de5df9 EW |
5 | /* |
6 | * Copyright (c) 1983 Regents of the University of California, | |
7 | * All rights reserved. Redistribution permitted subject to | |
8 | * the terms of the Berkeley Software License Agreement. | |
9 | */ | |
10 | ||
73f690a1 | 11 | #include "ww.h" |
fff1d01b | 12 | #include "tt.h" |
73f690a1 | 13 | |
769cbf09 EW |
14 | char PC, *BC, *UP; |
15 | short ospeed; | |
94c16993 | 16 | |
a6a7cd35 | 17 | /* normal frame */ |
a830e8bb | 18 | short gen_frame[16] = { |
73f690a1 EW |
19 | ' ', '|', '-', '+', |
20 | '|', '|', '+', '+', | |
fff1d01b | 21 | '-', '+', '-', '+', |
73f690a1 EW |
22 | '+', '+', '+', '+' |
23 | }; | |
24 | ||
a6a7cd35 EW |
25 | /* ANSI graphics frame */ |
26 | #define G (WWM_GRP << WWC_MSHIFT) | |
27 | short ansi_frame[16] = { | |
28 | ' ', 'x'|G, 'Q'|G, 'm'|G, | |
29 | 'x'|G, 'x'|G, 'l'|G, 't'|G, | |
30 | 'q'|G, 'j'|G, 'q'|G, 'v'|G, | |
31 | 'k'|G, 'u'|G, 'w'|G, 'n'|G | |
32 | }; | |
b16d80c6 EW |
33 | struct tt_str ansi_AS = { |
34 | "\033(0", 3 | |
35 | }; | |
a6a7cd35 | 36 | |
e1daf7d6 EW |
37 | struct tt_str *gen_CM; |
38 | struct tt_str *gen_IM; | |
39 | struct tt_str *gen_IC; | |
40 | struct tt_str *gen_IP; | |
41 | struct tt_str *gen_EI; | |
42 | struct tt_str *gen_DC; | |
43 | struct tt_str *gen_AL; | |
44 | struct tt_str *gen_DL; | |
45 | struct tt_str *gen_CE; | |
46 | struct tt_str *gen_CD; | |
47 | struct tt_str *gen_CL; | |
48 | struct tt_str *gen_VS; | |
49 | struct tt_str *gen_VE; | |
50 | struct tt_str *gen_TI; | |
51 | struct tt_str *gen_TE; | |
52 | struct tt_str *gen_SO; | |
53 | struct tt_str *gen_SE; | |
54 | struct tt_str *gen_US; | |
55 | struct tt_str *gen_UE; | |
56 | struct tt_str *gen_UP; | |
57 | struct tt_str *gen_PC; | |
58 | struct tt_str *gen_BC; | |
59 | struct tt_str *gen_ND; | |
60 | struct tt_str *gen_HO; | |
61 | struct tt_str *gen_NL; | |
62 | struct tt_str *gen_AS; | |
63 | struct tt_str *gen_AE; | |
a6833679 EW |
64 | struct tt_str *gen_XS; |
65 | struct tt_str *gen_XE; | |
745d1a08 EW |
66 | char gen_MI; |
67 | char gen_MS; | |
68 | char gen_AM; | |
69 | char gen_OS; | |
70 | char gen_BS; | |
377a2410 | 71 | char gen_DB; |
b16d80c6 | 72 | char gen_XN; |
745d1a08 EW |
73 | int gen_CO; |
74 | int gen_LI; | |
3babdf29 EW |
75 | int gen_UG; |
76 | int gen_SG; | |
745d1a08 | 77 | |
73f690a1 EW |
78 | gen_setinsert(new) |
79 | char new; | |
80 | { | |
745d1a08 EW |
81 | if (new) { |
82 | if (gen_IM) | |
e1daf7d6 | 83 | ttxputs(gen_IM); |
745d1a08 EW |
84 | } else |
85 | if (gen_EI) | |
e1daf7d6 | 86 | ttxputs(gen_EI); |
3130283e | 87 | tt.tt_insert = new; |
73f690a1 EW |
88 | } |
89 | ||
90 | gen_setmodes(new) | |
745d1a08 | 91 | register new; |
73f690a1 | 92 | { |
745d1a08 EW |
93 | register diff; |
94 | ||
3130283e | 95 | diff = new ^ tt.tt_modes; |
745d1a08 EW |
96 | if (diff & WWM_REV) { |
97 | if (new & WWM_REV) { | |
98 | if (gen_SO) | |
e1daf7d6 | 99 | ttxputs(gen_SO); |
745d1a08 EW |
100 | } else |
101 | if (gen_SE) | |
e1daf7d6 | 102 | ttxputs(gen_SE); |
745d1a08 EW |
103 | } |
104 | if (diff & WWM_UL) { | |
105 | if (new & WWM_UL) { | |
106 | if (gen_US) | |
e1daf7d6 | 107 | ttxputs(gen_US); |
745d1a08 EW |
108 | } else |
109 | if (gen_UE) | |
e1daf7d6 | 110 | ttxputs(gen_UE); |
745d1a08 | 111 | } |
a830e8bb EW |
112 | if (diff & WWM_GRP) { |
113 | if (new & WWM_GRP) { | |
a64e9887 | 114 | if (gen_AS) |
e1daf7d6 | 115 | ttxputs(gen_AS); |
a830e8bb | 116 | } else |
a64e9887 | 117 | if (gen_AE) |
e1daf7d6 | 118 | ttxputs(gen_AE); |
a830e8bb | 119 | } |
a6833679 EW |
120 | if (diff & WWM_USR) { |
121 | if (new & WWM_USR) { | |
122 | if (gen_XS) | |
123 | ttxputs(gen_XS); | |
124 | } else | |
125 | if (gen_XE) | |
126 | ttxputs(gen_XE); | |
127 | } | |
3130283e | 128 | tt.tt_modes = new; |
73f690a1 EW |
129 | } |
130 | ||
131 | gen_insline() | |
132 | { | |
3130283e EW |
133 | if (tt.tt_modes) /* for concept 100 */ |
134 | gen_setmodes(0); | |
745d1a08 | 135 | if (gen_AL) |
b1189050 | 136 | tttputs(gen_AL, gen_LI - tt.tt_row); |
73f690a1 EW |
137 | } |
138 | ||
139 | gen_delline() | |
140 | { | |
3130283e EW |
141 | if (tt.tt_modes) /* for concept 100 */ |
142 | gen_setmodes(0); | |
745d1a08 | 143 | if (gen_DL) |
b1189050 | 144 | tttputs(gen_DL, gen_LI - tt.tt_row); |
73f690a1 EW |
145 | } |
146 | ||
147 | gen_putc(c) | |
148 | register char c; | |
149 | { | |
3130283e EW |
150 | if (tt.tt_ninsert != tt.tt_insert) |
151 | gen_setinsert(tt.tt_ninsert); | |
152 | if (tt.tt_nmodes != tt.tt_modes) | |
153 | gen_setmodes(tt.tt_nmodes); | |
154 | if (tt.tt_insert) { | |
745d1a08 | 155 | if (gen_IC) |
b1189050 EW |
156 | tttputs(gen_IC, gen_CO - tt.tt_col); |
157 | ttputc(c); | |
745d1a08 | 158 | if (gen_IP) |
b1189050 | 159 | tttputs(gen_IP, gen_CO - tt.tt_col); |
745d1a08 | 160 | } else |
b1189050 | 161 | ttputc(c); |
3130283e | 162 | if (++tt.tt_col == gen_CO) |
b16d80c6 EW |
163 | if (gen_XN) |
164 | tt.tt_col = tt.tt_row = -10; | |
165 | else if (gen_AM) | |
3130283e | 166 | tt.tt_col = 0, tt.tt_row++; |
5e785082 | 167 | else |
3130283e | 168 | tt.tt_col--; |
73f690a1 EW |
169 | } |
170 | ||
3130283e | 171 | gen_write(p, n) |
e1daf7d6 EW |
172 | register char *p; |
173 | register n; | |
73f690a1 | 174 | { |
3130283e EW |
175 | if (tt.tt_ninsert != tt.tt_insert) |
176 | gen_setinsert(tt.tt_ninsert); | |
177 | if (tt.tt_nmodes != tt.tt_modes) | |
178 | gen_setmodes(tt.tt_nmodes); | |
e1daf7d6 | 179 | if (tt.tt_insert && (gen_IC || gen_IP)) { |
73f690a1 | 180 | while (--n >= 0) { |
745d1a08 | 181 | if (gen_IC) |
b1189050 EW |
182 | tttputs(gen_IC, gen_CO - tt.tt_col); |
183 | ttputc(*p++); | |
745d1a08 | 184 | if (gen_IP) |
b1189050 | 185 | tttputs(gen_IP, gen_CO - tt.tt_col); |
3130283e | 186 | tt.tt_col++; |
73f690a1 EW |
187 | } |
188 | } else { | |
3130283e | 189 | tt.tt_col += n; |
e1daf7d6 | 190 | ttwrite(p, n); |
73f690a1 | 191 | } |
3130283e | 192 | if (tt.tt_col == gen_CO) |
b16d80c6 EW |
193 | if (gen_XN) |
194 | tt.tt_col = tt.tt_row = -10; | |
195 | else if (gen_AM) | |
3130283e | 196 | tt.tt_col = 0, tt.tt_row++; |
5e785082 | 197 | else |
3130283e | 198 | tt.tt_col--; |
73f690a1 EW |
199 | } |
200 | ||
201 | gen_move(row, col) | |
202 | register char row, col; | |
203 | { | |
3130283e | 204 | if (tt.tt_row == row && tt.tt_col == col) |
745d1a08 | 205 | return; |
3130283e EW |
206 | if (!gen_MI && tt.tt_insert) |
207 | gen_setinsert(0); | |
208 | if (!gen_MS && tt.tt_modes) | |
209 | gen_setmodes(0); | |
210 | if (tt.tt_row == row) { | |
211 | if (tt.tt_col == col) | |
73f690a1 | 212 | return; |
3130283e | 213 | if (tt.tt_col == col - 1) { |
745d1a08 | 214 | if (gen_ND) { |
e1daf7d6 | 215 | ttxputs(gen_ND); |
745d1a08 EW |
216 | goto out; |
217 | } | |
3130283e | 218 | } else if (tt.tt_col == col + 1) { |
745d1a08 | 219 | if (gen_BC) { |
e1daf7d6 | 220 | ttxputs(gen_BC); |
745d1a08 EW |
221 | goto out; |
222 | } | |
73f690a1 EW |
223 | } |
224 | } | |
3130283e EW |
225 | if (tt.tt_col == col) { |
226 | if (tt.tt_row == row + 1) { | |
745d1a08 | 227 | if (gen_UP) { |
e1daf7d6 | 228 | ttxputs(gen_UP); |
745d1a08 EW |
229 | goto out; |
230 | } | |
3130283e | 231 | } else if (tt.tt_row == row + 1) { |
e1daf7d6 EW |
232 | ttxputs(gen_NL); |
233 | goto out; | |
73f690a1 EW |
234 | } |
235 | } | |
745d1a08 | 236 | if (gen_HO && col == 0 && row == 0) { |
e1daf7d6 | 237 | ttxputs(gen_HO); |
73f690a1 EW |
238 | goto out; |
239 | } | |
e1daf7d6 | 240 | tttgoto(gen_CM, col, row); |
73f690a1 | 241 | out: |
3130283e EW |
242 | tt.tt_col = col; |
243 | tt.tt_row = row; | |
73f690a1 EW |
244 | } |
245 | ||
246 | gen_init() | |
73f690a1 | 247 | { |
745d1a08 | 248 | if (gen_VS) |
e1daf7d6 | 249 | ttxputs(gen_VS); |
7d9e29c8 | 250 | if (gen_TI) |
e1daf7d6 EW |
251 | ttxputs(gen_TI); |
252 | ttxputs(gen_CL); | |
3130283e EW |
253 | tt.tt_col = tt.tt_row = 0; |
254 | tt.tt_ninsert = tt.tt_insert = 0; | |
255 | tt.tt_nmodes = tt.tt_modes = 0; | |
73f690a1 EW |
256 | } |
257 | ||
fff1d01b | 258 | gen_end() |
73f690a1 | 259 | { |
7d9e29c8 | 260 | if (gen_TE) |
e1daf7d6 | 261 | ttxputs(gen_TE); |
745d1a08 | 262 | if (gen_VE) |
e1daf7d6 | 263 | ttxputs(gen_VE); |
73f690a1 EW |
264 | } |
265 | ||
266 | gen_clreol() | |
267 | { | |
3130283e EW |
268 | if (tt.tt_modes) /* for concept 100 */ |
269 | gen_setmodes(0); | |
e1daf7d6 | 270 | tttputs(gen_CE, gen_CO - tt.tt_col); |
73f690a1 EW |
271 | } |
272 | ||
273 | gen_clreos() | |
274 | { | |
3130283e EW |
275 | if (tt.tt_modes) /* for concept 100 */ |
276 | gen_setmodes(0); | |
e1daf7d6 | 277 | tttputs(gen_CD, gen_LI - tt.tt_row); |
73f690a1 EW |
278 | } |
279 | ||
280 | gen_clear() | |
281 | { | |
3130283e EW |
282 | if (tt.tt_modes) /* for concept 100 */ |
283 | gen_setmodes(0); | |
e1daf7d6 | 284 | ttxputs(gen_CL); |
73f690a1 EW |
285 | } |
286 | ||
287 | gen_delchar() | |
288 | { | |
e1daf7d6 | 289 | tttputs(gen_DC, gen_CO - tt.tt_col); |
73f690a1 EW |
290 | } |
291 | ||
292 | tt_generic() | |
293 | { | |
e1daf7d6 EW |
294 | gen_PC = tttgetstr("pc"); |
295 | PC = gen_PC ? *gen_PC->ts_str : 0; | |
296 | ospeed = wwoldtty.ww_sgttyb.sg_ospeed; | |
297 | ||
b1189050 EW |
298 | gen_CM = ttxgetstr("cm"); /* may not work */ |
299 | gen_IM = ttxgetstr("im"); | |
300 | gen_IC = tttgetstr("ic"); | |
301 | gen_IP = tttgetstr("ip"); | |
302 | gen_EI = ttxgetstr("ei"); | |
303 | gen_DC = tttgetstr("dc"); | |
304 | gen_AL = tttgetstr("al"); | |
305 | gen_DL = tttgetstr("dl"); | |
306 | gen_CE = tttgetstr("ce"); | |
307 | gen_CD = tttgetstr("cd"); | |
308 | gen_CL = ttxgetstr("cl"); | |
309 | gen_VS = ttxgetstr("vs"); | |
310 | gen_VE = ttxgetstr("ve"); | |
311 | gen_TI = ttxgetstr("ti"); | |
312 | gen_TE = ttxgetstr("te"); | |
313 | gen_SO = ttxgetstr("so"); | |
314 | gen_SE = ttxgetstr("se"); | |
315 | gen_US = ttxgetstr("us"); | |
316 | gen_UE = ttxgetstr("ue"); | |
317 | gen_UP = ttxgetstr("up"); | |
b1189050 EW |
318 | gen_BC = ttxgetstr("bc"); |
319 | gen_ND = ttxgetstr("nd"); | |
320 | gen_HO = ttxgetstr("ho"); | |
321 | gen_NL = ttxgetstr("nl"); | |
322 | gen_AS = ttxgetstr("as"); | |
323 | gen_AE = ttxgetstr("ae"); | |
a6833679 EW |
324 | gen_XS = ttxgetstr("XS"); |
325 | gen_XE = ttxgetstr("XE"); | |
745d1a08 EW |
326 | gen_MI = tgetflag("mi"); |
327 | gen_MS = tgetflag("ms"); | |
328 | gen_AM = tgetflag("am"); | |
329 | gen_OS = tgetflag("os"); | |
330 | gen_BS = tgetflag("bs"); | |
377a2410 | 331 | gen_DB = tgetflag("db"); |
b16d80c6 | 332 | gen_XN = tgetflag("xn"); |
745d1a08 EW |
333 | gen_CO = tgetnum("co"); |
334 | gen_LI = tgetnum("li"); | |
3babdf29 EW |
335 | gen_UG = tgetnum("ug"); |
336 | gen_SG = tgetnum("sg"); | |
745d1a08 | 337 | |
e1daf7d6 EW |
338 | if (gen_NL == 0) { |
339 | static struct tt_str nl = { "\n", 1 }; | |
340 | gen_NL = &nl; | |
341 | } | |
342 | if (gen_BC == 0 && gen_BS) { | |
343 | static struct tt_str bc = { "\b", 1 }; | |
344 | gen_BC = &bc; | |
345 | } | |
346 | BC = gen_BC ? gen_BC->ts_str : 0; | |
347 | UP = gen_UP ? gen_UP->ts_str : 0; | |
348 | if (gen_CL == 0 || gen_OS || gen_CM == 0) | |
745d1a08 EW |
349 | return -1; |
350 | ||
745d1a08 EW |
351 | if (gen_DC) |
352 | tt.tt_delchar = gen_delchar; | |
353 | if (gen_AL) | |
354 | tt.tt_insline = gen_insline; | |
355 | if (gen_DL) | |
356 | tt.tt_delline = gen_delline; | |
357 | if (gen_CE) | |
358 | tt.tt_clreol = gen_clreol; | |
359 | if (gen_CD) | |
360 | tt.tt_clreos = gen_clreos; | |
3babdf29 EW |
361 | if (gen_SG > 0) |
362 | gen_SO = 0; | |
b16d80c6 | 363 | if (gen_UG > 0 || gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0) |
3babdf29 | 364 | gen_US = 0; |
5e785082 EW |
365 | if (gen_SO) |
366 | tt.tt_availmodes |= WWM_REV; | |
367 | if (gen_US) | |
368 | tt.tt_availmodes |= WWM_UL; | |
a64e9887 EW |
369 | if (gen_AS) |
370 | tt.tt_availmodes |= WWM_GRP; | |
a6833679 EW |
371 | if (gen_XS) |
372 | tt.tt_availmodes |= WWM_USR; | |
3130283e | 373 | tt.tt_hasinsert = gen_IM != 0; |
5e785082 | 374 | tt.tt_wrap = gen_AM; |
377a2410 | 375 | tt.tt_retain = gen_DB; |
745d1a08 | 376 | tt.tt_ncol = gen_CO; |
745d1a08 | 377 | tt.tt_nrow = gen_LI; |
73f690a1 | 378 | tt.tt_init = gen_init; |
fff1d01b | 379 | tt.tt_end = gen_end; |
73f690a1 EW |
380 | tt.tt_write = gen_write; |
381 | tt.tt_putc = gen_putc; | |
745d1a08 | 382 | tt.tt_move = gen_move; |
e1daf7d6 | 383 | tt.tt_clear = gen_clear; |
c1a57462 EW |
384 | tt.tt_setinsert = gen_setinsert; |
385 | tt.tt_setmodes = gen_setmodes; | |
b16d80c6 EW |
386 | tt.tt_frame = gen_AS && ttstrcmp(gen_AS, &ansi_AS) == 0 ? |
387 | ansi_frame : gen_frame; | |
73f690a1 EW |
388 | return 0; |
389 | } |