Module Name: src
Committed By: roy
Date: Thu Mar 23 00:23:29 UTC 2017
Modified Files:
src/lib/libterminfo: setupterm.c term.h
Log Message:
term.h
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libterminfo/setupterm.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libterminfo/term.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libterminfo/setupterm.c
diff -u src/lib/libterminfo/setupterm.c:1.4 src/lib/libterminfo/setupterm.c:1.5
--- src/lib/libterminfo/setupterm.c:1.4 Fri Jun 7 13:16:18 2013
+++ src/lib/libterminfo/setupterm.c Thu Mar 23 00:23:29 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: setupterm.c,v 1.4 2013/06/07 13:16:18 roy Exp $ */
+/* $NetBSD: setupterm.c,v 1.5 2017/03/23 00:23:29 roy Exp $ */
/*
* Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
@@ -28,10 +28,12 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: setupterm.c,v 1.4 2013/06/07 13:16:18 roy Exp $");
+__RCSID("$NetBSD: setupterm.c,v 1.5 2017/03/23 00:23:29 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.4 2013
#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 cha
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;
Index: src/lib/libterminfo/term.h
diff -u src/lib/libterminfo/term.h:1.19 src/lib/libterminfo/term.h:1.20
--- src/lib/libterminfo/term.h:1.19 Thu Mar 23 00:17:57 2017
+++ src/lib/libterminfo/term.h Thu Mar 23 00:23:29 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: term.h,v 1.19 2017/03/23 00:17:57 roy Exp $ */
+/* $NetBSD: term.h,v 1.20 2017/03/23 00:23:29 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2013 The NetBSD Foundation, Inc.
@@ -1933,8 +1933,8 @@ typedef struct {
/* We need to expose these so that the macros work */
const char *name;
const char *desc;
- const signed char *flags;
- const short *nums;
+ signed char *flags;
+ short *nums;
const char **strs;
} TERMINAL;
#endif