manual page distributed with 4.1BSD
[unix-history] / usr / src / lib / libcurses / initscr.c
... / ...
CommitLineData
1# include "curses.ext"
2# include <signal.h>
3
4extern char *getenv();
5
6/*
7 * This routine initializes the current and standard screen.
8 *
9 * @(#)initscr.c 1.5 (Berkeley) %G%
10 */
11WINDOW *
12initscr() {
13
14 reg char *sp;
15 int tstp();
16 int nfd;
17
18# ifdef DEBUG
19 fprintf(outf, "INITSCR()\n");
20# endif
21 if (My_term)
22 setterm(Def_term);
23 else {
24 if (isatty(2))
25 _tty_ch = 2;
26 else {
27 nfd = getdtablesize();
28 for (_tty_ch = 0; _tty_ch < nfd; _tty_ch++)
29 if (isatty(_tty_ch))
30 break;
31 }
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 }
40 _puts(TI);
41 _puts(VS);
42# ifdef SIGTSTP
43 signal(SIGTSTP, tstp);
44# endif
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
54 if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
55 return ERR;
56 clearok(curscr, TRUE);
57 curscr->_flags &= ~_FULLLINE;
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}