+ }
+
+ if (status == -1) {
+ ret_error0(-1, "terminals database is inaccessible\n");
+ } else if (status == 0) {
+ 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"))
+ do_prototype();
+
+ strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1);
+ ttytype[NAMESIZE - 1] = '\0';
+
+ /*
+ * Allow output redirection. This is what SVr3 does.
+ * If stdout is directed to a file, screen updates go
+ * to standard error.
+ */
+ if (Filedes == STDOUT_FILENO && !isatty(Filedes))
+ Filedes = STDERR_FILENO;
+ cur_term->Filedes = Filedes;
+
+ _nc_get_screensize(&LINES, &COLS);
+
+ if (errret)
+ *errret = 1;
+
+ T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
+
+ if (generic_type) {
+ ret_error(0, "'%s': I need something more specific.\n", tname);
+ }
+ if (hard_copy) {
+ ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
+ }
+ returnCode(OK);