2 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
21 sccsid
[] = "@(#)cr_tty.c 1.7 88/02/08 SMI"; /* from UCB 5.2 85/11/08 */
25 * Terminal initialization routines.
34 /* forward declaration */
37 static bool *sflags
[] = {
38 &AM
, &BS
, &DA
, &DB
, &EO
, &HC
, &HZ
, &IN
, &MI
,
39 &MS
, &NC
, &NS
, &OS
, &UL
, &XB
, &XN
, &XT
, &XS
,
45 &AL
, &BC
, &BT
, &CD
, &CE
, &CL
, &CM
, &CR
, &CS
,
46 &DC
, &DL
, &DM
, &DO
, &ED
, &EI
, &K0
, &K1
, &K2
,
47 &K3
, &K4
, &K5
, &K6
, &K7
, &K8
, &K9
, &HO
, &IC
,
48 &IM
, &IP
, &KD
, &KE
, &KH
, &KL
, &KR
, &KS
, &KU
,
49 &LL
, &MA
, &ND
, &NL
, &_PC
, &RC
, &SC
, &SE
, &SF
,
50 &SO
, &SR
, &TA
, &TE
, &TI
, &UC
, &UE
, &UP
, &US
,
51 &VB
, &VS
, &VE
, &AL_PARM
, &DL_PARM
, &UP_PARM
,
52 &DOWN_PARM
, &LEFT_PARM
, &RIGHT_PARM
,
55 char _tspace
[2048]; /* Space for capability strings */
57 static char *aoftspace
; /* Address of _tspace for relocation */
59 static int destcol
, destline
;
62 * This routine does terminal type initialization routines, and
63 * calculation of flags at entry. It is almost entirely stolen from
64 * Bill Joy's ex version 2.6.
71 if (gtty(_tty_ch
, &_tty
) < 0)
74 if (stty(_tty_ch
, &_tty
) < 0)
75 _tty
.sg_flags
= _res_flg
;
76 ospeed
= _tty
.sg_ospeed
;
77 _res_flg
= _tty
.sg_flags
;
78 UPPERCASE
= (_tty
.sg_flags
& LCASE
) != 0;
79 GT
= ((_tty
.sg_flags
& XTABS
) == 0);
80 NONL
= ((_tty
.sg_flags
& CRMOD
) == 0);
81 _tty
.sg_flags
&= ~XTABS
;
82 (void) stty(_tty_ch
, &_tty
);
84 fprintf(outf
, "GETTMODE: UPPERCASE = %s\n", UPPERCASE
? "TRUE":"FALSE");
85 fprintf(outf
, "GETTMODE: GT = %s\n", GT
? "TRUE" : "FALSE");
86 fprintf(outf
, "GETTMODE: NONL = %s\n", NONL
? "TRUE" : "FALSE");
87 fprintf(outf
, "GETTMODE: ospeed = %d\n", ospeed
);
96 static char genbuf
[1024];
102 fprintf(outf
, "SETTERM(\"%s\")\n", type
);
103 fprintf(outf
, "SETTERM: LINES = %d, COLS = %d\n", LINES
, COLS
);
108 if (tgetent(genbuf
, type
) != 1) {
110 (void) strcpy(genbuf
, "xx|dumb:");
113 fprintf(outf
, "SETTERM: tty = %s\n", type
);
116 if (ioctl(_tty_ch
, TIOCGWINSZ
, &win
) >= 0) {
125 LINES
= tgetnum("li");
130 COLS
= tgetnum("co");
135 fprintf(outf
, "SETTERM: LINES = %d, COLS = %d\n", LINES
, COLS
);
138 zap(); /* get terminal description */
141 * Handle funny termcap capabilities
143 if (CS
&& SC
&& RC
) AL
= DL
= "";
144 if (AL_PARM
&& AL
== NULL
) AL
= "";
145 if (DL_PARM
&& DL
== NULL
) DL
= "";
146 if (IC
&& IM
== NULL
) IM
= "";
147 if (IC
&& EI
== NULL
) EI
= "";
148 if (!GT
) BT
= NULL
; /* If we can't tab, we can't backtab either */
150 if (tgoto(CM
, destcol
, destline
)[0] == 'O')
155 PC
= _PC
? _PC
[0] : FALSE
;
157 (void) strncpy(ttytype
, longname(genbuf
, type
), sizeof (ttytype
) - 1);
158 ttytype
[sizeof (ttytype
) - 1] = '\0';
165 * This routine gets all the terminal flags from the termcap database
178 namp
= "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx";
181 *(*fp
++) = tgetflag(namp
);
183 fprintf(outf
, "%2.2s = %s\n", namp
, *fp
[-1] ? "TRUE" : "FALSE");
187 namp
= "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9"
188 "hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatet"
189 "iucueupusvbvsveALDLUPDOLERI";
192 *(*sp
++) = tgetstr(namp
, &aoftspace
);
194 fprintf(outf
, "%2.2s = %s",
195 namp
, *sp
[-1] == NULL
? "NULL\n" : "\"");
196 if (*sp
[-1] != NULL
) {
197 for (cp
= *sp
[-1]; *cp
; cp
++)
198 fprintf(outf
, "%s", unctrl(*cp
));
199 fprintf(outf
, "\"\n");
207 if (tgetnum("sg") > 0)
209 if (tgetnum("ug") > 0)
219 * return a capability from termcap
225 return (tgetstr(name
, &aoftspace
));