~ubuntu-branches/ubuntu/natty/ncurses/natty

« back to all changes in this revision

Viewing changes to ncurses/base/lib_newterm.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-17 09:00:42 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517090042-86fgxrr6j5jzagot
Tags: 5.6-0ubuntu1
* New upstream version.
  - Remove patches applied upstream: ncurses.upstream, signed-chars.
  - Update patches: debian-backspace.
* Build-depend on g++-multilib instead of lib{32,64}c*-dev-*.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
 
 * Copyright (c) 1998-2002,2004 Free Software Foundation, Inc.              *
 
2
 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
3
3
 *                                                                          *
4
4
 * Permission is hereby granted, free of charge, to any person obtaining a  *
5
5
 * copy of this software and associated documentation files (the            *
48
48
#include <term.h>               /* clear_screen, cup & friends, cur_term */
49
49
#include <tic.h>
50
50
 
51
 
MODULE_ID("$Id: lib_newterm.c,v 1.58 2004/08/14 20:36:39 tom Exp $")
 
51
MODULE_ID("$Id: lib_newterm.c,v 1.64 2006/01/14 15:36:24 tom Exp $")
52
52
 
53
53
#ifndef ONLCR                   /* Allows compilation under the QNX 4.2 OS */
54
54
#define ONLCR 0
62
62
 * The newterm function also initializes terminal settings, and since initscr
63
63
 * is supposed to behave as if it calls newterm, we do it here.
64
64
 */
65
 
static inline int
 
65
static NCURSES_INLINE int
66
66
_nc_initscr(void)
67
67
{
68
68
    int result = ERR;
77
77
        buf.c_lflag &= ~(ECHO | ECHONL);
78
78
        buf.c_iflag &= ~(ICRNL | INLCR | IGNCR);
79
79
        buf.c_oflag &= ~(ONLCR);
80
 
#else
 
80
#elif HAVE_SGTTY_H
81
81
        buf.sg_flags &= ~(ECHO | CRMOD);
 
82
#else
 
83
        memset(&buf, 0, sizeof(buf));
82
84
#endif
83
85
        if ((result = _nc_set_tty_mode(&buf)) == OK)
84
86
            cur_term->Nttyb = buf;
92
94
 * aside from possibly delaying a filter() call until some terminals have been
93
95
 * initialized.
94
96
 */
95
 
static int filter_mode = FALSE;
 
97
static bool filter_mode = FALSE;
96
98
 
97
99
NCURSES_EXPORT(void)
98
100
filter(void)
99
101
{
 
102
    START_TRACE();
100
103
    T((T_CALLED("filter")));
101
104
    filter_mode = TRUE;
102
105
    returnVoid;
103
106
}
104
107
 
 
108
#if NCURSES_EXT_FUNCS
 
109
/*
 
110
 * An extension, allowing the application to open a new screen without
 
111
 * requiring it to also be filtered.
 
112
 */
 
113
NCURSES_EXPORT(void)
 
114
nofilter(void)
 
115
{
 
116
    START_TRACE();
 
117
    T((T_CALLED("nofilter")));
 
118
    filter_mode = FALSE;
 
119
    returnVoid;
 
120
}
 
121
#endif
 
122
 
105
123
NCURSES_EXPORT(SCREEN *)
106
124
newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
107
125
{
 
126
    int value;
108
127
    int errret;
109
128
    int slk_format = _nc_slk_format;
110
129
    SCREEN *current;
 
130
    SCREEN *result = 0;
111
131
 
112
132
    START_TRACE();
113
133
    T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp));
114
134
 
 
135
    _nc_handle_sigwinch(0);
 
136
 
 
137
    /* allow user to set maximum escape delay from the environment */
 
138
    if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
 
139
        ESCDELAY = value;
 
140
    }
 
141
 
115
142
    /* this loads the capability entry, then sets LINES and COLS */
116
 
    if (setupterm(name, fileno(ofp), &errret) == ERR)
117
 
        returnSP(0);
118
 
 
119
 
    /* implement filter mode */
120
 
    if (filter_mode) {
121
 
        LINES = 1;
122
 
 
123
 
        clear_screen = 0;
124
 
        cursor_down = parm_down_cursor = 0;
125
 
        cursor_address = 0;
126
 
        cursor_up = parm_up_cursor = 0;
127
 
        row_address = 0;
128
 
 
129
 
        cursor_home = carriage_return;
130
 
    }
131
 
 
132
 
    /* If we must simulate soft labels, grab off the line to be used.
133
 
       We assume that we must simulate, if it is none of the standard
134
 
       formats (4-4  or 3-2-3) for which there may be some hardware
135
 
       support. */
136
 
    if (num_labels <= 0 || !SLK_STDFMT(slk_format))
