version 1.4, 2013/06/07 13:16:18 |
version 1.5, 2017/03/23 00:23:29 |
|
|
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
__RCSID("$NetBSD$"); |
__RCSID("$NetBSD$"); |
|
|
|
#include <sys/ioctl.h> |
#include <assert.h> |
#include <assert.h> |
#include <err.h> |
#include <err.h> |
|
#include <stdbool.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <strings.h> |
#include <strings.h> |
Line 39 __RCSID("$NetBSD$"); |
|
Line 41 __RCSID("$NetBSD$"); |
|
#include <term_private.h> |
#include <term_private.h> |
#include <term.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) \ |
#define reterr(code, msg) \ |
do { \ |
do { \ |
if (errret == NULL) \ |
if (errret == NULL) \ |
|
|
ti_setupterm(TERMINAL **nterm, const char *term, int fildes, int *errret) |
ti_setupterm(TERMINAL **nterm, const char *term, int fildes, int *errret) |
{ |
{ |
int error; |
int error; |
|
struct winsize win; |
|
|
_DIAGASSERT(nterm != NULL); |
_DIAGASSERT(nterm != NULL); |
|
|
Line 105 ti_setupterm(TERMINAL **nterm, const cha |
|
Line 122 ti_setupterm(TERMINAL **nterm, const cha |
|
reterrarg(0, "%s: generic terminal", term); |
reterrarg(0, "%s: generic terminal", term); |
if (t_hard_copy(*nterm)) |
if (t_hard_copy(*nterm)) |
reterrarg(1, "%s: hardcopy terminal", term); |
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 */ |
/* POSIX requires 1 for success */ |
if (errret) |
if (errret) |
*errret = 1; |
*errret = 1; |