1 /****************************************************************************
2 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
38 ** The newterm() function.
42 #include <curses.priv.h>
44 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
48 #include <term.h> /* clear_screen, cup & friends, cur_term */
51 MODULE_ID("$Id: lib_newterm.c,v 1.64 2006/01/14 15:36:24 tom Exp $")
53 #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */
58 * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not
59 * restored during the curses session. The library simulates echo in software.
60 * (The behavior is unspecified if the application enables hardware echo).
62 * The newterm function also initializes terminal settings, and since initscr
63 * is supposed to behave as if it calls newterm, we do it here.
65 static NCURSES_INLINE int
70 /* for extended XPG4 conformance requires cbreak() at this point */
71 /* (SVr4 curses does this anyway) */
75 buf = cur_term->Nttyb;
77 buf.c_lflag &= ~(ECHO | ECHONL);
78 buf.c_iflag &= ~(ICRNL | INLCR | IGNCR);
79 buf.c_oflag &= ~(ONLCR);
81 buf.sg_flags &= ~(ECHO | CRMOD);
83 memset(&buf, 0, sizeof(buf));
85 if ((result = _nc_set_tty_mode(&buf)) == OK)
86 cur_term->Nttyb = buf;
92 * filter() has to be called before either initscr() or newterm(), so there is
93 * apparently no way to make this flag apply to some terminals and not others,
94 * aside from possibly delaying a filter() call until some terminals have been
97 static bool filter_mode = FALSE;
103 T((T_CALLED("filter")));
108 #if NCURSES_EXT_FUNCS
110 * An extension, allowing the application to open a new screen without
111 * requiring it to also be filtered.
117 T((T_CALLED("nofilter")));
123 NCURSES_EXPORT(SCREEN *)
124 newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
128 int slk_format = _nc_slk_format;
133 T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp));
135 _nc_handle_sigwinch(0);
137 /* allow user to set maximum escape delay from the environment */
138 if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
142 /* this loads the capability entry, then sets LINES and COLS */
143 if (setupterm(name, fileno(ofp), &errret) == ERR) {
147 * This actually allocates the screen structure, and saves the original
152 if (_nc_setupscreen(LINES, COLS, ofp, filter_mode, slk_format) == ERR) {
153 _nc_set_screen(current);
156 /* if the terminal type has real soft labels, set those up */
157 if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format))
158 _nc_slk_initialize(stdscr, COLS);
160 SP->_ifd = fileno(ifp);
161 typeahead(fileno(ifp));
163 SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
164 !(cur_term->Ottyb.c_iflag & ISTRIP));
166 SP->_use_meta = FALSE;
171 * Check whether we can optimize scrolling under dumb terminals in
172 * case we do not have any of these capabilities, scrolling
173 * optimization will be useless.
175 SP->_scrolling = ((scroll_forward && scroll_reverse) ||
183 baudrate(); /* sets a field in the SP structure */
188 * Check for mismatched graphic-rendition capabilities. Most SVr4
189 * terminfo trees contain entries that have rmul or rmso equated to
190 * sgr0 (Solaris curses copes with those entries). We do this only
191 * for curses, since many termcap applications assume that
192 * smso/rmso and smul/rmul are paired, and will not function
193 * properly if we remove rmso or rmul. Curses applications
194 * shouldn't be looking at this detail.
196 #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
197 SP->_use_rmso = SGR0_TEST(exit_standout_mode);
198 SP->_use_rmul = SGR0_TEST(exit_underline_mode);
200 /* compute movement costs so we can do better move optimization */
203 /* initialize terminal to a sane state */
206 /* Initialize the terminal line settings. */
209 _nc_signal_handler(TRUE);
214 _nc_handle_sigwinch(1);