]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_newterm.c
ncurses 4.1
[ncurses.git] / ncurses / lib_newterm.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22
23
24 /*
25 **      lib_newterm.c
26 **
27 **      The newterm() function.
28 **
29 */
30
31 #include <curses.priv.h>
32
33 #ifdef SVR4_TERMIO
34 #define _POSIX_SOURCE
35 #endif
36
37 #include <term.h>       /* clear_screen, cup & friends, cur_term */
38
39 MODULE_ID("$Id: lib_newterm.c,v 1.23 1997/03/30 01:42:01 tom Exp $")
40
41 /* This should be moved to TERMINAL */
42 static int filter_mode = FALSE;
43
44 void filter(void)
45 {
46     filter_mode = TRUE;
47 }
48
49 SCREEN * newterm(const char *term, FILE *ofp, FILE *ifp)
50 {
51 int     errret;
52 #ifdef TRACE
53 char *t = getenv("NCURSES_TRACE");
54
55         if (t)
56                trace((unsigned) strtol(t, 0, 0));
57 #endif
58
59         T((T_CALLED("newterm(\"%s\",%p,%p)"), term, ofp, ifp));
60
61         /* this loads the capability entry, then sets LINES and COLS */
62         if (setupterm(term, fileno(ofp), &errret) == ERR)
63                 return NULL;
64
65         /*
66          * Check for mismatched graphic-rendition capabilities.  Most SVr4
67          * terminfo tree contain entries that have rmul or rmso equated to sgr0
68          * (Solaris curses copes with those entries).  We do this only for
69          * curses, since many termcap applications assume that smso/rmso and
70          * smul/rmul are paired, and will not function properly if we remove
71          * rmso or rmul.  Curses applications shouldn't be looking at this
72          * detail.
73          */
74         if (exit_attribute_mode) {
75 #define SGR0_FIX(mode) if (mode != 0 && !strcmp(mode, exit_attribute_mode)) \
76                         mode = 0
77                 SGR0_FIX(exit_underline_mode);
78                 SGR0_FIX(exit_standout_mode);
79         }
80
81         /* implement filter mode */
82         if (filter_mode) {
83                 LINES = 1;
84
85 #ifdef init_tabs
86                 if (init_tabs != -1)
87                         TABSIZE = init_tabs;
88                 else
89 #endif /* init_tabs */
90                         TABSIZE = 8;
91
92                 T(("TABSIZE = %d", TABSIZE));
93
94 #ifdef clear_screen
95                 clear_screen = (char *)NULL;
96                 cursor_down = parm_down_cursor = (char *)NULL;
97                 cursor_address = (char *)NULL;
98                 cursor_up = parm_up_cursor = (char *)NULL;
99                 row_address = (char *)NULL;
100                 
101                 cursor_home = carriage_return;
102 #endif /* clear_screen */
103         }
104
105         /* If we must simulate soft labels, grab off the line to be used.
106            We assume that we must simulate, if it is none of the standard
107            formats (4-4  or 3-2-3) for which there may be some hardware
108            support. */
109 #ifdef num_labels
110         if (num_labels <= 0 || !SLK_STDFMT)
111 #endif /* num_labels */
112             if (_nc_slk_format)
113               {
114                 if (ERR==_nc_ripoffline(-SLK_LINES, _nc_slk_initialize))
115                   return NULL;
116               }
117         /* this actually allocates the screen structure, and saves the
118          * original terminal settings.
119          */
120         if (_nc_setupscreen(LINES, COLS, ofp) == ERR)
121                 return NULL;
122
123 #ifdef num_labels
124         /* if the terminal type has real soft labels, set those up */
125         if (_nc_slk_format && num_labels > 0 && SLK_STDFMT)
126             _nc_slk_initialize(stdscr, COLS);
127 #endif /* num_labels */
128
129         SP->_ifd        = fileno(ifp);
130         SP->_checkfd    = fileno(ifp);
131         typeahead(fileno(ifp));
132 #ifdef TERMIOS
133         SP->_use_meta   = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
134                             !(cur_term->Ottyb.c_iflag & ISTRIP));
135 #else
136         SP->_use_meta   = FALSE;
137 #endif
138         SP->_endwin     = FALSE;
139
140         baudrate();     /* sets a field in the SP structure */
141
142         /* compute movement costs so we can do better move optimization */
143         _nc_mvcur_init();
144
145         _nc_signal_handler(TRUE);
146
147         /* open a connection to the screen's associated mouse, if any */
148         _nc_mouse_init(SP);
149
150         /* Initialize the terminal line settings. */
151         _nc_initscr();
152
153         T((T_RETURN("%p"), SP));
154         return(SP);
155 }