|
|
1.1 root 1: /*
2: * Terminal initialization routines.
3: *
4: * 5/15/81 (Berkeley) @(#)cr_tty.c 1.3
5: */
6:
7: # undef DEBUG
8:
9: # include "curses.ext"
10: # include "cr_ex.h"
11:
12: static bool *sflags[] = {
13: &AM, &BS, &EO, &HZ, &IN, &MI, &MS, &NC, &OS, &UL, &XN
14: };
15:
16: static char *xPC,
17: **sstrs[] = {
18: &AL, &BC, &BT, &CD, &CE, &CL, &CM, &DC, &DL,
19: &DM, &DO, &ED, &EI, &HO, &IC, &IM, &IP, &LL,
20: &MA, &ND, &xPC, &SE, &SF, &SO, &SR, &TA, &TE,
21: &TI, &UC, &UE, &UP, &US, &VB, &VS, &VE
22: },
23: *tgoto();
24:
25: static char tspace[128], /* Space for capability strings */
26: *aoftspace; /* Address of tspace for relocation */
27:
28: static int destcol, destline;
29:
30: /*
31: * This routine does terminal type initialization routines, and
32: * calculation of flags at entry. It is almost entirely stolen from
33: * Bill Joy's ex version 2.6.
34: */
35: short ospeed = -1;
36:
37: gettmode() {
38: struct ttydevb tt;
39:
40: if (ioctl(_tty_ch, TIOCGETP, &_tty) < 0)
41: return;
42: savetty();
43: if (ioctl(_tty_ch, TIOCSETP, &_tty) < 0)
44: _tty.sg_flags = _res_flg;
45: if (ioctl(_tty_ch, TIOCGDEV, &tt) >= 0)
46: ospeed = tt.ospeed;
47: _res_flg = _tty.sg_flags;
48: UPPERCASE = (_tty.sg_flags & LCASE) != 0;
49: GT = ((_tty.sg_flags & XTABS) == 0);
50: NONL = ((_tty.sg_flags & CRMOD) == 0);
51: # ifdef DEBUG
52: fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE");
53: fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE");
54: fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE");
55: fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed);
56: # endif
57: }
58:
59: setterm(type)
60: reg char *type; {
61:
62: reg int unknown;
63: char genbuf[1024];
64:
65: # ifdef DEBUG
66: fprintf(outf, "SETTERM(\"%s\")\n", type);
67: fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
68: # endif
69: if (type[0] == '\0')
70: type = "xx";
71: unknown = FALSE;
72: if (tgetent(genbuf, type) != 1) {
73: unknown++;
74: strcpy(genbuf, "xx|dumb:");
75: }
76: # ifdef DEBUG
77: fprintf(outf, "SETTERM: tty = %s\n", type);
78: # endif
79: if (LINES == 0)
80: LINES = tgetnum("li");
81: if (LINES <= 5)
82: LINES = 24;
83: else if (LINES > 80)
84: LINES = 80;
85:
86: if (COLS == 0)
87: COLS = tgetnum("co");
88: if (COLS <= 4)
89: COLS = 80;
90: else if (COLS > 1000)
91: COLS = 1000;
92: # ifdef DEBUG
93: fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
94: # endif
95: aoftspace = tspace;
96: zap(); /* get terminal description */
97: if (tgoto(CM, destcol, destline)[0] == 'O')
98: CA = FALSE, CM = 0;
99: else
100: CA = TRUE;
101: PC = xPC ? xPC[0] : FALSE;
102: aoftspace = tspace;
103: strcpy(ttytype, longname(genbuf, type));
104: if (unknown)
105: return ERR;
106: return OK;
107: }
108: /*
109: * This routine gets all the terminal falgs from the termcap database
110: */
111: zap() {
112:
113: reg bool **fp;
114: reg char *namp, ***sp;
115: extern char *tgetstr();
116:
117: /*
118: * get boolean flags
119: */
120: namp = "ambseohzinmimsncosulxn\0\0";
121: # ifdef FULLDEBUG
122: fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
123: # endif
124: fp = sflags;
125: do {
126: *(*fp++) = tgetflag(namp);
127: # ifdef FULLDEBUG
128: fprintf(outf, "ZAP: %.2s = %d", namp, *(*(fp - 1)));
129: # endif
130: namp += 2;
131: } while (*namp);
132:
133: /*
134: * get string values
135: */
136: namp = "albcbtcdceclcmdcdldmdoedeihoicimipllmandpcsesfsosrtatetiucueupusvbvsve";
137: # ifdef FULLDEBUG
138: fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
139: # endif
140: sp = sstrs;
141: do {
142: *(*sp++) = tgetstr(namp, &aoftspace);
143: # ifdef FULLDEBUG
144: fprintf(outf, "ZAP: %.2s = \"%s\"\n", namp, *(*(sp-1)));
145: # endif
146: namp += 2;
147: } while (*namp);
148: if (!SO && US) {
149: SO = US;
150: SE = UE;
151: }
152: }
153:
154: /*
155: * get a string capability from the entry
156: */
157: char *
158: getcap(name)
159: char *name;
160: {
161: return tgetstr(name, &aoftspace);
162: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.