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