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