2003-02-02 20:54:38 +03:00
|
|
|
/* $NetBSD: setterm.c,v 1.36 2003/02/02 17:54:38 jdc Exp $ */
|
1997-07-22 11:36:20 +04:00
|
|
|
|
1993-08-07 09:51:11 +04:00
|
|
|
/*
|
1994-08-18 01:51:41 +04:00
|
|
|
* Copyright (c) 1981, 1993, 1994
|
1993-11-09 06:34:01 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-08-07 09:51:11 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-22 11:36:20 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-07 09:51:11 +04:00
|
|
|
#ifndef lint
|
1997-07-22 11:36:20 +04:00
|
|
|
#if 0
|
1998-01-30 07:33:32 +03:00
|
|
|
static char sccsid[] = "@(#)setterm.c 8.8 (Berkeley) 10/25/94";
|
1997-07-22 11:36:20 +04:00
|
|
|
#else
|
2003-02-02 20:54:38 +03:00
|
|
|
__RCSID("$NetBSD: setterm.c,v 1.36 2003/02/02 17:54:38 jdc Exp $");
|
1997-07-22 11:36:20 +04:00
|
|
|
#endif
|
1993-08-07 09:51:11 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1994-08-18 01:51:41 +04:00
|
|
|
#include <sys/ioctl.h> /* TIOCGWINSZ on old systems. */
|
1993-08-07 09:51:11 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-08-18 01:51:41 +04:00
|
|
|
#include <termios.h>
|
1993-08-07 09:51:11 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
1994-08-18 01:51:41 +04:00
|
|
|
#include "curses.h"
|
2000-04-13 01:45:30 +04:00
|
|
|
#include "curses_private.h"
|
1994-08-18 01:51:41 +04:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
static int zap(SCREEN *screen);
|
2000-04-19 17:52:39 +04:00
|
|
|
|
2003-01-28 00:12:29 +03:00
|
|
|
static int does_esc_m(char *cap);
|
2003-02-02 20:54:38 +03:00
|
|
|
static int does_ctrl_o(char *cap);
|
2003-01-28 00:12:29 +03:00
|
|
|
|
2000-04-19 17:52:39 +04:00
|
|
|
struct tinfo *_cursesi_genbuf;
|
1993-08-07 09:51:11 +04:00
|
|
|
|
|
|
|
static char *sflags[] = {
|
2001-12-02 12:14:20 +03:00
|
|
|
/* am bs cc da eo */
|
|
|
|
&__tc_am, &__tc_bs, &__tc_cc, &__tc_da, &__tc_eo,
|
|
|
|
/* hc hl in mi ms */
|
|
|
|
&__tc_hc, &__tc_hl, &__tc_in, &__tc_mi, &__tc_ms,
|
|
|
|
/* nc ns os ul ut */
|
|
|
|
&__tc_nc, &__tc_ns, &__tc_os, &__tc_ul, &__tc_ut,
|
|
|
|
/* xb xn xt xs xx */
|
|
|
|
&__tc_xb, &__tc_xn, &__tc_xt, &__tc_xs, &__tc_xx
|
|
|
|
};
|
1993-08-07 09:51:11 +04:00
|
|
|
|
2000-04-13 01:45:30 +04:00
|
|
|
static int *svals[] = {
|
2001-12-02 12:14:20 +03:00
|
|
|
/* pa Co NC */
|
|
|
|
&__tc_pa, &__tc_Co, &__tc_NC
|
|
|
|
};
|
|
|
|
|
1993-08-07 09:51:11 +04:00
|
|
|
static char *_PC,
|
2001-12-02 12:14:20 +03:00
|
|
|
**sstrs[] = {
|
|
|
|
/* AB ac ae AF AL */
|
|
|
|
&__tc_AB, &__tc_ac, &__tc_ae, &__tc_AF, &__tc_AL,
|
|
|
|
/* al as bc bl bt */
|
|
|
|
&__tc_al, &__tc_as, &__tc_bc, &__tc_bl, &__tc_bt,
|
|
|
|
/* cd ce cl cm cr */
|
|
|
|
&__tc_cd, &__tc_ce, &__tc_cl, &__tc_cm, &__tc_cr,
|
|
|
|
/* cs dc DL dl dm */
|
|
|
|
&__tc_cs, &__tc_dc, &__tc_DL, &__tc_dl, &__tc_dm,
|
|
|
|
/* DO do eA ed ei */
|
|
|
|
&__tc_DO, &__tc_do, &__tc_eA, &__tc_ed, &__tc_ei,
|
|
|
|
/* ho Ic ic im Ip */
|
|
|
|
&__tc_ho, &__tc_Ic, &__tc_ic, &__tc_im, &__tc_Ip,
|
|
|
|
/* ip k0 k1 k2 k3 */
|
|
|
|
&__tc_ip, &__tc_k0, &__tc_k1, &__tc_k2, &__tc_k3,
|
|
|
|
/* k4 k5 k6 k7 k8 */
|
|
|
|
&__tc_k4, &__tc_k5, &__tc_k6, &__tc_k7, &__tc_k8,
|
|
|
|
/* k9 kd ke kh kl */
|
|
|
|
&__tc_k9, &__tc_kd, &__tc_ke, &__tc_kh, &__tc_kl,
|
|
|
|
/* kr ks ku LE ll */
|
|
|
|
&__tc_kr, &__tc_ks, &__tc_ku, &__tc_LE, &__tc_ll,
|
|
|
|
/* ma mb md me mh */
|
|
|
|
&__tc_ma, &__tc_mb, &__tc_md, &__tc_me, &__tc_mh,
|
|
|
|
/* mk mm mo mp mr */
|
|
|
|
&__tc_mk, &__tc_mm, &__tc_mo, &__tc_mp, &__tc_mr,
|
|
|
|
/* nd nl oc op pc */
|
|
|
|
&__tc_nd, &__tc_nl, &__tc_oc, &__tc_op, &_PC,
|
|
|
|
/* rc RI sc Sb se */
|
|
|
|
&__tc_rc, &__tc_RI, &__tc_Sb, &__tc_sc, &__tc_se,
|
|
|
|
/* SF Sf sf so sp */
|
|
|
|
&__tc_SF, &__tc_Sf, &__tc_sf, &__tc_so, &__tc_sp,
|
|
|
|
/* SR sr ta te ti */
|
|
|
|
&__tc_SR, &__tc_sr, &__tc_ta, &__tc_te, &__tc_ti,
|
|
|
|
/* uc ue UP up us */
|
|
|
|
&__tc_uc, &__tc_ue, &__tc_UP, &__tc_up, &__tc_us,
|
|
|
|
/* vb ve vi vs */
|
|
|
|
&__tc_vb, &__tc_ve, &__tc_vi, &__tc_vs
|
|
|
|
};
|
|
|
|
|
2000-12-20 00:34:24 +03:00
|
|
|
attr_t __mask_op, __mask_me, __mask_ue, __mask_se;
|
1993-08-07 09:51:11 +04:00
|
|
|
|
|
|
|
int
|
2000-04-15 17:17:02 +04:00
|
|
|
setterm(char *type)
|
1993-08-07 09:51:11 +04:00
|
|
|
{
|
2001-12-02 12:14:20 +03:00
|
|
|
return _cursesi_setterm(type, _cursesi_screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_cursesi_setterm(char *type, SCREEN *screen)
|
|
|
|
{
|
1998-02-03 22:12:13 +03:00
|
|
|
int unknown;
|
1993-08-07 09:51:11 +04:00
|
|
|
struct winsize win;
|
|
|
|
char *p;
|
2002-06-26 22:13:59 +04:00
|
|
|
char cm_buff[64];
|
1993-08-07 09:51:11 +04:00
|
|
|
|
|
|
|
if (type[0] == '\0')
|
|
|
|
type = "xx";
|
|
|
|
unknown = 0;
|
2001-12-02 12:14:20 +03:00
|
|
|
if (t_getent(&screen->cursesi_genbuf, type) != 1) {
|
1993-08-07 09:51:11 +04:00
|
|
|
unknown++;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
1993-11-09 06:34:01 +03:00
|
|
|
__CTRACE("setterm: tty = %s\n", type);
|
1993-08-07 09:51:11 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Try TIOCGWINSZ, and, if it fails, the termcap entry. */
|
2001-12-02 12:14:20 +03:00
|
|
|
if (ioctl(fileno(screen->outfd), TIOCGWINSZ, &win) != -1 &&
|
1993-08-07 09:51:11 +04:00
|
|
|
win.ws_row != 0 && win.ws_col != 0) {
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->LINES = win.ws_row;
|
|
|
|
screen->COLS = win.ws_col;
|
1993-08-07 09:51:11 +04:00
|
|
|
} else {
|
2000-04-19 17:52:39 +04:00
|
|
|
if (unknown) {
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->LINES = -1;
|
|
|
|
screen->COLS = -1;
|
2000-04-19 17:52:39 +04:00
|
|
|
} else {
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->LINES = t_getnum(screen->cursesi_genbuf, "li");
|
|
|
|
screen->COLS = t_getnum(screen->cursesi_genbuf, "co");
|
2000-04-19 17:52:39 +04:00
|
|
|
}
|
|
|
|
|
1993-08-07 09:51:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* POSIX 1003.2 requires that the environment override. */
|
1994-01-24 11:36:38 +03:00
|
|
|
if ((p = getenv("LINES")) != NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->LINES = (int) strtol(p, NULL, 10);
|
1993-08-07 09:51:11 +04:00
|
|
|
if ((p = getenv("COLUMNS")) != NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->COLS = (int) strtol(p, NULL, 10);
|
1993-08-07 09:51:11 +04:00
|
|
|
|
|
|
|
/*
|
1993-11-09 06:34:01 +03:00
|
|
|
* Want cols > 4, otherwise things will fail.
|
1993-08-07 09:51:11 +04:00
|
|
|
*/
|
2001-12-02 12:14:20 +03:00
|
|
|
if (screen->COLS <= 4)
|
1993-08-07 09:51:11 +04:00
|
|
|
return (ERR);
|
|
|
|
|
2002-12-05 20:04:25 +03:00
|
|
|
LINES = screen->LINES;
|
|
|
|
COLS = screen->COLS;
|
|
|
|
|
1993-08-07 09:51:11 +04:00
|
|
|
#ifdef DEBUG
|
1993-11-09 06:34:01 +03:00
|
|
|
__CTRACE("setterm: LINES = %d, COLS = %d\n", LINES, COLS);
|
1993-08-07 09:51:11 +04:00
|
|
|
#endif
|
2000-04-19 17:52:39 +04:00
|
|
|
if (!unknown) {
|
2001-12-02 12:14:20 +03:00
|
|
|
if (zap(screen) == ERR) /* Get terminal description.*/
|
2000-04-19 17:52:39 +04:00
|
|
|
return ERR;
|
|
|
|
}
|
2002-01-02 13:38:27 +03:00
|
|
|
|
1993-11-09 06:34:01 +03:00
|
|
|
/* If we can't tab, we can't backtab, either. */
|
2001-12-02 12:14:20 +03:00
|
|
|
if (!screen->GT)
|
|
|
|
screen->tc_bt = NULL;
|
1993-08-07 09:51:11 +04:00
|
|
|
|
1993-11-09 06:34:01 +03:00
|
|
|
/*
|
2000-04-19 17:52:39 +04:00
|
|
|
* Test for cursor motion capability.
|
1993-11-09 06:34:01 +03:00
|
|
|
*
|
|
|
|
*/
|
2002-06-26 22:13:59 +04:00
|
|
|
if (t_goto(NULL, screen->tc_cm, 0, 0, cm_buff, sizeof(cm_buff) - 1) < 0) {
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->CA = 0;
|
|
|
|
screen->tc_cm = 0;
|
1993-08-07 09:51:11 +04:00
|
|
|
} else
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->CA = 1;
|
1993-08-07 09:51:11 +04:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
/*
|
|
|
|
* set the pad char, only take the first char of the pc capability
|
|
|
|
* as this is all we can use.
|
|
|
|
*/
|
|
|
|
screen->pad_char = screen->tc_pc ? screen->tc_pc[0] : 0;
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2002-06-26 22:13:59 +04:00
|
|
|
/* Get full name of terminal */
|
2000-04-19 17:52:39 +04:00
|
|
|
if (unknown) {
|
2001-12-02 12:14:20 +03:00
|
|
|
strcpy(screen->ttytype, "dumb");
|
2000-04-19 17:52:39 +04:00
|
|
|
} else {
|
2002-06-26 22:13:59 +04:00
|
|
|
char *tcptr;
|
|
|
|
size_t limit = 0;
|
|
|
|
if (t_getterm(screen->cursesi_genbuf, 0, &limit))
|
2000-04-19 17:52:39 +04:00
|
|
|
return ERR;
|
2002-06-26 22:13:59 +04:00
|
|
|
if ((tcptr = malloc(limit + 1)) == NULL)
|
|
|
|
return ERR;
|
|
|
|
if (t_getterm(screen->cursesi_genbuf, &tcptr, 0) < 0)
|
|
|
|
return ERR;
|
|
|
|
__longname(tcptr, screen->ttytype);
|
|
|
|
free(tcptr);
|
2000-04-19 17:52:39 +04:00
|
|
|
}
|
2002-01-02 13:38:27 +03:00
|
|
|
|
1994-08-18 01:51:41 +04:00
|
|
|
/* If no scrolling commands, no quick change. */
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->noqch =
|
|
|
|
(screen->tc_cs == NULL || screen->tc_ho == NULL ||
|
|
|
|
(screen->tc_SF == NULL && screen->tc_sf == NULL) ||
|
|
|
|
(screen->tc_SR == NULL && screen->tc_sr == NULL)) &&
|
|
|
|
((screen->tc_AL == NULL && screen->tc_al == NULL) ||
|
|
|
|
(screen->tc_DL == NULL && screen->tc_dl == NULL));
|
1993-11-09 06:34:01 +03:00
|
|
|
|
2002-09-11 19:23:24 +04:00
|
|
|
/*
|
|
|
|
* Precalculate conflict info for color/attribute end commands.
|
|
|
|
*/
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->mask_op = __ATTRIBUTES & ~__COLOR;
|
|
|
|
if (screen->tc_op != NULL) {
|
2003-01-28 00:12:29 +03:00
|
|
|
if (does_esc_m(screen->tc_op))
|
|
|
|
screen->mask_op &=
|
|
|
|
~(__STANDOUT | __UNDERSCORE | __TERMATTR);
|
|
|
|
else {
|
|
|
|
if (screen->tc_se != NULL &&
|
|
|
|
!strcmp(screen->tc_op, screen->tc_se))
|
|
|
|
screen->mask_op &= ~__STANDOUT;
|
|
|
|
if (screen->tc_ue != NULL &&
|
|
|
|
!strcmp(screen->tc_op, screen->tc_ue))
|
|
|
|
screen->mask_op &= ~__UNDERSCORE;
|
|
|
|
if (screen->tc_me != NULL &&
|
|
|
|
!strcmp(screen->tc_op, screen->tc_me))
|
|
|
|
screen->mask_op &= ~__TERMATTR;
|
|
|
|
}
|
2000-04-29 04:42:26 +04:00
|
|
|
}
|
2003-02-02 20:54:38 +03:00
|
|
|
/*
|
|
|
|
* Assume that "me" turns off all attributes apart from ACS.
|
|
|
|
* It might turn off ACS, so check for that.
|
|
|
|
*/
|
|
|
|
if (screen->tc_me != NULL && does_ctrl_o(screen->tc_me))
|
|
|
|
screen->mask_me = 0;
|
|
|
|
else
|
|
|
|
screen->mask_me = __ALTCHARSET;
|
|
|
|
|
|
|
|
/* Check what turning off the attributes also turns off */
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->mask_ue = __ATTRIBUTES & ~__UNDERSCORE;
|
|
|
|
if (screen->tc_ue != NULL) {
|
2003-01-28 00:12:29 +03:00
|
|
|
if (does_esc_m(screen->tc_ue))
|
|
|
|
screen->mask_ue &=
|
|
|
|
~(__STANDOUT | __TERMATTR | __COLOR);
|
|
|
|
else {
|
|
|
|
if (screen->tc_se != NULL &&
|
|
|
|
!strcmp(screen->tc_ue, screen->tc_se))
|
|
|
|
screen->mask_ue &= ~__STANDOUT;
|
|
|
|
if (screen->tc_me != NULL &&
|
|
|
|
!strcmp(screen->tc_ue, screen->tc_me))
|
|
|
|
screen->mask_ue &= ~__TERMATTR;
|
|
|
|
if (screen->tc_op != NULL &&
|
|
|
|
!strcmp(screen->tc_ue, screen->tc_op))
|
|
|
|
screen->mask_ue &= ~__COLOR;
|
|
|
|
}
|
2000-04-29 04:42:26 +04:00
|
|
|
}
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->mask_se = __ATTRIBUTES & ~__STANDOUT;
|
|
|
|
if (screen->tc_se != NULL) {
|
2003-01-28 00:12:29 +03:00
|
|
|
if (does_esc_m(screen->tc_se))
|
|
|
|
screen->mask_se &=
|
2003-02-02 20:54:38 +03:00
|
|
|
~(__UNDERSCORE | __TERMATTR | __COLOR);
|
2003-01-28 00:12:29 +03:00
|
|
|
else {
|
|
|
|
if (screen->tc_ue != NULL &&
|
|
|
|
!strcmp(screen->tc_se, screen->tc_ue))
|
|
|
|
screen->mask_se &= ~__UNDERSCORE;
|
|
|
|
if (screen->tc_me != NULL &&
|
|
|
|
!strcmp(screen->tc_se, screen->tc_me))
|
|
|
|
screen->mask_se &= ~__TERMATTR;
|
|
|
|
if (screen->tc_op != NULL &&
|
|
|
|
!strcmp(screen->tc_se, screen->tc_op))
|
|
|
|
screen->mask_se &= ~__COLOR;
|
|
|
|
}
|
2000-04-29 04:42:26 +04:00
|
|
|
}
|
|
|
|
|
1993-08-07 09:51:11 +04:00
|
|
|
return (unknown ? ERR : OK);
|
|
|
|
}
|
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
/*
|
|
|
|
* _cursesi_resetterm --
|
|
|
|
* Copy the terminal instance data for the given screen to the global
|
|
|
|
* variables.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_cursesi_resetterm(SCREEN *screen)
|
|
|
|
{
|
|
|
|
char ***sp, **scr_sp;
|
|
|
|
int **vp, *scr_vp, i;
|
|
|
|
char **fp, *scr_fp;
|
|
|
|
|
|
|
|
LINES = screen->LINES;
|
|
|
|
COLS = screen->COLS;
|
|
|
|
|
|
|
|
/* reset terminal capabilities */
|
|
|
|
fp = sflags;
|
|
|
|
scr_fp = &screen->tc_am;
|
|
|
|
for (i = 0; i < screen->flag_count; i++)
|
|
|
|
*(*fp++) = *scr_fp++;
|
|
|
|
|
|
|
|
vp = svals;
|
|
|
|
scr_vp = &screen->tc_pa;
|
|
|
|
for (i = 0; i < screen->int_count; i++)
|
|
|
|
*(*vp++) = *scr_vp++;
|
|
|
|
|
|
|
|
sp = sstrs;
|
|
|
|
scr_sp = &screen->tc_AB;
|
|
|
|
for (i = 0; i < screen->str_count; i++)
|
|
|
|
*(*sp++) = *scr_sp++;
|
|
|
|
|
|
|
|
__GT = screen->GT;
|
|
|
|
__CA = screen->CA;
|
|
|
|
|
|
|
|
PC = screen->pad_char;
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
__noqch = screen->noqch;
|
|
|
|
__mask_op = screen->mask_op;
|
|
|
|
__mask_me = screen->mask_me;
|
|
|
|
__mask_ue = screen->mask_ue;
|
|
|
|
__mask_se = screen->mask_se;
|
|
|
|
}
|
|
|
|
|
1993-08-07 09:51:11 +04:00
|
|
|
/*
|
|
|
|
* zap --
|
|
|
|
* Gets all the terminal flags from the termcap database.
|
|
|
|
*/
|
2000-04-19 17:52:39 +04:00
|
|
|
static int
|
2001-12-02 12:14:20 +03:00
|
|
|
zap(SCREEN *screen)
|
1993-08-07 09:51:11 +04:00
|
|
|
{
|
2000-04-22 17:29:01 +04:00
|
|
|
const char *nampstr, *namp;
|
2001-12-02 12:14:20 +03:00
|
|
|
char **sp;
|
|
|
|
int *vp;
|
|
|
|
char *fp;
|
1993-11-09 06:34:01 +03:00
|
|
|
char tmp[3];
|
1993-08-07 09:51:11 +04:00
|
|
|
#ifdef DEBUG
|
1998-02-03 22:12:13 +03:00
|
|
|
char *cp;
|
1993-08-07 09:51:11 +04:00
|
|
|
#endif
|
1993-11-09 06:34:01 +03:00
|
|
|
tmp[2] = '\0';
|
1993-08-07 09:51:11 +04:00
|
|
|
|
2000-12-20 00:34:24 +03:00
|
|
|
namp = "ambsccdaeohchlinmimsncnsosulutxbxnxtxsxx";
|
2001-12-02 12:14:20 +03:00
|
|
|
fp = &screen->tc_am;
|
|
|
|
screen->flag_count = 0;
|
1993-08-07 09:51:11 +04:00
|
|
|
do {
|
1993-11-09 06:34:01 +03:00
|
|
|
*tmp = *namp;
|
|
|
|
*(tmp + 1) = *(namp + 1);
|
2001-12-02 12:14:20 +03:00
|
|
|
*fp++ = t_getflag(screen->cursesi_genbuf, tmp);
|
1993-08-07 09:51:11 +04:00
|
|
|
#ifdef DEBUG
|
2001-12-02 12:14:20 +03:00
|
|
|
__CTRACE("%2.2s = %s\n", namp, fp[-1] ? "TRUE" : "FALSE");
|
1993-08-07 09:51:11 +04:00
|
|
|
#endif
|
|
|
|
namp += 2;
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->flag_count++;
|
1993-08-07 09:51:11 +04:00
|
|
|
} while (*namp);
|
2000-04-13 01:45:30 +04:00
|
|
|
namp = "paCoNC";
|
2001-12-02 12:14:20 +03:00
|
|
|
vp = &screen->tc_pa;
|
|
|
|
screen->int_count = 0;
|
2000-04-13 01:45:30 +04:00
|
|
|
do {
|
|
|
|
*tmp = *namp;
|
|
|
|
*(tmp + 1) = *(namp + 1);
|
2001-12-02 12:14:20 +03:00
|
|
|
*vp++ = t_getnum(screen->cursesi_genbuf, tmp);
|
2000-04-13 01:45:30 +04:00
|
|
|
#ifdef DEBUG
|
2002-06-26 22:13:59 +04:00
|
|
|
__CTRACE("%2.2s = %d\n", namp, vp[-1]);
|
2000-04-13 01:45:30 +04:00
|
|
|
#endif
|
|
|
|
namp += 2;
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->int_count++;
|
2000-04-13 01:45:30 +04:00
|
|
|
} while (*namp);
|
2000-04-19 17:52:39 +04:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
nampstr = "ABacaeAFALalasbcblbtcdceclcmcrcsdcDLdldmDOdoeAedeihoIcicimIpipk0k1k2k3k4k5k6k7k8k9kdkekhklkrkskuLEllmambmdmemhmkmmmompmrndnlocoppcrcRISbscseSFSfsfsospSRsrtatetiucueUPupusvbvevivs";
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2000-04-22 17:29:01 +04:00
|
|
|
namp = nampstr;
|
2001-12-02 12:14:20 +03:00
|
|
|
sp = &screen->tc_AB;
|
|
|
|
screen->str_count = 0;
|
1993-08-07 09:51:11 +04:00
|
|
|
do {
|
1993-11-09 06:34:01 +03:00
|
|
|
*tmp = *namp;
|
|
|
|
*(tmp + 1) = *(namp + 1);
|
2001-12-02 12:14:20 +03:00
|
|
|
*sp++ = t_agetstr(screen->cursesi_genbuf, tmp);
|
1993-08-07 09:51:11 +04:00
|
|
|
#ifdef DEBUG
|
2002-06-26 22:13:59 +04:00
|
|
|
__CTRACE("%2.2s = %s", namp, sp[-1] == NULL ? "NULL\n" : "\"");
|
2001-12-02 12:14:20 +03:00
|
|
|
if (sp[-1] != NULL) {
|
|
|
|
for (cp = sp[-1]; *cp; cp++)
|
1999-12-07 06:18:52 +03:00
|
|
|
__CTRACE("%s", unctrl(*cp));
|
1993-11-09 06:34:01 +03:00
|
|
|
__CTRACE("\"\n");
|
1993-08-07 09:51:11 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
namp += 2;
|
2001-12-02 12:14:20 +03:00
|
|
|
screen->str_count++;
|
1993-08-07 09:51:11 +04:00
|
|
|
} while (*namp);
|
2001-12-02 12:14:20 +03:00
|
|
|
if (screen->tc_xs)
|
|
|
|
screen->tc_so = screen->tc_se = NULL;
|
1993-08-07 09:51:11 +04:00
|
|
|
else {
|
2001-12-02 12:14:20 +03:00
|
|
|
if (t_getnum(screen->cursesi_genbuf, "sg") > 0)
|
|
|
|
screen->tc_so = NULL;
|
|
|
|
if (t_getnum(screen->cursesi_genbuf, "ug") > 0)
|
|
|
|
screen->tc_us = NULL;
|
|
|
|
if (!screen->tc_so && screen->tc_us) {
|
|
|
|
screen->tc_so = screen->tc_us;
|
|
|
|
screen->tc_se = screen->tc_ue;
|
1993-08-07 09:51:11 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-19 17:52:39 +04:00
|
|
|
|
|
|
|
return OK;
|
1993-08-07 09:51:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getcap --
|
|
|
|
* Return a capability from termcap.
|
|
|
|
*/
|
1999-04-13 18:08:17 +04:00
|
|
|
char *
|
2000-04-15 17:17:02 +04:00
|
|
|
getcap(char *name)
|
1993-08-07 09:51:11 +04:00
|
|
|
{
|
2001-12-02 12:14:20 +03:00
|
|
|
return (t_agetstr(_cursesi_genbuf, name));
|
1993-08-07 09:51:11 +04:00
|
|
|
}
|
2003-01-28 00:12:29 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* does_esc_m --
|
|
|
|
* A hack for xterm-like terminals where "\E[m" or "\E[0m" will turn off
|
|
|
|
* other attributes, so we check for this in the capability passed to us.
|
|
|
|
* Note that we can't just do simple string comparison, as the capability
|
|
|
|
* may contain multiple, ';' separated sequence parts.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
does_esc_m(char *cap)
|
|
|
|
{
|
2003-02-02 20:54:38 +03:00
|
|
|
#define WAITING 0
|
|
|
|
#define PARSING 1
|
|
|
|
#define NUMBER 2
|
|
|
|
#define FOUND 4
|
|
|
|
char *capptr;
|
|
|
|
int seq;
|
2003-01-28 00:12:29 +03:00
|
|
|
|
2003-02-02 20:54:38 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("does_esc_m: Checking %s\n", cap);
|
|
|
|
#endif
|
2003-01-28 00:12:29 +03:00
|
|
|
/* Is it just "\E[m" or "\E[0m"? */
|
|
|
|
if (!strcmp(cap, "\x1b[m") || !strcmp(cap, "\x1b[0m"))
|
|
|
|
return 1;
|
|
|
|
|
2003-02-02 20:54:38 +03:00
|
|
|
/* Does it contain a "\E[...m" sequence? */
|
|
|
|
if (strlen(cap) < 4)
|
|
|
|
return 0;
|
|
|
|
capptr = cap;
|
|
|
|
seq = WAITING;
|
|
|
|
while (*capptr != NULL) {
|
|
|
|
switch (seq) {
|
|
|
|
/* Start of sequence */
|
|
|
|
case WAITING:
|
|
|
|
if (!strncmp(capptr, "\x1b[", 2)) {
|
|
|
|
capptr+=2;
|
|
|
|
if (*capptr == 'm')
|
|
|
|
return 1;
|
|
|
|
else {
|
|
|
|
seq=PARSING;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* Looking for '0' */
|
|
|
|
case PARSING:
|
|
|
|
if (*capptr == '0')
|
|
|
|
seq=FOUND;
|
|
|
|
else if (*capptr > '0' && *capptr <= '9')
|
|
|
|
seq=NUMBER;
|
|
|
|
else if (*capptr != ';')
|
|
|
|
seq=WAITING;
|
|
|
|
break;
|
|
|
|
/* Some other number */
|
|
|
|
case NUMBER:
|
|
|
|
if (*capptr == ';')
|
|
|
|
seq=PARSING;
|
|
|
|
else if (!(*capptr >= '0' && *capptr <= '9'))
|
|
|
|
seq=WAITING;
|
|
|
|
break;
|
|
|
|
/* Found a '0' */
|
|
|
|
case FOUND:
|
|
|
|
if (*capptr == 'm')
|
2003-01-28 00:12:29 +03:00
|
|
|
return 1;
|
2003-02-02 20:54:38 +03:00
|
|
|
else if (!((*capptr >= '0' && *capptr <= '9') ||
|
|
|
|
*capptr == ';'))
|
|
|
|
seq=WAITING;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2003-01-28 00:12:29 +03:00
|
|
|
}
|
2003-02-02 20:54:38 +03:00
|
|
|
capptr++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* does_ctrl_o --
|
|
|
|
* A hack for vt100/xterm-like terminals where the "me" capability also
|
|
|
|
* unsets acs (i.e. it contains the character '\017').
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
does_ctrl_o(char *cap)
|
|
|
|
{
|
|
|
|
char *capptr = cap;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("does_ctrl_o: Looping on %s\n", capptr);
|
|
|
|
#endif
|
|
|
|
while (*capptr != NULL) {
|
|
|
|
if (*capptr == '\x0f')
|
|
|
|
return 1;
|
|
|
|
capptr++;
|
2003-01-28 00:12:29 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|