* Copyright (c) 1981 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)setterm.c 5.10 (Berkeley) %G%";
static void zap
__P((void));
static char *sflags
[] = {
&AM
, &BS
, &DA
, &EO
, &HC
, &HZ
, &IN
, &MI
, &MS
,
&NC
, &NS
, &OS
, &UL
, &XB
, &XN
, &XT
, &XS
, &XX
&AL
, &BC
, &BT
, &CD
, &CE
, &CL
, &CM
, &CR
, &CS
,
&DC
, &DL
, &DM
, &DO
, &ED
, &EI
, &K0
, &K1
, &K2
,
&K3
, &K4
, &K5
, &K6
, &K7
, &K8
, &K9
, &HO
, &IC
,
&IM
, &IP
, &KD
, &KE
, &KH
, &KL
, &KR
, &KS
, &KU
,
&LL
, &MA
, &ND
, &NL
, &_PC
, &RC
, &SC
, &SE
, &SF
,
&SO
, &SR
, &TA
, &TE
, &TI
, &UC
, &UE
, &UP
, &US
,
&VB
, &VS
, &VE
, &AL_PARM
, &DL_PARM
, &UP_PARM
,
&DOWN_PARM
, &LEFT_PARM
, &RIGHT_PARM
,
static char *aoftspace
; /* Address of _tspace for relocation */
static char tspace
[2048]; /* Space for capability strings */
static int destcol
, destline
;
static char genbuf
[1024];
static char __ttytype
[1024];
__TRACE("setterm: (\"%s\")\nLINES = %d, COLS = %d\n",
if (tgetent(genbuf
, type
) != 1) {
strcpy(genbuf
, "xx|dumb:");
__TRACE("setterm: tty = %s\n", type
);
/* Try TIOCGWINSZ, and, if it fails, the termcap entry. */
if (ioctl(STDERR_FILENO
, TIOCGWINSZ
, &win
) != -1 &&
win
.ws_row
!= 0 && win
.ws_col
!= 0) {
/* POSIX 1003.2 requires that the environment override. */
if ((p
= getenv("ROWS")) != NULL
)
LINES
= strtol(p
, NULL
, 10);
if ((p
= getenv("COLUMNS")) != NULL
)
COLS
= strtol(p
, NULL
, 10);
* Historically, curses fails if rows <= 5, cols <= 4.
if (LINES
<= 5 || COLS
<= 4)
__TRACE("setterm: LINES = %d, COLS = %d\n", LINES
, COLS
);
zap(); /* Get terminal description. */
/* Handle funny termcap capabilities. */
if (AL_PARM
&& AL
== NULL
)
if (DL_PARM
&& DL
== NULL
)
if (!GT
) /* If we can't tab, we can't backtab either. */
if (tgoto(CM
, destcol
, destline
)[0] == 'O') {
ttytype
= longname(genbuf
, __ttytype
);
return (unknown
? ERR
: OK
);
* Gets all the terminal flags from the termcap database.
register char *namp
, ***sp
;
namp
= "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx";
*(tmp
+ 1) = *(namp
+ 1);
*(*fp
++) = tgetflag(tmp
);
__TRACE("2.2s = %s\n", namp
, *fp
[-1] ? "TRUE" : "FALSE");
namp
= "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI";
*(tmp
+ 1) = *(namp
+ 1);
*(*sp
++) = tgetstr(tmp
, &aoftspace
);
__TRACE("2.2s = %s", namp
, *sp
[-1] == NULL
? "NULL\n" : "\"");
for (cp
= *sp
[-1]; *cp
; cp
++)
__TRACE("%s", unctrl(*cp
));
* Return a capability from termcap.
return (tgetstr(name
, &aoftspace
));