diff options
author | 1997-11-26 04:01:02 +0000 | |
---|---|---|
committer | 1997-11-26 04:01:02 +0000 | |
commit | 010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b (patch) | |
tree | 5ee5e7213ad9b412a927de7effdcb7c8ce4b489e /lib/libcurses/lib_initscr.c | |
parent | libform from ncurses 4.1. Post 4.1 patches to be applied in a separate commit. (diff) | |
download | wireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.tar.xz wireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.zip |
ncurses 4.1 + changes to work with our terminfo libs (instead of
the ncurses ones). Changes are #ifdef EXTERN_TERMINFO.
Post 4.1 patches will be applied in a separate commit.
Diffstat (limited to 'lib/libcurses/lib_initscr.c')
-rw-r--r-- | lib/libcurses/lib_initscr.c | 86 |
1 files changed, 59 insertions, 27 deletions
diff --git a/lib/libcurses/lib_initscr.c b/lib/libcurses/lib_initscr.c index b9c6fcaaad9..8b2b90562cd 100644 --- a/lib/libcurses/lib_initscr.c +++ b/lib/libcurses/lib_initscr.c @@ -26,37 +26,69 @@ ** */ -#include "curses.priv.h" -#include <stdlib.h> -#include <string.h> +#include <curses.priv.h> +#include <term.h> /* cur_term */ -WINDOW *initscr(void) +#if HAVE_SYS_TERMIO_H +#include <sys/termio.h> /* needed for ISC */ +#endif + +MODULE_ID("Id: lib_initscr.c,v 1.18 1997/03/08 14:03:59 tom Exp $") + +#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ +#define ONLCR 0 +#endif + +/* + * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not + * restored during the curses session. The library simulates echo in software. + * (The behavior is unspecified if the application enables hardware echo). + * + * The newterm function also initializes terminal settings. + */ +int _nc_initscr(void) { -char *name = getenv("TERM"); + /* for extended XPG4 conformance requires cbreak() at this point */ + /* (SVr4 curses does this anyway) */ + cbreak(); - if (name == 0) - name = "unknown"; - if (newterm(name, stdout, stdin) == NULL) { - fprintf(stderr, "Error opening terminal: %s.\n", name); - exit(1); - } +#ifdef TERMIOS + cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL); + cur_term->Nttyb.c_iflag &= ~(ICRNL|INLCR|IGNCR); + cur_term->Nttyb.c_oflag &= ~(ONLCR); +#else + cur_term->Nttyb.sg_flags &= ~(ECHO|CRMOD); +#endif + if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) + return ERR; + return OK; +} - /* allow user to set maximum escape delay from the environment */ - if ((name = getenv("ESCDELAY"))) - ESCDELAY = atoi(getenv("ESCDELAY")); +WINDOW *initscr(void) +{ +static bool initialized = FALSE; +const char *name; - def_shell_mode(); + T((T_CALLED("initscr()"))); + /* Portable applications must not call initscr() more than once */ + if (!initialized) { + initialized = TRUE; - /* follow the XPG4 requirement to turn echo off at this point */ - noecho(); + if ((name = getenv("TERM")) == 0) + name = "unknown"; + if (newterm(name, stdout, stdin) == 0) { + fprintf(stderr, "Error opening terminal: %s.\n", name); + exit(EXIT_FAILURE); + } -#ifdef _XOPEN_SOURCE_EXTENDED - /* for extended XPG4 conformance requires cbreak() at this point */ - cbreak(); -#endif /* _XOPEN_SOURCE_EXTENDED */ + /* allow user to set maximum escape delay from the environment */ + if ((name = getenv("ESCDELAY")) != 0) + ESCDELAY = atoi(getenv("ESCDELAY")); - def_prog_mode(); - return(stdscr); + /* def_shell_mode - done in newterm/_nc_setupscreen */ + def_prog_mode(); + } + returnWin(stdscr); } char *termname(void) @@ -66,10 +98,10 @@ static char ret[15]; T(("termname() called")); - if (term == (char *)NULL) - return(char *)NULL; - else { + if (term != 0) { (void) strncpy(ret, term, sizeof(ret) - 1); - return(ret); + ret[sizeof(ret) - 1] = '\0'; + term = ret; } + return term; } |