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