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