rip out SHELL_ESCAPE define
[unix-history] / usr / src / usr.bin / window / ttgeneric.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60de5df9
EW
16 */
17
46e9ea25 18#ifndef lint
5e8b0e60 19static char sccsid[] = "@(#)ttgeneric.c 3.35 (Berkeley) %G%";
46e9ea25
KB
20#endif /* not lint */
21
73f690a1 22#include "ww.h"
fff1d01b 23#include "tt.h"
73f690a1 24
769cbf09
EW
25char PC, *BC, *UP;
26short ospeed;
94c16993 27
a6a7cd35 28 /* normal frame */
a830e8bb 29short gen_frame[16] = {
73f690a1
EW
30 ' ', '|', '-', '+',
31 '|', '|', '+', '+',
fff1d01b 32 '-', '+', '-', '+',
73f690a1
EW
33 '+', '+', '+', '+'
34};
35
a6a7cd35
EW
36 /* ANSI graphics frame */
37#define G (WWM_GRP << WWC_MSHIFT)
38short ansi_frame[16] = {
39 ' ', 'x'|G, 'Q'|G, 'm'|G,
40 'x'|G, 'x'|G, 'l'|G, 't'|G,
41 'q'|G, 'j'|G, 'q'|G, 'v'|G,
42 'k'|G, 'u'|G, 'w'|G, 'n'|G
43};
b16d80c6
EW
44struct tt_str ansi_AS = {
45 "\033(0", 3
46};
a6a7cd35 47
e1daf7d6
EW
48struct tt_str *gen_CM;
49struct tt_str *gen_IM;
50struct tt_str *gen_IC;
51struct tt_str *gen_IP;
52struct tt_str *gen_EI;
53struct tt_str *gen_DC;
54struct tt_str *gen_AL;
55struct tt_str *gen_DL;
56struct tt_str *gen_CE;
57struct tt_str *gen_CD;
58struct tt_str *gen_CL;
59struct tt_str *gen_VS;
60struct tt_str *gen_VE;
61struct tt_str *gen_TI;
62struct tt_str *gen_TE;
63struct tt_str *gen_SO;
64struct tt_str *gen_SE;
65struct tt_str *gen_US;
66struct tt_str *gen_UE;
67struct tt_str *gen_UP;
68struct tt_str *gen_PC;
69struct tt_str *gen_BC;
70struct tt_str *gen_ND;
71struct tt_str *gen_HO;
72struct tt_str *gen_NL;
16ea9636 73struct tt_str *gen_CR;
e1daf7d6
EW
74struct tt_str *gen_AS;
75struct tt_str *gen_AE;
a6833679
EW
76struct tt_str *gen_XS;
77struct tt_str *gen_XE;
16ea9636
EW
78struct tt_str *gen_SF;
79struct tt_str *gen_SR;
80struct tt_str *gen_CS;
745d1a08
EW
81char gen_MI;
82char gen_MS;
83char gen_AM;
84char gen_OS;
85char gen_BS;
16ea9636 86char gen_DA;
377a2410 87char gen_DB;
df7b254b 88char gen_NS;
b16d80c6 89char gen_XN;
745d1a08
EW
90int gen_CO;
91int gen_LI;
3babdf29
EW
92int gen_UG;
93int gen_SG;
745d1a08 94
73f690a1
EW
95gen_setinsert(new)
96char new;
97{
745d1a08
EW
98 if (new) {
99 if (gen_IM)
e1daf7d6 100 ttxputs(gen_IM);
745d1a08
EW
101 } else
102 if (gen_EI)
e1daf7d6 103 ttxputs(gen_EI);
3130283e 104 tt.tt_insert = new;
73f690a1
EW
105}
106
107gen_setmodes(new)
745d1a08 108register new;
73f690a1 109{
745d1a08
EW
110 register diff;
111
3130283e 112 diff = new ^ tt.tt_modes;
745d1a08
EW
113 if (diff & WWM_REV) {
114 if (new & WWM_REV) {
115 if (gen_SO)
e1daf7d6 116 ttxputs(gen_SO);
745d1a08
EW
117 } else
118 if (gen_SE)
e1daf7d6 119 ttxputs(gen_SE);
745d1a08
EW
120 }
121 if (diff & WWM_UL) {
122 if (new & WWM_UL) {
123 if (gen_US)
e1daf7d6 124 ttxputs(gen_US);
745d1a08
EW
125 } else
126 if (gen_UE)
e1daf7d6 127 ttxputs(gen_UE);
745d1a08 128 }
a830e8bb
EW
129 if (diff & WWM_GRP) {
130 if (new & WWM_GRP) {
a64e9887 131 if (gen_AS)
e1daf7d6 132 ttxputs(gen_AS);
a830e8bb 133 } else
a64e9887 134 if (gen_AE)
e1daf7d6 135 ttxputs(gen_AE);
a830e8bb 136 }
a6833679
EW
137 if (diff & WWM_USR) {
138 if (new & WWM_USR) {
139 if (gen_XS)
140 ttxputs(gen_XS);
141 } else
142 if (gen_XE)
143 ttxputs(gen_XE);
144 }
3130283e 145 tt.tt_modes = new;
73f690a1
EW
146}
147
148gen_insline()
149{
3130283e
EW
150 if (tt.tt_modes) /* for concept 100 */
151 gen_setmodes(0);
745d1a08 152 if (gen_AL)
b1189050 153 tttputs(gen_AL, gen_LI - tt.tt_row);
73f690a1
EW
154}
155
156gen_delline()
157{
3130283e
EW
158 if (tt.tt_modes) /* for concept 100 */
159 gen_setmodes(0);
745d1a08 160 if (gen_DL)
b1189050 161 tttputs(gen_DL, gen_LI - tt.tt_row);
73f690a1
EW
162}
163
164gen_putc(c)
165register char c;
166{
3130283e
EW
167 if (tt.tt_ninsert != tt.tt_insert)
168 gen_setinsert(tt.tt_ninsert);
169 if (tt.tt_nmodes != tt.tt_modes)
170 gen_setmodes(tt.tt_nmodes);
171 if (tt.tt_insert) {
745d1a08 172 if (gen_IC)
b1189050
EW
173 tttputs(gen_IC, gen_CO - tt.tt_col);
174 ttputc(c);
745d1a08 175 if (gen_IP)
b1189050 176 tttputs(gen_IP, gen_CO - tt.tt_col);
745d1a08 177 } else
b1189050 178 ttputc(c);
3130283e 179 if (++tt.tt_col == gen_CO)
b16d80c6
EW
180 if (gen_XN)
181 tt.tt_col = tt.tt_row = -10;
182 else if (gen_AM)
3130283e 183 tt.tt_col = 0, tt.tt_row++;
5e785082 184 else
3130283e 185 tt.tt_col--;
73f690a1
EW
186}
187
3130283e 188gen_write(p, n)
e1daf7d6
EW
189 register char *p;
190 register n;
73f690a1 191{
3130283e
EW
192 if (tt.tt_ninsert != tt.tt_insert)
193 gen_setinsert(tt.tt_ninsert);
194 if (tt.tt_nmodes != tt.tt_modes)
195 gen_setmodes(tt.tt_nmodes);
e1daf7d6 196 if (tt.tt_insert && (gen_IC || gen_IP)) {
73f690a1 197 while (--n >= 0) {
745d1a08 198 if (gen_IC)
b1189050
EW
199 tttputs(gen_IC, gen_CO - tt.tt_col);
200 ttputc(*p++);
745d1a08 201 if (gen_IP)
b1189050 202 tttputs(gen_IP, gen_CO - tt.tt_col);
3130283e 203 tt.tt_col++;
73f690a1
EW
204 }
205 } else {
3130283e 206 tt.tt_col += n;
e1daf7d6 207 ttwrite(p, n);
73f690a1 208 }
3130283e 209 if (tt.tt_col == gen_CO)
b16d80c6
EW
210 if (gen_XN)
211 tt.tt_col = tt.tt_row = -10;
212 else if (gen_AM)
3130283e 213 tt.tt_col = 0, tt.tt_row++;
5e785082 214 else
3130283e 215 tt.tt_col--;
73f690a1
EW
216}
217
218gen_move(row, col)
1306887c 219register int row, col;
73f690a1 220{
3130283e 221 if (tt.tt_row == row && tt.tt_col == col)
745d1a08 222 return;
3130283e
EW
223 if (!gen_MI && tt.tt_insert)
224 gen_setinsert(0);
225 if (!gen_MS && tt.tt_modes)
226 gen_setmodes(0);
16ea9636
EW
227 if (row < tt.tt_scroll_top || row > tt.tt_scroll_bot)
228 gen_setscroll(tt.tt_nrow - 1, 0);
3130283e 229 if (tt.tt_row == row) {
16ea9636
EW
230 if (col == 0) {
231 ttxputs(gen_CR);
232 goto out;
233 }
3130283e 234 if (tt.tt_col == col - 1) {
745d1a08 235 if (gen_ND) {
e1daf7d6 236 ttxputs(gen_ND);
745d1a08
EW
237 goto out;
238 }
3130283e 239 } else if (tt.tt_col == col + 1) {
745d1a08 240 if (gen_BC) {
e1daf7d6 241 ttxputs(gen_BC);
745d1a08
EW
242 goto out;
243 }
73f690a1
EW
244 }
245 }
3130283e
EW
246 if (tt.tt_col == col) {
247 if (tt.tt_row == row + 1) {
745d1a08 248 if (gen_UP) {
e1daf7d6 249 ttxputs(gen_UP);
745d1a08
EW
250 goto out;
251 }
3130283e 252 } else if (tt.tt_row == row + 1) {
e1daf7d6
EW
253 ttxputs(gen_NL);
254 goto out;
73f690a1
EW
255 }
256 }
745d1a08 257 if (gen_HO && col == 0 && row == 0) {
e1daf7d6 258 ttxputs(gen_HO);
73f690a1
EW
259 goto out;
260 }
e1daf7d6 261 tttgoto(gen_CM, col, row);
73f690a1 262out:
3130283e
EW
263 tt.tt_col = col;
264 tt.tt_row = row;
73f690a1
EW
265}
266
267gen_init()
73f690a1 268{
745d1a08 269 if (gen_VS)
e1daf7d6 270 ttxputs(gen_VS);
7d9e29c8 271 if (gen_TI)
e1daf7d6
EW
272 ttxputs(gen_TI);
273 ttxputs(gen_CL);
3130283e
EW
274 tt.tt_col = tt.tt_row = 0;
275 tt.tt_ninsert = tt.tt_insert = 0;
276 tt.tt_nmodes = tt.tt_modes = 0;
73f690a1
EW
277}
278
fff1d01b 279gen_end()
73f690a1 280{
7d9e29c8 281 if (gen_TE)
e1daf7d6 282 ttxputs(gen_TE);
745d1a08 283 if (gen_VE)
e1daf7d6 284 ttxputs(gen_VE);
73f690a1
EW
285}
286
287gen_clreol()
288{
3130283e
EW
289 if (tt.tt_modes) /* for concept 100 */
290 gen_setmodes(0);
e1daf7d6 291 tttputs(gen_CE, gen_CO - tt.tt_col);
73f690a1
EW
292}
293
294gen_clreos()
295{
3130283e
EW
296 if (tt.tt_modes) /* for concept 100 */
297 gen_setmodes(0);
e1daf7d6 298 tttputs(gen_CD, gen_LI - tt.tt_row);
73f690a1
EW
299}
300
301gen_clear()
302{
3130283e
EW
303 if (tt.tt_modes) /* for concept 100 */
304 gen_setmodes(0);
e1daf7d6 305 ttxputs(gen_CL);
73f690a1
EW
306}
307
308gen_delchar()
309{
e1daf7d6 310 tttputs(gen_DC, gen_CO - tt.tt_col);
73f690a1
EW
311}
312
16ea9636
EW
313gen_scroll_down()
314{
315 gen_move(tt.tt_scroll_bot, 0);
316 ttxputs(gen_SF);
317}
318
319gen_scroll_up()
320{
321 gen_move(tt.tt_scroll_top, 0);
322 ttxputs(gen_SR);
323}
324
325gen_setscroll(top, bot)
326{
327 tttgoto(gen_CS, bot, top);
328 tt.tt_scroll_top = top;
329 tt.tt_scroll_bot = bot;
330 tt.tt_row = tt.tt_col = -10;
331}
332
73f690a1
EW
333tt_generic()
334{
e1daf7d6
EW
335 gen_PC = tttgetstr("pc");
336 PC = gen_PC ? *gen_PC->ts_str : 0;
337 ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
338
b1189050
EW
339 gen_CM = ttxgetstr("cm"); /* may not work */
340 gen_IM = ttxgetstr("im");
341 gen_IC = tttgetstr("ic");
342 gen_IP = tttgetstr("ip");
343 gen_EI = ttxgetstr("ei");
344 gen_DC = tttgetstr("dc");
345 gen_AL = tttgetstr("al");
346 gen_DL = tttgetstr("dl");
347 gen_CE = tttgetstr("ce");
348 gen_CD = tttgetstr("cd");
349 gen_CL = ttxgetstr("cl");
350 gen_VS = ttxgetstr("vs");
351 gen_VE = ttxgetstr("ve");
352 gen_TI = ttxgetstr("ti");
353 gen_TE = ttxgetstr("te");
354 gen_SO = ttxgetstr("so");
355 gen_SE = ttxgetstr("se");
356 gen_US = ttxgetstr("us");
357 gen_UE = ttxgetstr("ue");
358 gen_UP = ttxgetstr("up");
b1189050
EW
359 gen_BC = ttxgetstr("bc");
360 gen_ND = ttxgetstr("nd");
361 gen_HO = ttxgetstr("ho");
362 gen_NL = ttxgetstr("nl");
16ea9636 363 gen_CR = ttxgetstr("cr");
b1189050
EW
364 gen_AS = ttxgetstr("as");
365 gen_AE = ttxgetstr("ae");
a6833679
EW
366 gen_XS = ttxgetstr("XS");
367 gen_XE = ttxgetstr("XE");
16ea9636
EW
368 gen_SF = ttxgetstr("sf");
369 gen_SR = ttxgetstr("sr");
370 gen_CS = ttxgetstr("cs");
745d1a08
EW
371 gen_MI = tgetflag("mi");
372 gen_MS = tgetflag("ms");
373 gen_AM = tgetflag("am");
374 gen_OS = tgetflag("os");
375 gen_BS = tgetflag("bs");
16ea9636 376 gen_DA = tgetflag("da");
377a2410 377 gen_DB = tgetflag("db");
df7b254b 378 gen_NS = tgetflag("ns");
b16d80c6 379 gen_XN = tgetflag("xn");
745d1a08
EW
380 gen_CO = tgetnum("co");
381 gen_LI = tgetnum("li");
3babdf29
EW
382 gen_UG = tgetnum("ug");
383 gen_SG = tgetnum("sg");
16ea9636
EW
384 if (gen_CL == 0 || gen_OS || gen_CM == 0)
385 return -1;
745d1a08 386
e1daf7d6
EW
387 if (gen_NL == 0) {
388 static struct tt_str nl = { "\n", 1 };
389 gen_NL = &nl;
390 }
16ea9636
EW
391 if (gen_CR == 0) {
392 static struct tt_str cr = { "\r", 1 };
393 gen_CR = &cr;
394 }
e1daf7d6
EW
395 if (gen_BC == 0 && gen_BS) {
396 static struct tt_str bc = { "\b", 1 };
397 gen_BC = &bc;
398 }
16ea9636
EW
399 if (gen_SF == 0 && !gen_NS)
400 gen_SF = gen_NL;
e1daf7d6
EW
401 BC = gen_BC ? gen_BC->ts_str : 0;
402 UP = gen_UP ? gen_UP->ts_str : 0;
745d1a08 403
745d1a08
EW
404 if (gen_DC)
405 tt.tt_delchar = gen_delchar;
406 if (gen_AL)
407 tt.tt_insline = gen_insline;
408 if (gen_DL)
409 tt.tt_delline = gen_delline;
410 if (gen_CE)
411 tt.tt_clreol = gen_clreol;
412 if (gen_CD)
413 tt.tt_clreos = gen_clreos;
16ea9636
EW
414 if (gen_SF)
415 tt.tt_scroll_down = gen_scroll_down;
416 /*
417 * Don't allow scroll_up if da or db but not cs.
418 * See comment in wwscroll.c.
419 */
420 if (gen_SR && (gen_CS || !gen_DA && !gen_DB))
421 tt.tt_scroll_up = gen_scroll_up;
422 if (gen_CS)
423 tt.tt_setscroll = gen_setscroll;
3babdf29
EW
424 if (gen_SG > 0)
425 gen_SO = 0;
b16d80c6 426 if (gen_UG > 0 || gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0)
3babdf29 427 gen_US = 0;
5e785082
EW
428 if (gen_SO)
429 tt.tt_availmodes |= WWM_REV;
430 if (gen_US)
431 tt.tt_availmodes |= WWM_UL;
a64e9887
EW
432 if (gen_AS)
433 tt.tt_availmodes |= WWM_GRP;
a6833679
EW
434 if (gen_XS)
435 tt.tt_availmodes |= WWM_USR;
3130283e 436 tt.tt_hasinsert = gen_IM != 0;
5e785082 437 tt.tt_wrap = gen_AM;
377a2410 438 tt.tt_retain = gen_DB;
745d1a08 439 tt.tt_ncol = gen_CO;
745d1a08 440 tt.tt_nrow = gen_LI;
73f690a1 441 tt.tt_init = gen_init;
fff1d01b 442 tt.tt_end = gen_end;
73f690a1
EW
443 tt.tt_write = gen_write;
444 tt.tt_putc = gen_putc;
745d1a08 445 tt.tt_move = gen_move;
e1daf7d6 446 tt.tt_clear = gen_clear;
c1a57462
EW
447 tt.tt_setinsert = gen_setinsert;
448 tt.tt_setmodes = gen_setmodes;
b16d80c6
EW
449 tt.tt_frame = gen_AS && ttstrcmp(gen_AS, &ansi_AS) == 0 ?
450 ansi_frame : gen_frame;
73f690a1
EW
451 return 0;
452}