4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / lib / libcurses / initscr.c
CommitLineData
6e1c93d0 1/*
2f14f200
KB
2 * Copyright (c) 1981 Regents of the University of California.
3 * All rights reserved.
4 *
c07973a2 5 * %sccs.include.redist.c%
6e1c93d0
DF
6 */
7
8#ifndef lint
14a0061d 9static char sccsid[] = "@(#)initscr.c 5.15 (Berkeley) %G%";
1d092b00 10#endif /* not lint */
6e1c93d0 11
1d092b00
KB
12#include <curses.h>
13#include <signal.h>
14#include <stdlib.h>
fa02ff96
KA
15
16/*
1d092b00
KB
17 * initscr --
18 * Initialize the current and standard screen.
fa02ff96
KA
19 */
20WINDOW *
1d092b00
KB
21initscr()
22{
23 register char *sp;
fa02ff96 24
1d092b00 25#ifdef DEBUG
14a0061d 26 __CTRACE("initscr\n");
1d092b00 27#endif
d31a5781
KB
28 __echoit = 1;
29 __pfast = __rawmode = __noqch = 0;
30
79ec5a07 31 if (gettmode() == ERR)
d31a5781
KB
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;
79ec5a07 40 if (setterm(sp) == ERR)
d31a5781
KB
41 return (NULL);
42
f4009729
EA
43 /* Need either homing or cursor motion for refreshes */
44 if (!HO && !CM)
d31a5781
KB
45 return (NULL);
46
d31a5781 47 if (curscr != NULL)
fa02ff96 48 delwin(curscr);
79ec5a07 49 if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
1d092b00
KB
50 return (NULL);
51 clearok(curscr, 1);
d31a5781
KB
52
53 if (stdscr != NULL)
fa02ff96 54 delwin(stdscr);
79ec5a07 55 if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) {
d31a5781
KB
56 delwin(curscr);
57 return (NULL);
fa02ff96 58 }
d31a5781 59
f7efeecb 60 (void)signal(SIGTSTP, __stop_signal_handler);
d31a5781
KB
61
62#ifdef DEBUG
14a0061d 63 __CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
d31a5781 64#endif
7885f659
KB
65 __startwin();
66
d31a5781 67 return (stdscr);
fa02ff96 68}