1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 /* LINTLIBRARY */
28
29 /*
30 * initscr.c
31 *
32 * XCurses Library
33 *
34 * Copyright 1986, 1994 by Mortice Kern Systems Inc. All rights reserved.
35 *
36 */
37
38 #ifdef M_RCSID
39 #ifndef lint
40 static char rcsID[] =
41 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
42 "libxcurses/src/libc/xcurses/rcs/initscr.c 1.4 1998/04/30 20:30:21 "
43 "cbates Exp $";
44 #endif
45 #endif
46
47 #include <private.h>
48 #include <errno.h>
49 #include <stdlib.h>
50
51 static const char nomem_msg[] = "Failed to allocate required memory.\n";
52 static const char noterm_msg[] = "Unknown terminal \"%s\".\n";
53 static const char dumb_msg[] =
54 "Terminal \"%s\" has insufficent capabilities for Curses.\n";
55
56 /*
57 * Initialize XCurses for use with a single terminal. stdin and stdout
58 * are used. If a program needs an indication of error conditions,
59 * so that it can continue to run in a line-oriented mode, use newterm()
60 * instead.
61 */
62 WINDOW *
initscr(void)63 initscr(void)
64 {
65 SCREEN *sp;
66 char *term, *err;
67
68 errno = 0;
69 sp = newterm(NULL, stdout, stdin);
70
71 if (sp == NULL) {
72 err = (errno == ENOMEM) ? (char *)nomem_msg :
73 (char *)noterm_msg;
74 goto error_1;
75 }
76
77 (void) set_term(sp);
78
79 /*
80 * We require some form of cursor positioning and the ability to
81 * clear the end of a line. These abilities should be sufficient
82 * to provide minimum full screen support.
83 */
84 if ((1 < lines) && (cursor_address == NULL) &&
85 (row_address == NULL) &&
86 ((cursor_up == NULL) || (cursor_down == NULL)) &&
87 ((parm_up_cursor == NULL) || (parm_down_cursor == NULL))) {
88 err = (char *)dumb_msg;
89 goto error_3;
90 }
91
92 if (((1 < lines) && (cursor_address == NULL)) &&
93 (column_address == NULL) &&
94 ((cursor_left == NULL) || (cursor_right == NULL)) &&
95 ((parm_left_cursor == NULL) ||
96 (parm_right_cursor == NULL))) {
97 err = (char *)dumb_msg;
98 goto error_3;
99 }
100
101 if (clr_eol == NULL) {
102 err = (char *)dumb_msg;
103 goto error_3;
104 }
105
106 return (stdscr);
107
108 error_3:
109 (void) delwin(stdscr);
110 (void) endwin();
111 (void) delscreen(sp);
112
113 error_1:
114 /*
115 * newterm()/setupterm() attempts to load $TERM, else if
116 * $TERM is not defined, the vendor's default terminal type.
117 */
118 if ((term = getenv("TERM")) == NULL) {
119 term = M_TERM_NAME;
120 }
121
122 (void) fprintf(stderr, err, term);
123 exit(1);
124 return (NULL);
125 }
126