source: trunk/src/emx/bsd/curses/cr_tty.c@ 1322

Last change on this file since 1322 was 272, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.5 KB
Line 
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, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char sccsid[] = "@(#)cr_tty.c 5.8 (Berkeley) 6/1/90";
36#endif /* not lint */
37
38/*
39 * Terminal initialization routines.
40 *
41 */
42
43# include "curses.ext"
44
45static bool *sflags[] = {
46 &AM, &BS, &DA, &DB, &EO, &HC, &HZ, &IN, &MI,
47 &MS, &NC, &NS, &OS, &UL, &XB, &XN, &XT, &XS,
48 &XX
49 };
50
51static char *_PC,
52 **sstrs[] = {
53 &AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS,
54 &DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2,
55 &K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC,
56 &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU,
57 &LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF,
58 &SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US,
59 &VB, &VS, &VE, &AL_PARM, &DL_PARM, &UP_PARM,
60 &DOWN_PARM, &LEFT_PARM, &RIGHT_PARM,
61 };
62
63extern char *tgoto();
64
65char _tspace[2048]; /* Space for capability strings */
66
67static char *aoftspace; /* Address of _tspace for relocation */
68
69static int destcol, destline;
70
71/*
72 * This routine does terminal type initialization routines, and
73 * calculation of flags at entry. It is almost entirely stolen from
74 * Bill Joy's ex version 2.6.
75 */
76short ospeed = -1;
77
78gettmode() {
79
80# ifdef OS2
81 ioctl (_tty_ch, TCGETA, &_tty);
82 savetty();
83 ospeed = B38400;
84 UPPERCASE = 0;
85 GT = ((_tty.c_iflag & IUCLC) == 0);
86 NONL = ((_tty.c_iflag & ICRNL) == 0);
87# else
88 if (ioctl(_tty_ch, TIOCGETP, &_tty) < 0)
89 return;
90 savetty();
91 if (ioctl(_tty_ch, TIOCSETP, &_tty) < 0)
92 _tty.sg_flags = _res_flg;
93 ospeed = _tty.sg_ospeed;
94 _res_flg = _tty.sg_flags;
95 UPPERCASE = (_tty.sg_flags & LCASE) != 0;
96 GT = ((_tty.sg_flags & XTABS) == 0);
97 NONL = ((_tty.sg_flags & CRMOD) == 0);
98 _tty.sg_flags &= ~XTABS;
99 ioctl(_tty_ch, TIOCSETP, &_tty);
100# endif
101# ifdef DEBUG
102 fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE");
103 fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE");
104 fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE");
105 fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed);
106# endif
107}
108
109setterm(type)
110reg char *type; {
111
112 reg int unknown;
113 static char genbuf[1024];
114# ifdef TIOCGWINSZ
115 struct winsize win;
116# endif
117
118# ifdef DEBUG
119 fprintf(outf, "SETTERM(\"%s\")\n", type);
120 fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
121# endif
122 if (type[0] == '\0')
123 type = "xx";
124 unknown = FALSE;
125 if (tgetent(genbuf, type) != 1) {
126 unknown++;
127 strcpy(genbuf, "xx|dumb:");
128 }
129# ifdef DEBUG
130 fprintf(outf, "SETTERM: tty = %s\n", type);
131# endif
132# ifdef TIOCGWINSZ
133 if (ioctl(_tty_ch, TIOCGWINSZ, &win) >= 0) {
134 if (LINES == 0)
135 LINES = win.ws_row;
136 if (COLS == 0)
137 COLS = win.ws_col;
138 }
139# endif
140# ifdef OS2
141 {
142 int result[2];
143 _scrsize(result);
144 LINES = result[1];
145 COLS = result[0];
146 }
147# endif
148
149 if (LINES == 0)
150 LINES = tgetnum("li");
151 if (LINES <= 5)
152 LINES = 24;
153
154 if (COLS == 0)
155 COLS = tgetnum("co");
156 if (COLS <= 4)
157 COLS = 80;
158
159# ifdef DEBUG
160 fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
161# endif
162 aoftspace = _tspace;
163 zap(); /* get terminal description */
164
165 /*
166 * Handle funny termcap capabilities
167 */
168 if (CS && SC && RC) AL=DL="";
169 if (AL_PARM && AL==NULL) AL="";
170 if (DL_PARM && DL==NULL) DL="";
171 if (IC && IM==NULL) IM="";
172 if (IC && EI==NULL) EI="";
173 if (!GT) BT=NULL; /* If we can't tab, we can't backtab either */
174
175 if (tgoto(CM, destcol, destline)[0] == 'O')
176 CA = FALSE, CM = 0;
177 else
178 CA = TRUE;
179
180 PC = _PC ? _PC[0] : FALSE;
181 aoftspace = _tspace;
182 {
183 /* xtype should be the same size as genbuf for longname(). */
184 static char xtype[1024];
185
186 (void)strcpy(xtype,type);
187 strncpy(ttytype, longname(genbuf, xtype), sizeof(ttytype) - 1);
188 }
189 ttytype[sizeof(ttytype) - 1] = '\0';
190 if (unknown)
191 return ERR;
192 return OK;
193}
194
195/*
196 * This routine gets all the terminal flags from the termcap database
197 */
198
199zap()
200{
201 register char *namp;
202 register bool **fp;
203 register char ***sp;
204#ifdef DEBUG
205 register char *cp;
206#endif
207 extern char *tgetstr();
208 char flag[3];
209
210 namp = "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx";
211 fp = sflags;
212 do {
213 strncpy(flag, namp, 2);
214 flag[2] = 0;
215 *(*fp++) = tgetflag(flag);
216#ifdef DEBUG
217 fprintf(outf, "%2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
218#endif
219 namp += 2;
220 } while (*namp);
221 namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI";
222 sp = sstrs;
223 do {
224 *(*sp++) = tgetstr(namp, &aoftspace);
225#ifdef DEBUG
226 fprintf(outf, "%2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
227 if (*sp[-1] != NULL) {
228 for (cp = *sp[-1]; *cp; cp++)
229 fprintf(outf, "%s", unctrl(*cp));
230 fprintf(outf, "\"\n");
231 }
232#endif
233 namp += 2;
234 } while (*namp);
235 if (XS)
236 SO = SE = NULL;
237 else {
238 if (tgetnum("sg") > 0)
239 SO = NULL;
240 if (tgetnum("ug") > 0)
241 US = NULL;
242 if (!SO && US) {
243 SO = US;
244 SE = UE;
245 }
246 }
247}
248
249/*
250 * return a capability from termcap
251 */
252char *
253getcap(name)
254char *name;
255{
256 char *tgetstr();
257
258 return tgetstr(name, &aoftspace);
259}
Note: See TracBrowser for help on using the repository browser.