Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libterminfo term.h



details:   https://anonhg.NetBSD.org/src/rev/b047b3617f3d
branches:  trunk
changeset: 822505:b047b3617f3d
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Mar 23 00:23:29 2017 +0000

description:
term.h

diffstat:

 lib/libterminfo/setupterm.c |  40 ++++++++++++++++++++++++++++++++++++++--
 lib/libterminfo/term.h      |   6 +++---
 2 files changed, 41 insertions(+), 5 deletions(-)

diffs (98 lines):

diff -r 3299ea381632 -r b047b3617f3d lib/libterminfo/setupterm.c
--- a/lib/libterminfo/setupterm.c       Thu Mar 23 00:17:57 2017 +0000
+++ b/lib/libterminfo/setupterm.c       Thu Mar 23 00:23:29 2017 +0000
@@ -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 @@
 #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 @@
 ti_setupterm(TERMINAL **nterm, const char *term, int fildes, int *errret)
 {
        int error;
+       struct winsize win;
 
        _DIAGASSERT(nterm != NULL);
 
@@ -105,6 +122,25 @@
                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;
diff -r 3299ea381632 -r b047b3617f3d lib/libterminfo/term.h
--- a/lib/libterminfo/term.h    Thu Mar 23 00:17:57 2017 +0000
+++ b/lib/libterminfo/term.h    Thu Mar 23 00:23:29 2017 +0000
@@ -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 @@
        /* 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



Home | Main Index | Thread Index | Old Index