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