xref: /original-bsd/lib/libcurses/initscr.c (revision 3708840b)
1 # include	"curses.ext"
2 # include	<signal.h>
3 # include	<sys/param.h>
4 
5 extern char	*getenv();
6 
7 /*
8  *	This routine initializes the current and standard screen.
9  *
10  * 05/19/83 (Berkeley) @(#)initscr.c	1.3
11  */
12 WINDOW *
13 initscr() {
14 
15 	reg char	*sp;
16 	int		tstp();
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 			for (_tty_ch = 0; _tty_ch < NOFILE; _tty_ch++)
28 				if (isatty(_tty_ch))
29 					break;
30 		}
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 	}
39 	_puts(TI);
40 	_puts(VS);
41 # ifdef SIGTSTP
42 	signal(SIGTSTP, tstp);
43 # endif
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
53 	if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
54 		return ERR;
55 	curscr->_clear = TRUE;
56 	if (stdscr != NULL) {
57 # ifdef DEBUG
58 		fprintf(outf, "INITSCR: stdscr = 0%o\n", stdscr);
59 # endif
60 		delwin(stdscr);
61 	}
62 	stdscr = newwin(LINES, COLS, 0, 0);
63 	return stdscr;
64 }
65