|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * Edward Wang at The University of California, Berkeley.
7: *
8: * Redistribution and use in source and binary forms are permitted provided
9: * that: (1) source distributions retain this entire copyright notice and
10: * comment, and (2) distributions including binaries display the following
11: * acknowledgement: ``This product includes software developed by the
12: * University of California, Berkeley and its contributors'' in the
13: * documentation or other materials provided with the distribution and in
14: * all advertising materials mentioning features or use of this software.
15: * Neither the name of the University nor the names of its contributors may
16: * be used to endorse or promote products derived from this software without
17: * specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)ttgeneric.c 3.45 (Berkeley) 6/6/90";
25: #endif /* not lint */
26:
27: #include "ww.h"
28: #include "tt.h"
29:
30: char PC, *BC, *UP;
31: short ospeed;
32:
33: /* normal frame */
34: short gen_frame[16] = {
35: ' ', '|', '-', '+',
36: '|', '|', '+', '+',
37: '-', '+', '-', '+',
38: '+', '+', '+', '+'
39: };
40:
41: /* ANSI graphics frame */
42: #define G (WWM_GRP << WWC_MSHIFT)
43: short ansi_frame[16] = {
44: ' ', 'x'|G, 'Q'|G, 'm'|G,
45: 'x'|G, 'x'|G, 'l'|G, 't'|G,
46: 'q'|G, 'j'|G, 'q'|G, 'v'|G,
47: 'k'|G, 'u'|G, 'w'|G, 'n'|G
48: };
49: struct tt_str ansi_AS = {
50: "\033(0", 3
51: };
52:
53: struct tt_str *gen_PC;
54: struct tt_str *gen_CM;
55: struct tt_str *gen_IM;
56: struct tt_str *gen_IC;
57: struct tt_str *gen_ICn;
58: struct tt_str *gen_IP;
59: struct tt_str *gen_EI;
60: struct tt_str *gen_DC;
61: struct tt_str *gen_DCn;
62: struct tt_str *gen_AL;
63: struct tt_str *gen_ALn;
64: struct tt_str *gen_DL;
65: struct tt_str *gen_DLn;
66: struct tt_str *gen_CE;
67: struct tt_str *gen_CD;
68: struct tt_str *gen_CL;
69: struct tt_str *gen_VS;
70: struct tt_str *gen_VE;
71: struct tt_str *gen_TI;
72: struct tt_str *gen_TE;
73: struct tt_str *gen_SO;
74: struct tt_str *gen_SE;
75: struct tt_str *gen_US;
76: struct tt_str *gen_UE;
77: struct tt_str *gen_LE;
78: struct tt_str *gen_ND;
79: struct tt_str *gen_UP;
80: struct tt_str *gen_DO;
81: struct tt_str *gen_BC;
82: struct tt_str *gen_NL;
83: struct tt_str *gen_CR;
84: struct tt_str *gen_HO;
85: struct tt_str *gen_AS;
86: struct tt_str *gen_AE;
87: struct tt_str *gen_XS;
88: struct tt_str *gen_XE;
89: struct tt_str *gen_SF;
90: struct tt_str *gen_SFn;
91: struct tt_str *gen_SR;
92: struct tt_str *gen_SRn;
93: struct tt_str *gen_CS;
94: char gen_MI;
95: char gen_MS;
96: char gen_AM;
97: char gen_OS;
98: char gen_BS;
99: char gen_DA;
100: char gen_DB;
101: char gen_NS;
102: char gen_XN;
103: int gen_CO;
104: int gen_LI;
105: int gen_UG;
106: int gen_SG;
107:
108: gen_setinsert(new)
109: char new;
110: {
111: if (new) {
112: if (gen_IM)
113: ttxputs(gen_IM);
114: } else
115: if (gen_EI)
116: ttxputs(gen_EI);
117: tt.tt_insert = new;
118: }
119:
120: gen_setmodes(new)
121: register new;
122: {
123: register diff;
124:
125: diff = new ^ tt.tt_modes;
126: if (diff & WWM_REV) {
127: if (new & WWM_REV) {
128: if (gen_SO)
129: ttxputs(gen_SO);
130: } else
131: if (gen_SE)
132: ttxputs(gen_SE);
133: }
134: if (diff & WWM_UL) {
135: if (new & WWM_UL) {
136: if (gen_US)
137: ttxputs(gen_US);
138: } else
139: if (gen_UE)
140: ttxputs(gen_UE);
141: }
142: if (diff & WWM_GRP) {
143: if (new & WWM_GRP) {
144: if (gen_AS)
145: ttxputs(gen_AS);
146: } else
147: if (gen_AE)
148: ttxputs(gen_AE);
149: }
150: if (diff & WWM_USR) {
151: if (new & WWM_USR) {
152: if (gen_XS)
153: ttxputs(gen_XS);
154: } else
155: if (gen_XE)
156: ttxputs(gen_XE);
157: }
158: tt.tt_modes = new;
159: }
160:
161: gen_insline(n)
162: {
163: if (tt.tt_modes) /* for concept 100 */
164: gen_setmodes(0);
165: if (gen_ALn)
166: ttpgoto(gen_ALn, 0, n, gen_LI - tt.tt_row);
167: else
168: while (--n >= 0)
169: tttputs(gen_AL, gen_LI - tt.tt_row);
170: }
171:
172: gen_delline(n)
173: {
174: if (tt.tt_modes) /* for concept 100 */
175: gen_setmodes(0);
176: if (gen_DLn)
177: ttpgoto(gen_DLn, 0, n, gen_LI - tt.tt_row);
178: else
179: while (--n >= 0)
180: tttputs(gen_DL, gen_LI - tt.tt_row);
181: }
182:
183: gen_putc(c)
184: register char c;
185: {
186: if (tt.tt_insert)
187: gen_setinsert(0);
188: if (tt.tt_nmodes != tt.tt_modes)
189: gen_setmodes(tt.tt_nmodes);
190: ttputc(c);
191: if (++tt.tt_col == gen_CO)
192: if (gen_XN)
193: tt.tt_col = tt.tt_row = -10;
194: else if (gen_AM)
195: tt.tt_col = 0, tt.tt_row++;
196: else
197: tt.tt_col--;
198: }
199:
200: gen_write(p, n)
201: register char *p;
202: register n;
203: {
204: if (tt.tt_insert)
205: gen_setinsert(0);
206: if (tt.tt_nmodes != tt.tt_modes)
207: gen_setmodes(tt.tt_nmodes);
208: ttwrite(p, n);
209: tt.tt_col += n;
210: if (tt.tt_col == gen_CO)
211: if (gen_XN)
212: tt.tt_col = tt.tt_row = -10;
213: else if (gen_AM)
214: tt.tt_col = 0, tt.tt_row++;
215: else
216: tt.tt_col--;
217: }
218:
219: gen_move(row, col)
220: register int row, col;
221: {
222: if (tt.tt_row == row && tt.tt_col == col)
223: return;
224: if (!gen_MI && tt.tt_insert)
225: gen_setinsert(0);
226: if (!gen_MS && tt.tt_modes)
227: gen_setmodes(0);
228: if (row < tt.tt_scroll_top || row > tt.tt_scroll_bot)
229: gen_setscroll(0, tt.tt_nrow - 1);
230: if (tt.tt_row == row) {
231: if (col == 0) {
232: ttxputs(gen_CR);
233: goto out;
234: }
235: if (tt.tt_col == col - 1) {
236: if (gen_ND) {
237: ttxputs(gen_ND);
238: goto out;
239: }
240: } else if (tt.tt_col == col + 1) {
241: if (gen_LE) {
242: ttxputs(gen_LE);
243: goto out;
244: }
245: }
246: }
247: if (tt.tt_col == col) {
248: if (tt.tt_row == row + 1) {
249: if (gen_UP) {
250: ttxputs(gen_UP);
251: goto out;
252: }
253: } else if (tt.tt_row == row - 1) {
254: ttxputs(gen_DO);
255: goto out;
256: }
257: }
258: if (gen_HO && col == 0 && row == 0) {
259: ttxputs(gen_HO);
260: goto out;
261: }
262: tttgoto(gen_CM, col, row);
263: out:
264: tt.tt_col = col;
265: tt.tt_row = row;
266: }
267:
268: gen_start()
269: {
270: if (gen_VS)
271: ttxputs(gen_VS);
272: if (gen_TI)
273: ttxputs(gen_TI);
274: ttxputs(gen_CL);
275: tt.tt_col = tt.tt_row = 0;
276: tt.tt_insert = 0;
277: tt.tt_nmodes = tt.tt_modes = 0;
278: }
279:
280: gen_end()
281: {
282: if (tt.tt_insert)
283: gen_setinsert(0);
284: if (gen_TE)
285: ttxputs(gen_TE);
286: if (gen_VE)
287: ttxputs(gen_VE);
288: }
289:
290: gen_clreol()
291: {
292: if (tt.tt_modes) /* for concept 100 */
293: gen_setmodes(0);
294: tttputs(gen_CE, gen_CO - tt.tt_col);
295: }
296:
297: gen_clreos()
298: {
299: if (tt.tt_modes) /* for concept 100 */
300: gen_setmodes(0);
301: tttputs(gen_CD, gen_LI - tt.tt_row);
302: }
303:
304: gen_clear()
305: {
306: if (tt.tt_modes) /* for concept 100 */
307: gen_setmodes(0);
308: ttxputs(gen_CL);
309: }
310:
311: gen_inschar(c)
312: register char c;
313: {
314: if (!tt.tt_insert)
315: gen_setinsert(1);
316: if (tt.tt_nmodes != tt.tt_modes)
317: gen_setmodes(tt.tt_nmodes);
318: if (gen_IC)
319: tttputs(gen_IC, gen_CO - tt.tt_col);
320: ttputc(c);
321: if (gen_IP)
322: tttputs(gen_IP, gen_CO - tt.tt_col);
323: if (++tt.tt_col == gen_CO)
324: if (gen_XN)
325: tt.tt_col = tt.tt_row = -10;
326: else if (gen_AM)
327: tt.tt_col = 0, tt.tt_row++;
328: else
329: tt.tt_col--;
330: }
331:
332: gen_insspace(n)
333: {
334: if (gen_ICn)
335: ttpgoto(gen_ICn, 0, n, gen_CO - tt.tt_col);
336: else
337: while (--n >= 0)
338: tttputs(gen_IC, gen_CO - tt.tt_col);
339: }
340:
341: gen_delchar(n)
342: {
343: if (gen_DCn)
344: ttpgoto(gen_DCn, 0, n, gen_CO - tt.tt_col);
345: else
346: while (--n >= 0)
347: tttputs(gen_DC, gen_CO - tt.tt_col);
348: }
349:
350: gen_scroll_down(n)
351: {
352: gen_move(tt.tt_scroll_bot, 0);
353: if (gen_SFn)
354: ttpgoto(gen_SFn, 0, n, n);
355: else
356: while (--n >= 0)
357: ttxputs(gen_SF);
358: }
359:
360: gen_scroll_up(n)
361: {
362: gen_move(tt.tt_scroll_top, 0);
363: if (gen_SRn)
364: ttpgoto(gen_SRn, 0, n, n);
365: else
366: while (--n >= 0)
367: ttxputs(gen_SR);
368: }
369:
370: gen_setscroll(top, bot)
371: {
372: tttgoto(gen_CS, bot, top);
373: tt.tt_scroll_top = top;
374: tt.tt_scroll_bot = bot;
375: tt.tt_row = tt.tt_col = -10;
376: }
377:
378: tt_generic()
379: {
380: gen_PC = tttgetstr("pc");
381: PC = gen_PC ? *gen_PC->ts_str : 0;
382: #ifndef POSIX_TTY
383: ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
384: #else
385: #ifdef CBAUD
386: ospeed = wwoldtty.ww_termios.c_cflag & CBAUD;
387: #else
388: ospeed = wwoldtty.ww_termios.c_ospeed; /* XXX */
389: #endif
390: #endif
391:
392: gen_CM = ttxgetstr("cm"); /* may not work */
393: gen_IM = ttxgetstr("im");
394: gen_IC = tttgetstr("ic");
395: gen_ICn = tttgetstr("IC");
396: gen_IP = tttgetstr("ip");
397: gen_EI = ttxgetstr("ei");
398: gen_DC = tttgetstr("dc");
399: gen_DCn = tttgetstr("DC");
400: gen_AL = tttgetstr("al");
401: gen_ALn = tttgetstr("AL");
402: gen_DL = tttgetstr("dl");
403: gen_DLn = tttgetstr("DL");
404: gen_CE = tttgetstr("ce");
405: gen_CD = tttgetstr("cd");
406: gen_CL = ttxgetstr("cl");
407: gen_VS = ttxgetstr("vs");
408: gen_VE = ttxgetstr("ve");
409: gen_TI = ttxgetstr("ti");
410: gen_TE = ttxgetstr("te");
411: gen_SO = ttxgetstr("so");
412: gen_SE = ttxgetstr("se");
413: gen_US = ttxgetstr("us");
414: gen_UE = ttxgetstr("ue");
415: gen_LE = ttxgetstr("le");
416: gen_ND = ttxgetstr("nd");
417: gen_UP = ttxgetstr("up");
418: gen_DO = ttxgetstr("do");
419: gen_BC = ttxgetstr("bc");
420: gen_NL = ttxgetstr("nl");
421: gen_CR = ttxgetstr("cr");
422: gen_HO = ttxgetstr("ho");
423: gen_AS = ttxgetstr("as");
424: gen_AE = ttxgetstr("ae");
425: gen_XS = ttxgetstr("XS");
426: gen_XE = ttxgetstr("XE");
427: gen_SF = ttxgetstr("sf");
428: gen_SFn = ttxgetstr("SF");
429: gen_SR = ttxgetstr("sr");
430: gen_SRn = ttxgetstr("SR");
431: gen_CS = ttxgetstr("cs");
432: gen_MI = tgetflag("mi");
433: gen_MS = tgetflag("ms");
434: gen_AM = tgetflag("am");
435: gen_OS = tgetflag("os");
436: gen_BS = tgetflag("bs");
437: gen_DA = tgetflag("da");
438: gen_DB = tgetflag("db");
439: gen_NS = tgetflag("ns");
440: gen_XN = tgetflag("xn");
441: gen_CO = tgetnum("co");
442: gen_LI = tgetnum("li");
443: gen_UG = tgetnum("ug");
444: gen_SG = tgetnum("sg");
445: if (gen_CL == 0 || gen_OS || gen_CM == 0)
446: return -1;
447:
448: /*
449: * Deal with obsolete termcap fields.
450: */
451: if (gen_LE == 0)
452: if (gen_BC)
453: gen_LE = gen_BC;
454: else if (gen_BS) {
455: static struct tt_str bc = { "\b", 1 };
456: gen_BC = &bc;
457: }
458: if (gen_NL == 0) {
459: static struct tt_str nl = { "\n", 1 };
460: gen_NL = &nl;
461: }
462: if (gen_DO == 0)
463: gen_DO = gen_NL;
464: if (gen_CR == 0) {
465: static struct tt_str cr = { "\r", 1 };
466: gen_CR = &cr;
467: }
468: /*
469: * Most terminal will scroll with "nl", but very few specify "sf".
470: * We shouldn't use "do" here.
471: */
472: if (gen_SF == 0 && !gen_NS)
473: gen_SF = gen_NL;
474: BC = gen_LE ? gen_LE->ts_str : 0;
475: UP = gen_UP ? gen_UP->ts_str : 0;
476: /*
477: * Fix up display attributes that we can't handle, or don't
478: * really exist.
479: */
480: if (gen_SG > 0)
481: gen_SO = 0;
482: if (gen_UG > 0 || gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0)
483: gen_US = 0;
484:
485: if (gen_IM && gen_IM->ts_n == 0) {
486: free((char *) gen_IM);
487: gen_IM = 0;
488: }
489: if (gen_EI && gen_EI->ts_n == 0) {
490: free((char *) gen_EI);
491: gen_EI = 0;
492: }
493: if (gen_IC && gen_IC->ts_n == 0) {
494: free((char *) gen_IC);
495: gen_IC = 0;
496: }
497: if (gen_IM)
498: tt.tt_inschar = gen_inschar;
499: else if (gen_IC)
500: tt.tt_insspace = gen_insspace;
501: if (gen_DC)
502: tt.tt_delchar = gen_delchar;
503: if (gen_AL)
504: tt.tt_insline = gen_insline;
505: if (gen_DL)
506: tt.tt_delline = gen_delline;
507: if (gen_CE)
508: tt.tt_clreol = gen_clreol;
509: if (gen_CD)
510: tt.tt_clreos = gen_clreos;
511: if (gen_SF)
512: tt.tt_scroll_down = gen_scroll_down;
513: /*
514: * Don't allow scroll_up if da or db but not cs.
515: * See comment in wwscroll.c.
516: */
517: if (gen_SR && (gen_CS || !gen_DA && !gen_DB))
518: tt.tt_scroll_up = gen_scroll_up;
519: if (gen_CS)
520: tt.tt_setscroll = gen_setscroll;
521: if (gen_SO)
522: tt.tt_availmodes |= WWM_REV;
523: if (gen_US)
524: tt.tt_availmodes |= WWM_UL;
525: if (gen_AS)
526: tt.tt_availmodes |= WWM_GRP;
527: if (gen_XS)
528: tt.tt_availmodes |= WWM_USR;
529: tt.tt_wrap = gen_AM;
530: tt.tt_retain = gen_DB;
531: tt.tt_ncol = gen_CO;
532: tt.tt_nrow = gen_LI;
533: tt.tt_start = gen_start;
534: tt.tt_end = gen_end;
535: tt.tt_write = gen_write;
536: tt.tt_putc = gen_putc;
537: tt.tt_move = gen_move;
538: tt.tt_clear = gen_clear;
539: tt.tt_setmodes = gen_setmodes;
540: tt.tt_frame = gen_AS && ttstrcmp(gen_AS, &ansi_AS) == 0 ?
541: ansi_frame : gen_frame;
542: return 0;
543: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.