date and time created 83/05/31 00:19:54 by sam
[unix-history] / usr / src / lib / libcurses / initscr.c
index 1852971..73fb810 100644 (file)
@@ -1,22 +1,33 @@
 # include      "curses.ext"
 # include      "curses.ext"
+# include      <signal.h>
+# include      <sys/param.h>
 
 extern char    *getenv();
 
 /*
  *     This routine initializes the current and standard screen.
  *
 
 extern char    *getenv();
 
 /*
  *     This routine initializes the current and standard screen.
  *
- * %G% (Berkeley) @(#)initscr.c        1.1
+ * %G% (Berkeley) @(#)initscr.c        1.3
  */
 WINDOW *
 initscr() {
 
        reg char        *sp;
  */
 WINDOW *
 initscr() {
 
        reg char        *sp;
+       int             tstp();
 
 # ifdef DEBUG
        fprintf(outf, "INITSCR()\n");
 # endif
 
 # ifdef DEBUG
        fprintf(outf, "INITSCR()\n");
 # endif
-       if (!My_term && isatty(2)) {
-               _tty_ch = 2;
+       if (My_term)
+               setterm(Def_term);
+       else {
+               if (isatty(2))
+                       _tty_ch = 2;
+               else {
+                       for (_tty_ch = 0; _tty_ch < NOFILE; _tty_ch++)
+                               if (isatty(_tty_ch))
+                                       break;
+               }
                gettmode();
                if ((sp = getenv("TERM")) == NULL)
                        sp = Def_term;
                gettmode();
                if ((sp = getenv("TERM")) == NULL)
                        sp = Def_term;
@@ -25,10 +36,11 @@ initscr() {
                fprintf(outf, "INITSCR: term = %s\n", sp);
 # endif
        }
                fprintf(outf, "INITSCR: term = %s\n", sp);
 # endif
        }
-       else
-               setterm(Def_term);
        _puts(TI);
        _puts(VS);
        _puts(TI);
        _puts(VS);
+# ifdef SIGTSTP
+       signal(SIGTSTP, tstp);
+# endif
        if (curscr != NULL) {
 # ifdef DEBUG
                fprintf(outf, "INITSCR: curscr = 0%o\n", curscr);
        if (curscr != NULL) {
 # ifdef DEBUG
                fprintf(outf, "INITSCR: curscr = 0%o\n", curscr);
@@ -38,7 +50,7 @@ initscr() {
 # ifdef DEBUG
        fprintf(outf, "LINES = %d, COLS = %d\n", LINES, COLS);
 # endif
 # 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;
        curscr->_clear = TRUE;
        if (stdscr != NULL) {
                return ERR;
        curscr->_clear = TRUE;
        if (stdscr != NULL) {