xref: /original-bsd/lib/libcurses/initscr.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1981, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)initscr.c	8.1 (Berkeley) 06/04/93";
10 #endif	/* not lint */
11 
12 #include <curses.h>
13 #include <signal.h>
14 #include <stdlib.h>
15 
16 /*
17  * initscr --
18  *	Initialize the current and standard screen.
19  */
20 WINDOW *
21 initscr()
22 {
23 	register char *sp;
24 
25 #ifdef DEBUG
26 	__CTRACE("initscr\n");
27 #endif
28 	__echoit = 1;
29         __pfast = __rawmode = __noqch = 0;
30 
31 	if (gettmode() == ERR)
32 		return (NULL);
33 
34 	/*
35 	 * If My_term is set, or can't find a terminal in the environment,
36 	 * use Def_term.
37 	 */
38 	if (My_term || (sp = getenv("TERM")) == NULL)
39 		sp = Def_term;
40 	if (setterm(sp) == ERR)
41 		return (NULL);
42 
43 	/* Need either homing or cursor motion for refreshes */
44 	if (!HO && !CM)
45 		return (NULL);
46 
47 	if (curscr != NULL)
48 		delwin(curscr);
49 	if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
50 		return (NULL);
51 	clearok(curscr, 1);
52 
53 	if (stdscr != NULL)
54 		delwin(stdscr);
55 	if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) {
56 		delwin(curscr);
57 		return (NULL);
58 	}
59 
60 	__set_stophandler();
61 
62 #ifdef DEBUG
63 	__CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
64 #endif
65 	__startwin();
66 
67 	return (stdscr);
68 }
69