/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
#include <locale.h>
#endif
-MODULE_ID("$Id: lib_setup.c,v 1.210 2020/09/06 21:03:33 tom Exp $")
+MODULE_ID("$Id: lib_setup.c,v 1.221 2023/07/22 20:13:04 tom Exp $")
/****************************************************************************
*
#endif
#if NEED_PTEM_H
- /* On SCO, they neglected to define struct winsize in termios.h -- it's only
+ /* On SCO, they neglected to define struct winsize in termios.h -- it is only
* in termio.h and ptem.h (the former conflicts with other definitions).
*/
# include <sys/stream.h>
if (tname == 0) {
tname = getenv("TERM");
-#if defined(USE_TERM_DRIVER) && !defined(EXP_WIN32_DRIVER)
+#if defined(EXP_WIN32_DRIVER)
+ if (!VALID_TERM_ENV(tname, NO_TERMINAL)) {
+ T(("Failure with TERM=%s", NonNull(tname)));
+ ret_error0(TGETENT_ERR, "TERM environment variable not set.\n");
+ }
+#elif defined(USE_TERM_DRIVER)
if (!NonEmpty(tname))
tname = "unknown";
#else
- if (!CHECK_TERM_ENV(tname, NO_TERMINAL)) {
- T(("Failure with TERM=%s", tname));
+ if (!NonEmpty(tname)) {
+ T(("Failure with TERM=%s", NonNull(tname)));
ret_error0(TGETENT_ERR, "TERM environment variable not set.\n");
}
#endif
}
myname = strdup(tname);
-
- if (strlen(myname) > MAX_NAME_SIZE) {
+ if (myname == NULL || strlen(myname) > MAX_NAME_SIZE) {
ret_error(TGETENT_ERR,
- "TERM environment must be <= %d characters.\n",
+ "TERM environment must be 1..%d characters.\n",
MAX_NAME_SIZE,
free(myname));
}
*/
if (Filedes == STDOUT_FILENO && !NC_ISATTY(Filedes))
Filedes = STDERR_FILENO;
+#if defined(EXP_WIN32_DRIVER)
+ if (Filedes != STDERR_FILENO && NC_ISATTY(Filedes))
+ _setmode(Filedes, _O_BINARY);
+#endif
/*
* Check if we have already initialized to use this terminal. If so, we
"Not enough memory to create terminal structure.\n",
myname, free(myname));
}
+ ++_nc_globals.terminal_count;
#if HAVE_SYSCONF
{
long limit;
#ifdef USE_TERM_DRIVER
INIT_TERM_DRIVER();
+ /*
+ * _nc_get_driver() will call td_CanHandle() for each driver, and win_driver
+ * needs file descriptor to do the test, so set it before calling.
+ */
+ termp->Filedes = (short) Filedes;
TCB = (TERMINAL_CONTROL_BLOCK *) termp;
code = _nc_globals.term_driver(TCB, myname, errret);
if (code == OK) {
- termp->Filedes = (short) Filedes;
termp->_termname = strdup(myname);
} else {
ret_error1(errret ? *errret : TGETENT_ERR,
ret_error1(status, "unknown terminal type.\n",
myname, free(myname));
} else {
+ free(myname);
ret_error0(status, "unexpected return-code\n");
}
}
if (NC_ISATTY(Filedes)) {
NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_ARG);
NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_ARG);
- baudrate();
+ NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG);
}
code = OK;
#endif
{
PRESCREEN_LIST *p, *q;
pthread_t id = GetThreadID();
+ _nc_lock_global(screen);
for (p = _nc_prescreen.allocated, q = 0; p != 0; q = p, p = p->next) {
if (p->id == id) {
if (q) {
break;
}
}
+ _nc_unlock_global(screen);
}
#endif /* USE_PTHREADS */
int rc = ERR;
TERMINAL *termp = 0;
+ _nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
if (TINFO_SETUP_TERM(&termp, tname, Filedes, errret, reuse) == OK) {
}
}
_nc_unlock_global(prescreen);
+
return rc;
}
#endif