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