1 /****************************************************************************
2 * Copyright (c) 1998 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 ****************************************************************************/
39 ** The newterm() function.
43 #include <curses.priv.h>
45 #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
49 #include <term.h> /* clear_screen, cup & friends, cur_term */
51 MODULE_ID("$Id: lib_newterm.c,v 1.33 1998/02/11 12:13:57 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 inline int _nc_initscr(void)
67 /* for extended XPG4 conformance requires cbreak() at this point */
68 /* (SVr4 curses does this anyway) */
72 cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL);
73 cur_term->Nttyb.c_iflag &= ~(ICRNL|INLCR|IGNCR);
74 cur_term->Nttyb.c_oflag &= ~(ONLCR);
76 cur_term->Nttyb.sg_flags &= ~(ECHO|CRMOD);
78 return _nc_set_curterm(&cur_term->Nttyb);
82 * filter() has to be called before either initscr() or newterm(), so there is
83 * apparently no way to make this flag apply to some terminals and not others,
84 * aside from possibly delaying a filter() call until some terminals have been
87 static int filter_mode = FALSE;
94 SCREEN * newterm(const char *term, FILE *ofp, FILE *ifp)
99 char *t = getenv("NCURSES_TRACE");
102 trace((unsigned) strtol(t, 0, 0));
105 T((T_CALLED("newterm(\"%s\",%p,%p)"), term, ofp, ifp));
107 /* this loads the capability entry, then sets LINES and COLS */
108 if (setupterm(term, fileno(ofp), &errret) == ERR)
112 * Check for mismatched graphic-rendition capabilities. Most SVr4
113 * terminfo trees contain entries that have rmul or rmso equated to
114 * sgr0 (Solaris curses copes with those entries). We do this only for
115 * curses, since many termcap applications assume that smso/rmso and
116 * smul/rmul are paired, and will not function properly if we remove
117 * rmso or rmul. Curses applications shouldn't be looking at this
120 if (exit_attribute_mode) {
121 #define SGR0_FIX(mode) if (mode != 0 && !strcmp(mode, exit_attribute_mode)) \
123 SGR0_FIX(exit_underline_mode);
124 SGR0_FIX(exit_standout_mode);
127 /* implement filter mode */
135 #endif /* init_tabs */
138 T(("TABSIZE = %d", TABSIZE));
142 cursor_down = parm_down_cursor = 0;
144 cursor_up = parm_up_cursor = 0;
147 cursor_home = carriage_return;
148 #endif /* clear_screen */
151 /* If we must simulate soft labels, grab off the line to be used.
152 We assume that we must simulate, if it is none of the standard
153 formats (4-4 or 3-2-3) for which there may be some hardware
156 if (num_labels <= 0 || !SLK_STDFMT)
157 #endif /* num_labels */
160 if (ERR==_nc_ripoffline(-SLK_LINES, _nc_slk_initialize))
163 /* this actually allocates the screen structure, and saves the
164 * original terminal settings.
168 if (_nc_setupscreen(LINES, COLS, ofp) == ERR) {
169 _nc_set_screen(current);
174 /* if the terminal type has real soft labels, set those up */
175 if (_nc_slk_format && num_labels > 0 && SLK_STDFMT)
176 _nc_slk_initialize(stdscr, COLS);
177 #endif /* num_labels */
179 SP->_ifd = fileno(ifp);
180 SP->_checkfd = fileno(ifp);
181 typeahead(fileno(ifp));
183 SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
184 !(cur_term->Ottyb.c_iflag & ISTRIP));
186 SP->_use_meta = FALSE;
190 /* Check whether we can optimize scrolling under dumb terminals in case
191 * we do not have any of these capabilities, scrolling optimization
194 SP->_scrolling = ((scroll_forward && scroll_reverse) ||
195 ((parm_rindex || parm_insert_line || insert_line) &&
196 (parm_index || parm_delete_line || delete_line)));
198 baudrate(); /* sets a field in the SP structure */
202 /* compute movement costs so we can do better move optimization */
205 _nc_signal_handler(TRUE);
207 /* initialize terminal to a sane state */
210 /* Initialize the terminal line settings. */
213 T((T_RETURN("%p"), SP));