POSIX says that use_env(3) must precede setupterm(3).
The former lives in curses.h, but the latter lives in term.h. This is solved by moving the function to libterminfo. Because the environment can affect the terminal capabilities for lines and columns, it follows that the tty size should affect it to. So move that code to libterminfo and adjust in libcurses.
This commit is contained in:
parent
d5c74a0225
commit
5128a2ed79
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: setterm.c,v 1.65 2017/03/20 20:44:06 christos Exp $ */
|
||||
/* $NetBSD: setterm.c,v 1.66 2017/03/23 00:55:39 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
@ -34,12 +34,10 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)setterm.c 8.8 (Berkeley) 10/25/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: setterm.c,v 1.65 2017/03/20 20:44:06 christos Exp $");
|
||||
__RCSID("$NetBSD: setterm.c,v 1.66 2017/03/23 00:55:39 roy Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/ioctl.h> /* TIOCGWINSZ on old systems. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
@ -50,17 +48,9 @@ __RCSID("$NetBSD: setterm.c,v 1.65 2017/03/20 20:44:06 christos Exp $");
|
||||
|
||||
static int does_esc_m(const char *cap);
|
||||
static int does_ctrl_o(const char *exit_cap, const char *acs_cap);
|
||||
static bool __use_env = true;
|
||||
|
||||
attr_t __mask_op, __mask_me, __mask_ue, __mask_se;
|
||||
|
||||
void
|
||||
use_env(bool value)
|
||||
{
|
||||
|
||||
__use_env = value;
|
||||
}
|
||||
|
||||
int
|
||||
setterm(char *type)
|
||||
{
|
||||
@ -72,7 +62,6 @@ int
|
||||
_cursesi_setterm(char *type, SCREEN *screen)
|
||||
{
|
||||
int unknown, r;
|
||||
struct winsize win;
|
||||
char *p;
|
||||
|
||||
if (type[0] == '\0')
|
||||
@ -93,20 +82,9 @@ _cursesi_setterm(char *type, SCREEN *screen)
|
||||
__CTRACE(__CTRACE_INIT, "setterm: tty = %s\n", type);
|
||||
#endif
|
||||
|
||||
/* Try TIOCGWINSZ, and, if it fails, the terminfo entry. */
|
||||
if (ioctl(fileno(screen->outfd), TIOCGWINSZ, &win) != -1 &&
|
||||
win.ws_row != 0 && win.ws_col != 0) {
|
||||
screen->LINES = win.ws_row;
|
||||
screen->COLS = win.ws_col;
|
||||
} else {
|
||||
if (unknown) {
|
||||
screen->LINES = -1;
|
||||
screen->COLS = -1;
|
||||
} else {
|
||||
screen->LINES = t_lines(screen->term);
|
||||
screen->COLS = t_columns(screen->term);
|
||||
}
|
||||
}
|
||||
/* lines and cols will have been setup correctly by ti_setupterm(3). */
|
||||
screen->LINES = t_lines(screen->term);
|
||||
screen->COLS = t_columns(screen->term);
|
||||
|
||||
if (screen->filtered) {
|
||||
/* Disable use of clear, cud, cud1, cup, cuu1 and vpa. */
|
||||
@ -122,18 +100,12 @@ _cursesi_setterm(char *type, SCREEN *screen)
|
||||
screen->term->strs[TICODE_home] = screen->term->strs[TICODE_cr];
|
||||
/* Set lines equal to 1. */
|
||||
screen->LINES = 1;
|
||||
t_lines(screen->term) = 1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INIT, "setterm: filtered %d", screen->filtered);
|
||||
#endif
|
||||
|
||||
/* POSIX 1003.2 requires that the environment override. */
|
||||
if (__use_env) {
|
||||
if (!screen->filtered && (p = getenv("LINES")) != NULL)
|
||||
screen->LINES = (int)strtol(p, NULL, 0);
|
||||
if ((p = getenv("COLUMNS")) != NULL)
|
||||
screen->COLS = (int)strtol(p, NULL, 0);
|
||||
}
|
||||
if ((p = getenv("ESCDELAY")) != NULL)
|
||||
screen->ESCDELAY = (int)strtol(p, NULL, 0);
|
||||
else
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: setupterm.c,v 1.6 2017/03/23 00:36:37 roy Exp $ */
|
||||
/* $NetBSD: setupterm.c,v 1.7 2017/03/23 00:55:39 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
|
||||
@ -28,10 +28,12 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: setupterm.c,v 1.6 2017/03/23 00:36:37 roy Exp $");
|
||||
__RCSID("$NetBSD: setupterm.c,v 1.7 2017/03/23 00:55:39 roy Exp $");
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
@ -39,6 +41,20 @@ __RCSID("$NetBSD: setupterm.c,v 1.6 2017/03/23 00:36:37 roy Exp $");
|
||||
#include <term_private.h>
|
||||
#include <term.h>
|
||||
|
||||
/*
|
||||
* use_env is really a curses function - POSIX mandates it's in curses.h
|
||||
* But it has to live in terminfo because it must precede a call to setupterm().
|
||||
*/
|
||||
#include <curses.h>
|
||||
|
||||
static bool __use_env = true;
|
||||
|
||||
void
|
||||
use_env(bool value)
|
||||
{
|
||||
|
||||
__use_env = value;
|
||||
}
|
||||
#define reterr(code, msg) \
|
||||
do { \
|
||||
if (errret == NULL) \
|
||||
@ -64,6 +80,7 @@ int
|
||||
ti_setupterm(TERMINAL **nterm, const char *term, int fildes, int *errret)
|
||||
{
|
||||
int error;
|
||||
struct winsize win;
|
||||
|
||||
_DIAGASSERT(nterm != NULL);
|
||||
|
||||
@ -105,6 +122,25 @@ ti_setupterm(TERMINAL **nterm, const char *term, int fildes, int *errret)
|
||||
reterrarg(0, "%s: generic terminal", term);
|
||||
if (t_hard_copy(*nterm))
|
||||
reterrarg(1, "%s: hardcopy terminal", term);
|
||||
|
||||
/* If TIOCGWINSZ works, then set initial lines and columns. */
|
||||
if (ioctl(fildes, TIOCGWINSZ, &win) != -1 &&
|
||||
win.ws_row != 0 && win.ws_col != 0)
|
||||
{
|
||||
t_lines(*nterm) = win.ws_row;
|
||||
t_columns(*nterm) = win.ws_col;
|
||||
}
|
||||
|
||||
/* POSIX 1003.2 requires that the environment override. */
|
||||
if (__use_env) {
|
||||
char *p;
|
||||
|
||||
if ((p = getenv("LINES")) != NULL)
|
||||
t_lines(*nterm) = (int)strtol(p, NULL, 0);
|
||||
if ((p = getenv("COLUMNS")) != NULL)
|
||||
t_columns(*nterm) = (int)strtol(p, NULL, 0);
|
||||
}
|
||||
|
||||
/* POSIX requires 1 for success */
|
||||
if (errret)
|
||||
*errret = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user