*/
#include <curses.priv.h>
+#include <tic.h> /* for MAX_NAME_SIZE */
+#include <term_entry.h>
#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#include <term.h> /* lines, columns, cur_term */
-MODULE_ID("$Id: lib_setup.c,v 1.37 1998/02/11 12:13:56 tom Exp $")
+MODULE_ID("$Id: lib_setup.c,v 1.55 1999/08/21 23:06:08 tom Exp $")
/****************************************************************************
*
****************************************************************************/
#if HAVE_SIZECHANGE
-# if !defined(sun) || !HAVE_TERMIOS_H
+# if !defined(sun) || !TERMIOS
# if HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
# endif
# endif
#endif
-extern TERMINAL *cur_term;
-
static int _use_env = TRUE;
static void do_prototype(void);
static void _nc_get_screensize(int *linep, int *colp)
/* Obtain lines/columns values from the environment and/or terminfo entry */
{
-char *rows, *cols;
-
/* figure out the size of the screen */
T(("screen size: terminfo lines = %d columns = %d", lines, columns));
}
else /* usually want to query LINES and COLUMNS from environment */
{
+ int value;
+
*linep = *colp = 0;
/* first, look for environment variables */
- rows = getenv("LINES");
- if (rows != 0)
- *linep = atoi(rows);
- cols = getenv("COLUMNS");
- if (cols != 0)
- *colp = atoi(cols);
+ if ((value = _nc_getenv_num("LINES")) > 0) {
+ *linep = value;
+ }
+ if ((value = _nc_getenv_num("COLUMNS")) > 0) {
+ *colp = value;
+ }
T(("screen size: environment LINES = %d COLUMNS = %d",*linep,*colp));
+#ifdef __EMX__
+ if (*linep <= 0 || *colp <= 0)
+ {
+ int screendata[2];
+ _scrsize(screendata);
+ *colp = screendata[0];
+ *linep = screendata[1];
+ T(("EMX screen size: environment LINES = %d COLUMNS = %d",*linep,*colp));
+ }
+#endif
#if HAVE_SIZECHANGE
/* if that didn't work, maybe we can try asking the OS */
if (*linep <= 0 || *colp <= 0)
} while
(errno == EINTR);
- *linep = WINSIZE_ROWS(size);
- *colp = WINSIZE_COLS(size);
+ /*
+ * Solaris lets users override either dimension with an
+ * environment variable.
+ */
+ if (*linep <= 0)
+ *linep = WINSIZE_ROWS(size);
+ if (*colp <= 0)
+ *colp = WINSIZE_COLS(size);
}
/* FALLTHRU */
failure:;
T(("screen size is %dx%d", *linep, *colp));
-#ifdef init_tabs
if (init_tabs != -1)
TABSIZE = (int)init_tabs;
else
-#endif /* init_tabs */
TABSIZE = 8;
T(("TABSIZE = %d", TABSIZE));
char filename[PATH_MAX];
int status;
- if ((status = _nc_read_entry(tn, filename, tp)) == 1)
- return(1);
-
-#ifndef PURE_TERMINFO
/*
- * Try falling back on the termcap file. Note: allowing this call
- * links the entire terminfo/termcap compiler into the startup code.
- * It's preferable to build a real terminfo database and use that.
+ * $TERM shouldn't contain pathname delimiters.
*/
- status = _nc_read_termcap_entry(tn, tp);
+ if (strchr(tn, '/'))
+ return 0;
+
+ if ((status = _nc_read_entry(tn, filename, tp)) != 1) {
+
+#ifndef PURE_TERMINFO
+ /*
+ * Try falling back on the termcap file.
+ * Note: allowing this call links the entire terminfo/termcap
+ * compiler into the startup code. It's preferable to build a
+ * real terminfo database and use that.
+ */
+ status = _nc_read_termcap_entry(tn, tp);
#endif /* PURE_TERMINFO */
+ }
+
+ /*
+ * If we have an entry, force all of the cancelled strings to null
+ * pointers so we don't have to test them in the rest of the library.
+ * (The terminfo compiler bypasses this logic, since it must know if
+ * a string is cancelled, for merging entries).
+ */
+ if (status == 1) {
+ int n;
+ for_each_boolean(n,tp)
+ if (!VALID_BOOLEAN(tp->Booleans[n]))
+ tp->Booleans[n] = FALSE;
+ for_each_string(n,tp)
+ if (tp->Strings[n] == CANCELLED_STRING)
+ tp->Strings[n] = ABSENT_STRING;
+ }
return(status);
}
#endif
*
*/
-int setupterm(const char *tname, int Filedes, int *errret)
+int setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
{
struct term *term_ptr;
int status;
- T((T_CALLED("setupterm(\"%s\",%d,%p)"), tname, Filedes, errret));
+ T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
if (tname == 0) {
tname = getenv("TERM");
- if (tname == 0 || *tname == '\0')
+ if (tname == 0 || *tname == '\0') {
ret_error0(-1, "TERM environment variable not set.\n");
+ }
+ }
+ if (strlen(tname) > MAX_NAME_SIZE) {
+ ret_error(-1, "TERM environment must be <= %d characters.\n",
+ MAX_NAME_SIZE);
}
T(("your terminal name is %s", tname));
term_ptr = typeCalloc(TERMINAL, 1);
- if (term_ptr == 0)
+ if (term_ptr == 0) {
ret_error0(-1, "Not enough memory to create terminal structure.\n") ;
+ }
#if USE_DATABASE
status = grab_entry(tname, &term_ptr->type);
#else
if (fallback)
{
- memcpy(&term_ptr->type, fallback, sizeof(TERMTYPE));
+ term_ptr->type = *fallback;
status = 1;
}
}
ret_error(0, "'%s': unknown terminal type.\n", tname);
}
+ /*
+ * Improve on SVr4 curses. If an application mixes curses and termcap
+ * calls, it may call both initscr and tgetent. This is not really a
+ * good thing to do, but can happen if someone tries using ncurses with
+ * the readline library. The problem we are fixing is that when
+ * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
+ * zeroed. A subsequent call to endwin uses the zeroed terminal
+ * settings rather than the ones saved in initscr. So we check if
+ * cur_term appears to contain terminal settings for the same output
+ * file as our current call - and copy those terminal settings. (SVr4
+ * curses does not do this, however applications that are working
+ * around the problem will still work properly with this feature).
+ */
+ if (cur_term != 0) {
+ if (cur_term->Filedes == Filedes)
+ term_ptr->Ottyb = cur_term->Ottyb;
+ }
+
set_curterm(term_ptr);
if (command_character && getenv("CC"))
T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
- if (generic_type)
+ if (generic_type) {
ret_error(0, "'%s': I need something more specific.\n", tname);
- if (hard_copy)
+ }
+ if (hard_copy) {
ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
-
+ }
returnCode(OK);
}
static void
do_prototype(void)
{
-int i, j;
+int i;
char CC;
char proto;
char *tmp;
CC = *tmp;
proto = *command_character;
- for (i=0; i < STRCOUNT; i++) {
- j = 0;
- while (cur_term->type.Strings[i][j]) {
- if (cur_term->type.Strings[i][j] == proto)
- cur_term->type.Strings[i][j] = CC;
- j++;
- }
+ for_each_string(i, &(cur_term->type)) {
+ for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) {
+ if (*tmp == proto)
+ *tmp = CC;
+ }
}
}