Commit | Line | Data |
---|---|---|
73f690a1 | 1 | #ifndef lint |
7d9e29c8 | 2 | static char *sccsid = "@(#)ttgeneric.c 3.13 83/08/23"; |
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 | ||
745d1a08 | 17 | int gen_row, gen_col; |
7d9e29c8 EW |
18 | char gen_modes, gen_nmodes; |
19 | char gen_insert, gen_ninsert; | |
745d1a08 | 20 | |
745d1a08 EW |
21 | char *gen_CM; |
22 | char *gen_IM; | |
23 | char *gen_IC; | |
24 | char *gen_IP; | |
25 | char *gen_EI; | |
26 | char *gen_DC; | |
27 | char *gen_AL; | |
28 | char *gen_DL; | |
29 | char *gen_CE; | |
30 | char *gen_CD; | |
31 | char *gen_CL; | |
32 | char *gen_VS; | |
33 | char *gen_VE; | |
7d9e29c8 EW |
34 | char *gen_TI; |
35 | char *gen_TE; | |
745d1a08 EW |
36 | char *gen_SO; |
37 | char *gen_SE; | |
38 | char *gen_US; | |
39 | char *gen_UE; | |
40 | char *gen_UP; | |
41 | char *gen_PC; | |
42 | char *gen_BC; | |
43 | char *gen_ND; | |
44 | char *gen_HO; | |
45 | char *gen_NL; | |
46 | char gen_MI; | |
47 | char gen_MS; | |
48 | char gen_AM; | |
49 | char gen_OS; | |
50 | char gen_BS; | |
51 | int gen_CO; | |
52 | int gen_LI; | |
3babdf29 EW |
53 | int gen_UG; |
54 | int gen_SG; | |
745d1a08 EW |
55 | |
56 | #define pc(c) putchar('c') | |
57 | #define ps(s) fputs((s), stdout) | |
58 | ||
73f690a1 | 59 | gen_setinsert(new) |
7d9e29c8 EW |
60 | { |
61 | gen_ninsert = new; | |
62 | } | |
63 | ||
64 | gen_setinsert1(new) | |
73f690a1 EW |
65 | char new; |
66 | { | |
745d1a08 EW |
67 | if (gen_insert == new) |
68 | return; | |
69 | if (new) { | |
70 | if (gen_IM) | |
71 | ps(gen_IM); | |
72 | } else | |
73 | if (gen_EI) | |
74 | ps(gen_EI); | |
75 | gen_insert = new; | |
73f690a1 EW |
76 | } |
77 | ||
78 | gen_setmodes(new) | |
7d9e29c8 EW |
79 | char new; |
80 | { | |
81 | gen_nmodes = new & tt.tt_availmodes; | |
82 | } | |
83 | ||
84 | gen_setmodes1(new) | |
745d1a08 | 85 | register new; |
73f690a1 | 86 | { |
745d1a08 EW |
87 | register diff; |
88 | ||
745d1a08 EW |
89 | if ((diff = new ^ gen_modes) == 0) |
90 | return; | |
91 | if (diff & WWM_REV) { | |
92 | if (new & WWM_REV) { | |
93 | if (gen_SO) | |
94 | ps(gen_SO); | |
95 | } else | |
96 | if (gen_SE) | |
97 | ps(gen_SE); | |
98 | } | |
99 | if (diff & WWM_UL) { | |
100 | if (new & WWM_UL) { | |
101 | if (gen_US) | |
102 | ps(gen_US); | |
103 | } else | |
104 | if (gen_UE) | |
105 | ps(gen_UE); | |
106 | } | |
107 | gen_modes = new; | |
73f690a1 EW |
108 | } |
109 | ||
110 | gen_insline() | |
111 | { | |
7d9e29c8 EW |
112 | if (gen_modes) /* for concept 100 */ |
113 | gen_setmodes1(0); | |
745d1a08 | 114 | if (gen_AL) |
c3f80cb5 | 115 | tt_tputs(gen_AL, gen_LI - gen_row); |
73f690a1 EW |
116 | } |
117 | ||
118 | gen_delline() | |
119 | { | |
7d9e29c8 EW |
120 | if (gen_modes) /* for concept 100 */ |
121 | gen_setmodes1(0); | |
745d1a08 | 122 | if (gen_DL) |
c3f80cb5 | 123 | tt_tputs(gen_DL, gen_LI - gen_row); |
73f690a1 EW |
124 | } |
125 | ||
126 | gen_putc(c) | |
127 | register char c; | |
128 | { | |
7d9e29c8 EW |
129 | gen_setinsert1(gen_ninsert); |
130 | gen_setmodes1(gen_nmodes); | |
745d1a08 EW |
131 | if (gen_insert) { |
132 | if (gen_IC) | |
c3f80cb5 | 133 | tt_tputs(gen_IC, gen_CO - gen_col); |
745d1a08 EW |
134 | putchar(c); |
135 | if (gen_IP) | |
c3f80cb5 | 136 | tt_tputs(gen_IP, gen_CO - gen_col); |
745d1a08 | 137 | } else |
73f690a1 | 138 | putchar(c); |
5e785082 EW |
139 | if (++gen_col == gen_CO) |
140 | if (gen_AM) | |
141 | gen_col = 0, gen_row++; | |
142 | else | |
9574abf2 | 143 | gen_col--; |
73f690a1 EW |
144 | } |
145 | ||
146 | gen_write(start, end) | |
147 | register char *start, *end; | |
148 | { | |
7d9e29c8 EW |
149 | gen_setinsert1(gen_ninsert); |
150 | gen_setmodes1(gen_nmodes); | |
73f690a1 EW |
151 | if (gen_insert) { |
152 | while (start <= end) { | |
745d1a08 | 153 | if (gen_IC) |
c3f80cb5 | 154 | tt_tputs(gen_IC, gen_CO - gen_col); |
745d1a08 EW |
155 | putchar(*start++); |
156 | if (gen_IP) | |
c3f80cb5 | 157 | tt_tputs(gen_IP, gen_CO - gen_col); |
73f690a1 EW |
158 | gen_col++; |
159 | } | |
160 | } else { | |
161 | gen_col += end - start + 1; | |
162 | while (start <= end) | |
745d1a08 | 163 | putchar(*start++); |
73f690a1 | 164 | } |
5e785082 EW |
165 | if (gen_col == gen_CO) |
166 | if (gen_AM) | |
167 | gen_col = 0, gen_row++; | |
168 | else | |
9574abf2 | 169 | gen_col--; |
73f690a1 EW |
170 | } |
171 | ||
172 | gen_blank(n) | |
173 | register n; | |
174 | { | |
175 | if (n <= 0) | |
176 | return; | |
7d9e29c8 EW |
177 | gen_setinsert1(gen_ninsert); |
178 | gen_setmodes1(gen_nmodes); | |
73f690a1 EW |
179 | if (gen_insert) { |
180 | while (--n >= 0) { | |
745d1a08 | 181 | if (gen_IC) |
c3f80cb5 | 182 | tt_tputs(gen_IC, gen_CO - gen_col); |
73f690a1 | 183 | putchar(' '); |
745d1a08 | 184 | if (gen_IP) |
c3f80cb5 | 185 | tt_tputs(gen_IP, gen_CO - gen_col); |
73f690a1 EW |
186 | gen_col++; |
187 | } | |
188 | } else { | |
189 | gen_col += n; | |
190 | while (--n >= 0) | |
191 | putchar(' '); | |
192 | } | |
5e785082 EW |
193 | if (gen_col == gen_CO) |
194 | if (gen_AM) | |
195 | gen_col = 0, gen_row++; | |
196 | else | |
9574abf2 | 197 | gen_col--; |
73f690a1 EW |
198 | } |
199 | ||
200 | gen_move(row, col) | |
201 | register char row, col; | |
202 | { | |
745d1a08 EW |
203 | if (gen_row == row && gen_col == col) |
204 | return; | |
205 | if (!gen_MI && gen_insert) | |
7d9e29c8 EW |
206 | gen_setinsert(0); |
207 | if (!gen_MS && gen_modes) | |
208 | gen_setmodes(0); | |
73f690a1 EW |
209 | if (gen_row == row) { |
210 | if (gen_col == col) | |
211 | return; | |
212 | if (gen_col == col - 1) { | |
745d1a08 EW |
213 | if (gen_ND) { |
214 | ps(gen_ND); | |
215 | goto out; | |
216 | } | |
73f690a1 | 217 | } else if (gen_col == col + 1) { |
745d1a08 EW |
218 | if (gen_BC) { |
219 | ps(gen_BC); | |
220 | goto out; | |
221 | } | |
73f690a1 EW |
222 | } |
223 | } | |
224 | if (gen_col == col) { | |
225 | if (gen_row == row + 1) { | |
745d1a08 EW |
226 | if (gen_UP) { |
227 | ps(gen_UP); | |
228 | goto out; | |
229 | } | |
73f690a1 | 230 | } else if (gen_row == row + 1) { |
745d1a08 EW |
231 | if (gen_NL) { |
232 | ps(gen_NL); | |
233 | goto out; | |
234 | } | |
73f690a1 EW |
235 | } |
236 | } | |
745d1a08 EW |
237 | if (gen_HO && col == 0 && row == 0) { |
238 | ps(gen_HO); | |
73f690a1 EW |
239 | goto out; |
240 | } | |
c3f80cb5 | 241 | ps(tgoto(gen_CM, col, row)); |
73f690a1 EW |
242 | out: |
243 | gen_col = col; | |
244 | gen_row = row; | |
245 | } | |
246 | ||
247 | gen_init() | |
73f690a1 | 248 | { |
745d1a08 EW |
249 | if (gen_VS) |
250 | ps(gen_VS); | |
7d9e29c8 EW |
251 | if (gen_TI) |
252 | ps(gen_TI); | |
fff1d01b EW |
253 | if (gen_CL) |
254 | ps(gen_CL); | |
73f690a1 | 255 | gen_col = gen_row = 0; |
7d9e29c8 EW |
256 | gen_ninsert = gen_insert = 0; |
257 | gen_nmodes = gen_modes = 0; | |
73f690a1 EW |
258 | } |
259 | ||
fff1d01b | 260 | gen_end() |
73f690a1 | 261 | { |
7d9e29c8 EW |
262 | gen_setmodes1(0); |
263 | gen_setinsert1(0); | |
264 | if (gen_TE) | |
265 | ps(gen_TE); | |
745d1a08 EW |
266 | if (gen_VE) |
267 | ps(gen_VE); | |
73f690a1 EW |
268 | } |
269 | ||
270 | gen_clreol() | |
271 | { | |
7d9e29c8 EW |
272 | if (gen_modes) /* for concept 100 */ |
273 | gen_setmodes1(0); | |
745d1a08 | 274 | if (gen_CE) |
c3f80cb5 | 275 | tt_tputs(gen_CE, gen_CO - gen_col); |
73f690a1 EW |
276 | } |
277 | ||
278 | gen_clreos() | |
279 | { | |
7d9e29c8 EW |
280 | if (gen_modes) /* for concept 100 */ |
281 | gen_setmodes1(0); | |
745d1a08 | 282 | if (gen_CD) |
c3f80cb5 | 283 | tt_tputs(gen_CD, gen_LI - gen_row); |
73f690a1 EW |
284 | } |
285 | ||
286 | gen_clear() | |
287 | { | |
7d9e29c8 EW |
288 | if (gen_modes) /* for concept 100 */ |
289 | gen_setmodes1(0); | |
745d1a08 EW |
290 | if (gen_CL) |
291 | ps(gen_CL); | |
73f690a1 EW |
292 | } |
293 | ||
294 | gen_delchar() | |
295 | { | |
745d1a08 | 296 | if (gen_DC) |
c3f80cb5 | 297 | tt_tputs(gen_DC, gen_CO - gen_col); |
73f690a1 EW |
298 | } |
299 | ||
300 | tt_generic() | |
301 | { | |
c3f80cb5 EW |
302 | gen_CM = tt_xgetstr("cm"); /* may not work */ |
303 | gen_IM = tt_xgetstr("im"); | |
304 | gen_IC = tt_tgetstr("ic"); | |
305 | gen_IP = tt_tgetstr("ip"); | |
306 | gen_EI = tt_xgetstr("ei"); | |
307 | gen_DC = tt_tgetstr("dc"); | |
308 | gen_AL = tt_tgetstr("al"); | |
309 | gen_DL = tt_tgetstr("dl"); | |
310 | gen_CE = tt_tgetstr("ce"); | |
311 | gen_CD = tt_tgetstr("cd"); | |
312 | gen_CL = tt_xgetstr("cl"); | |
313 | gen_VS = tt_xgetstr("vs"); | |
314 | gen_VE = tt_xgetstr("ve"); | |
7d9e29c8 EW |
315 | gen_TI = tt_xgetstr("ti"); |
316 | gen_TE = tt_xgetstr("te"); | |
c3f80cb5 EW |
317 | gen_SO = tt_xgetstr("so"); |
318 | gen_SE = tt_xgetstr("se"); | |
319 | gen_US = tt_xgetstr("us"); | |
320 | gen_UE = tt_xgetstr("ue"); | |
321 | gen_UP = tt_xgetstr("up"); | |
322 | gen_PC = tt_tgetstr("pc"); | |
323 | gen_BC = tt_xgetstr("bc"); | |
324 | gen_ND = tt_xgetstr("nd"); | |
325 | gen_HO = tt_xgetstr("ho"); | |
326 | gen_NL = tt_xgetstr("nl"); | |
745d1a08 EW |
327 | gen_MI = tgetflag("mi"); |
328 | gen_MS = tgetflag("ms"); | |
329 | gen_AM = tgetflag("am"); | |
330 | gen_OS = tgetflag("os"); | |
331 | gen_BS = tgetflag("bs"); | |
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_IM) |
356 | tt.tt_setinsert = gen_setinsert; | |
357 | if (gen_DC) | |
358 | tt.tt_delchar = gen_delchar; | |
359 | if (gen_AL) | |
360 | tt.tt_insline = gen_insline; | |
361 | if (gen_DL) | |
362 | tt.tt_delline = gen_delline; | |
363 | if (gen_CE) | |
364 | tt.tt_clreol = gen_clreol; | |
365 | if (gen_CD) | |
366 | tt.tt_clreos = gen_clreos; | |
367 | if (gen_CL) | |
368 | tt.tt_clear = gen_clear; | |
3babdf29 EW |
369 | if (gen_SG > 0) |
370 | gen_SO = 0; | |
371 | if (gen_UG > 0) | |
372 | gen_US = 0; | |
5e785082 EW |
373 | if (gen_SO) |
374 | tt.tt_availmodes |= WWM_REV; | |
375 | if (gen_US) | |
376 | tt.tt_availmodes |= WWM_UL; | |
377 | tt.tt_wrap = gen_AM; | |
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; |
745d1a08 EW |
382 | tt.tt_setmodes = gen_setmodes; |
383 | tt.tt_blank = gen_blank; | |
73f690a1 EW |
384 | tt.tt_write = gen_write; |
385 | tt.tt_putc = gen_putc; | |
745d1a08 | 386 | tt.tt_move = gen_move; |
73f690a1 EW |
387 | tt.tt_frame = gen_frame; |
388 | return 0; | |
389 | } |