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