rewrite tstp as __stop_signal_handler: new implementation
[unix-history] / usr / src / lib / libcurses / initscr.c
index f360d41..7bf73ff 100644 (file)
@@ -1,66 +1,70 @@
-# include      "curses.ext"
-# include      <signal.h>
+/*
+ * Copyright (c) 1981 Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)initscr.c  5.12 (Berkeley) %G%";
+#endif /* not lint */
 
 
-extern char    *getenv();
+#include <curses.h>
+#include <signal.h>
+#include <stdlib.h>
 
 /*
 
 /*
- *     This routine initializes the current and standard screen.
- *
- * @(#)initscr.c       1.5 (Berkeley) %G%
+ * initscr --
+ *     Initialize the current and standard screen.
  */
 WINDOW *
  */
 WINDOW *
-initscr() {
+initscr()
+{
+       register char *sp;
 
 
-       reg char        *sp;
-       int             tstp();
-       int             nfd;
+#ifdef DEBUG
+       __TRACE("initscr\n");
+#endif
+       __echoit = 1;
+        __pfast = __rawmode = __noqch = 0;
 
 
-# ifdef DEBUG
-       fprintf(outf, "INITSCR()\n");
-# endif
-       if (My_term)
-               setterm(Def_term);
-       else {
-               if (isatty(2))
-                       _tty_ch = 2;
-               else {
-                       nfd = getdtablesize();
-                       for (_tty_ch = 0; _tty_ch < nfd; _tty_ch++)
-                               if (isatty(_tty_ch))
-                                       break;
-               }
-               gettmode();
-               if ((sp = getenv("TERM")) == NULL)
-                       sp = Def_term;
-               setterm(sp);
-# ifdef DEBUG
-               fprintf(outf, "INITSCR: term = %s\n", sp);
-# endif
-       }
-       _puts(TI);
-       _puts(VS);
-# ifdef SIGTSTP
-       signal(SIGTSTP, tstp);
-# endif
-       if (curscr != NULL) {
-# ifdef DEBUG
-               fprintf(outf, "INITSCR: curscr = 0%o\n", curscr);
-# endif
+       if (gettmode() == ERR)
+               return (NULL);
+
+       /*
+        * If My_term is set, or can't find a terminal in the environment,
+        * use Def_term.
+        */
+       if (My_term || (sp = getenv("TERM")) == NULL)
+               sp = Def_term;
+       if (setterm(sp) == ERR)
+               return (NULL);
+
+       /* Need either homing or cursor motion for refreshes */
+       if (!HO && !CM) 
+               return (NULL);
+
+       tputs(TI, 0, __cputchar);
+       tputs(VS, 0, __cputchar);
+
+       if (curscr != NULL)
                delwin(curscr);
                delwin(curscr);
-       }
-# ifdef DEBUG
-       fprintf(outf, "LINES = %d, COLS = %d\n", LINES, COLS);
-# endif
        if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
        if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
-               return ERR;
-       clearok(curscr, TRUE);
-       curscr->_flags &= ~_FULLLINE;
-       if (stdscr != NULL) {
-# ifdef DEBUG
-               fprintf(outf, "INITSCR: stdscr = 0%o\n", stdscr);
-# endif
+               return (NULL);
+       clearok(curscr, 1);
+
+       if (stdscr != NULL)
                delwin(stdscr);
                delwin(stdscr);
+       if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) {
+               delwin(curscr);
+               return (NULL);
        }
        }
-       stdscr = newwin(LINES, COLS, 0, 0);
-       return stdscr;
+
+       (void)signal(SIGTSTP, tstp);
+
+#ifdef DEBUG
+       __TRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
+#endif
+       return (stdscr);
 }
 }
+