137
 
        if (slk_format) {
138
 
            if (ERR == _nc_ripoffline(-SLK_LINES(slk_format),
139
 
                                      _nc_slk_initialize))
140
 
                returnSP(0);
 
143
    if (setupterm(name, fileno(ofp), &errret) == ERR) {
 
144
        result = 0;
 
145
    } else {
 
146
        /*
 
147
         * This actually allocates the screen structure, and saves the original
 
148
         * terminal settings.
 
149
         */
 
150
        current = SP;
 
151
        _nc_set_screen(0);
 
152
        if (_nc_setupscreen(LINES, COLS, ofp, filter_mode, slk_format) == ERR) {
 
153
            _nc_set_screen(current);
 
154
            result = 0;
 
155
        } else {
 
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);
 
159
 
 
160
            SP->_ifd = fileno(ifp);
 
161
            typeahead(fileno(ifp));
 
162
#ifdef TERMIOS
 
163
            SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
 
164
                             !(cur_term->Ottyb.c_iflag & ISTRIP));
 
165
#else
 
166
            SP->_use_meta = FALSE;
 
167
#endif
 
168
            SP->_endwin = FALSE;
 
169
 
 
170
            /*
 
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.
 
174
             */
 
175
            SP->_scrolling = ((scroll_forward && scroll_reverse) ||
 
176
                              ((parm_rindex ||
 
177
                                parm_insert_line ||
 
178
                                insert_line) &&
 
179
                               (parm_index ||
 
180
                                parm_delete_line ||
 
181
                                delete_line)));
 
182
 
 
183
            baudrate();         /* sets a field in the SP structure */
 
184
 
 
185
            SP->_keytry = 0;
 
186
 
 
187
            /*
 
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.
 
195
             */
 
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);
 
199
 
 
200
            /* compute movement costs so we can do better move optimization */
 
201
            _nc_mvcur_init();
 
202
 
 
203
            /* initialize terminal to a sane state */
 
204
            _nc_screen_init();
 
205
 
 
206
            /* Initialize the terminal line settings. */
 
207
            _nc_initscr();
 
208
 
 
209
            _nc_signal_handler(TRUE);
 
210
 
 
211
            result = SP;
141
212
        }
142
 
    /* this actually allocates the screen structure, and saves the
143
 
     * original terminal settings.
144
 
     */
145
 
    current = SP;
146
 
    _nc_set_screen(0);
147
 
    if (_nc_setupscreen(LINES, COLS, ofp) == ERR) {
148
 
        _nc_set_screen(current);
149
 
        returnSP(0);
150
213
    }
151
 
 
152
 
    /* if the terminal type has real soft labels, set those up */
153
 
    if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format))
154
 
        _nc_slk_initialize(stdscr, COLS);
155
 
 
156
 
    SP->_ifd = fileno(ifp);
157
 
    typeahead(fileno(ifp));
158
 
#ifdef TERMIOS
159
 
    SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
160
 
                     !(cur_term->Ottyb.c_iflag & ISTRIP));
161
 
#else
162
 
    SP->_use_meta = FALSE;
163
 
#endif
164
 
    SP->_endwin = FALSE;
165
 
 
166
 
    /* Check whether we can optimize scrolling under dumb terminals in case
167
 
     * we do not have any of these capabilities, scrolling optimization
168
 
     * will be useless.
169
 
     */
170
 
    SP->_scrolling = ((scroll_forward && scroll_reverse) ||
171
 
                      ((parm_rindex || parm_insert_line || insert_line) &&
172
 
                       (parm_index || parm_delete_line || delete_line)));
173
 
 
174
 
    baudrate();                 /* sets a field in the SP structure */
175
 
 
176
 
    SP->_keytry = 0;
177
 
 
178
 
    /*
179
 
     * Check for mismatched graphic-rendition capabilities.  Most SVr4
180
 
     * terminfo trees contain entries that have rmul or rmso equated to
181
 
     * sgr0 (Solaris curses copes with those entries).  We do this only for
182
 
     * curses, since many termcap applications assume that smso/rmso and
183
 
     * smul/rmul are paired, and will not function properly if we remove
184
 
     * rmso or rmul.  Curses applications shouldn't be looking at this
185
 
     * detail.
186
 
     */
187
 
#define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
188
 
    SP->_use_rmso = SGR0_TEST(exit_standout_mode);
189
 
    SP->_use_rmul = SGR0_TEST(exit_underline_mode);
190
 
 
191
 
    /* compute movement costs so we can do better move optimization */
192
 
    _nc_mvcur_init();
193
 
 
194
 
    /* initialize terminal to a sane state */
195
 
    _nc_screen_init();
196
 
 
197
 
    /* Initialize the terminal line settings. */
198
 
    _nc_initscr();
199
 
 
200
 
    _nc_signal_handler(TRUE);
201
 
 
202
 
#if USE_SIZECHANGE
203
 
    /*
204
 
     * Pretend we received a SIGWINCH, just in case we're starting up in a
205
 
     * terminal that cannot initialize its size properly (Debian #265631).
206
 
     */
207
 
    SP->_sig_winch = TRUE;
208
 
#endif
209
 
 
210
 
    returnSP(SP);
 
214
    _nc_handle_sigwinch(1);
 
215
    returnSP(result);
211
216
}