|
|
1.1 root 1: /*
2: * Copyright (c) 1981 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
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.
16: *
17: * Modifications copyright (c) 1989 by INETCO Systems, Ltd.
18: */
19:
20: #define uchar unsigned char
21:
22: #ifndef COHERENT
23: #ifndef lint
24: static uchar sccsid[] = "@(#)cr_tty.c 5.4 (Berkeley) 6/30/88";
25: #endif /* not lint */
26: #endif /* not COHERENT */
27:
28: /*
29: * Terminal initialization routines.
30: *
31: */
32:
33: # include "curses.ext"
34:
35: static uchar *_PC;
36:
37: uchar *tgoto();
38:
39: uchar _tspace[2048]; /* Space for capability strings */
40:
41: static uchar *aoftspace; /* Address of _tspace for relocation */
42:
43: static int destcol, destline;
44:
45: /*
46: * This routine does terminal type initialization routines, and
47: * calculation of flags at entry. It is almost entirely stolen from
48: * Bill Joy's ex version 2.6.
49: */
50: extern short ospeed;
51:
52: gettmode() {
53:
54: if (gtty(_tty_ch, &_tty) < 0)
55: return;
56: savetty();
57: if (stty(_tty_ch, &_tty) < 0)
58: _tty.sg_flags = _res_flg;
59: ospeed = _tty.sg_ospeed;
60: _res_flg = _tty.sg_flags;
61: UPPERCASE = (_tty.sg_flags & LCASE) != 0;
62: GT = ((_tty.sg_flags & XTABS) == 0);
63: NONL = ((_tty.sg_flags & CRMOD) == 0);
64: _tty.sg_flags &= ~XTABS;
65: stty(_tty_ch, &_tty);
66: # ifdef DEBUG
67: fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE");
68: fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE");
69: fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE");
70: fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed);
71: # endif
72: }
73:
74: setterm(type)
75: reg uchar *type;
76: {
77:
78: reg int unknown;
79: static uchar genbuf[1024];
80: # ifdef TIOCGWINSZ
81: struct winsize win;
82: # endif
83:
84: # ifdef DEBUG
85: fprintf(outf, "SETTERM(\"%s\")\n", type);
86: fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
87: # endif
88: if (type[0] == '\0')
89: type = "xx";
90: unknown = FALSE;
91: if (tgetent(genbuf, type) != 1) {
92: unknown++;
93: strcpy(genbuf, "xx|dumb:");
94: }
95: # ifdef DEBUG
96: fprintf(outf, "SETTERM: tty = %s\n", type);
97: # endif
98: # ifdef TIOCGWINSZ
99: if (ioctl(_tty_ch, TIOCGWINSZ, &win) >= 0) {
100: if (LINES == 0)
101: LINES = win.ws_row;
102: if (COLS == 0)
103: COLS = win.ws_col;
104: }
105: # endif
106:
107: if (LINES == 0)
108: LINES = tgetnum("li");
109: if (LINES <= 5)
110: LINES = 24;
111:
112: if (COLS == 0)
113: COLS = tgetnum("co");
114: if (COLS <= 4)
115: COLS = 80;
116:
117: # ifdef DEBUG
118: fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
119: # endif
120: aoftspace = _tspace;
121:
122: /*
123: * Extract boolean capabilities.
124: */
125: {
126: register tflgent_t * fp;
127:
128: for ( fp = tflgmap; fp->bp != NULL; fp++ ) {
129: *(fp->bp) = tgetflag(fp->id);
130: #ifdef DEBUG
131: fprintf( outf, "%2.2s = %s", fp->id,
132: *(fp->bp) ? "TRUE" : "FALSE" );
133: #endif
134: }
135: }
136:
137: /*
138: * Extract string capabilities.
139: */
140: {
141: register tstrent_t *sp;
142: extern uchar *tgetstr();
143:
144: for ( sp = tstrmap; sp->cpp != NULL; sp++ ) {
145: *(sp->cpp) = tgetstr(sp->id, &aoftspace);
146: #ifdef DEBUG
147: {
148: fprintf(outf, "%2.2s = %s", sp->id,
149: *(sp->cpp) == NULL ? "NULL\n" : "\"");
150: if (*(sp->cpp) != NULL) {
151: uchar * cp;
152: for (cp = *(sp->cpp); *cp; cp++)
153: fprintf(outf,"%s",unctrl(*cp));
154: fprintf(outf, "\"\n");
155: }
156: }
157: #endif
158: }
159: }
160:
161: /*
162: * Standout not erased by writing over it - disable standout mode.
163: */
164: if (XS)
165: SO = SE = NULL;
166:
167: /*
168: * Entering/exiting standout mode consumes display memory.
169: * Disable standout mode.
170: */
171: if ( (magic_cookie_glitch = tgetnum( "sg" )) > 0 )
172: SO = NULL;
173:
174: /*
175: * Entering/exiting underline mode consumes display memory.
176: * Disable underline mode.
177: */
178: if (tgetnum("ug") > 0)
179: US = NULL;
180:
181: /*
182: * Standout mode not provided, but underline mode is.
183: * Map standout mode into underline mode.
184: */
185: if (!SO && US) {
186: SO = US;
187: SE = UE;
188: }
189:
190: /*
191: * Handle funny termcap capabilities
192: */
193: if (CS && SC && RC) AL=DL="";
194: if (AL_PARM && AL==NULL) AL="";
195: if (DL_PARM && DL==NULL) DL="";
196: if (IC && IM==NULL) IM="";
197: if (IC && EI==NULL) EI="";
198: if (!GT) BT=NULL; /* If we can't tab, we can't backtab either */
199:
200: if (tgoto(CM, destcol, destline)[0] == 'O')
201: CA = FALSE, CM = 0;
202: else
203: CA = TRUE;
204:
205: PC = _PC ? _PC[0] : FALSE;
206: aoftspace = _tspace;
207: strncpy(ttytype, longname(genbuf, type), sizeof(ttytype) - 1);
208: ttytype[sizeof(ttytype) - 1] = '\0';
209: if (unknown)
210: return ERR;
211: return OK;
212: }
213:
214: /*
215: * return a capability from termcap
216: */
217: uchar *
218: getcap(name)
219: uchar *name;
220: {
221: uchar *tgetstr();
222:
223: return tgetstr(name, &aoftspace);
224: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.