manual page distributed with 4.1BSD
[unix-history] / usr / src / lib / libcurses / initscr.c
CommitLineData
fa02ff96 1# include "curses.ext"
4bffae9a 2# include <signal.h>
fa02ff96
KA
3
4extern char *getenv();
5
6/*
7 * This routine initializes the current and standard screen.
8 *
2557a18e 9 * @(#)initscr.c 1.5 (Berkeley) %G%
fa02ff96
KA
10 */
11WINDOW *
12initscr() {
13
14 reg char *sp;
4bffae9a 15 int tstp();
2557a18e 16 int nfd;
fa02ff96
KA
17
18# ifdef DEBUG
19 fprintf(outf, "INITSCR()\n");
20# endif
cac32540
KA
21 if (My_term)
22 setterm(Def_term);
23 else {
24 if (isatty(2))
25 _tty_ch = 2;
26 else {
2557a18e
JB
27 nfd = getdtablesize();
28 for (_tty_ch = 0; _tty_ch < nfd; _tty_ch++)
cac32540
KA
29 if (isatty(_tty_ch))
30 break;
31 }
fa02ff96
KA
32 gettmode();
33 if ((sp = getenv("TERM")) == NULL)
34 sp = Def_term;
35 setterm(sp);
36# ifdef DEBUG
37 fprintf(outf, "INITSCR: term = %s\n", sp);
38# endif
39 }
fa02ff96
KA
40 _puts(TI);
41 _puts(VS);
4bffae9a
KA
42# ifdef SIGTSTP
43 signal(SIGTSTP, tstp);
44# endif
fa02ff96
KA
45 if (curscr != NULL) {
46# ifdef DEBUG
47 fprintf(outf, "INITSCR: curscr = 0%o\n", curscr);
48# endif
49 delwin(curscr);
50 }
51# ifdef DEBUG
52 fprintf(outf, "LINES = %d, COLS = %d\n", LINES, COLS);
53# endif
4bffae9a 54 if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
fa02ff96 55 return ERR;
62fc2477
JB
56 clearok(curscr, TRUE);
57 curscr->_flags &= ~_FULLLINE;
fa02ff96
KA
58 if (stdscr != NULL) {
59# ifdef DEBUG
60 fprintf(outf, "INITSCR: stdscr = 0%o\n", stdscr);
61# endif
62 delwin(stdscr);
63 }
64 stdscr = newwin(LINES, COLS, 0, 0);
65 return stdscr;
66}