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