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