[BACK]Return to screen.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libcurses

Annotation of src/lib/libcurses/screen.c, Revision 1.9

1.9     ! blymn       1: /*     $NetBSD: screen.c,v 1.8 2002/12/23 12:25:10 jdc Exp $   */
1.1       blymn       2:
                      3: /*
                      4:  * Copyright (c) 1981, 1993, 1994
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *     This product includes software developed by the University of
                     18:  *     California, Berkeley and its contributors.
                     19:  * 4. Neither the name of the University nor the names of its contributors
                     20:  *    may be used to endorse or promote products derived from this software
                     21:  *    without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     33:  * SUCH DAMAGE.
                     34:  */
                     35:
                     36: #include <sys/cdefs.h>
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "@(#)screen.c   8.2 (blymn) 11/27/2001";
                     40: #else
1.9     ! blymn      41: __RCSID("$NetBSD: screen.c,v 1.8 2002/12/23 12:25:10 jdc Exp $");
1.1       blymn      42: #endif
                     43: #endif                                 /* not lint */
                     44:
                     45: #include <stdlib.h>
                     46:
                     47: #include "curses.h"
                     48: #include "curses_private.h"
                     49:
                     50: /*
                     51:  * set_term --
                     52:  *      Change the term to the given screen.
                     53:  *
                     54:  */
                     55: SCREEN *
                     56: set_term(SCREEN *new)
                     57: {
1.4       blymn      58:        SCREEN *old_screen = _cursesi_screen;
1.1       blymn      59:
                     60:        if (_cursesi_screen != NULL) {
                     61:                  /* save changes made to the current screen... */
                     62:                old_screen->echoit = __echoit;
                     63:                old_screen->pfast = __pfast;
                     64:                old_screen->rawmode = __rawmode;
                     65:                old_screen->noqch = __noqch;
                     66:                old_screen->nca = __nca;
                     67:                old_screen->winlistp = __winlistp;
                     68:                old_screen->COLS = COLS;
                     69:                old_screen->LINES = LINES;
                     70:                old_screen->COLORS = COLORS;
                     71:                old_screen->COLOR_PAIRS = COLOR_PAIRS;
                     72:                old_screen->GT = __GT;
                     73:                old_screen->NONL = __NONL;
                     74:                old_screen->UPPERCASE = __UPPERCASE;
                     75:        }
1.5       blymn      76:
1.1       blymn      77:        _cursesi_screen = new;
1.5       blymn      78:
1.1       blymn      79:        __echoit = new->echoit;
                     80:         __pfast = new->pfast;
                     81:        __rawmode = new->rawmode;
                     82:        __noqch = new->noqch;
                     83:        __nca = new->nca;
                     84:        COLS = new->COLS;
                     85:        LINES = new->LINES;
                     86:        COLORS = new->COLORS;
                     87:        COLOR_PAIRS = new->COLOR_PAIRS;
                     88:        __GT = new->GT;
                     89:        __NONL = new->NONL;
                     90:        __UPPERCASE = new->UPPERCASE;
                     91:
                     92:        _cursesi_resetterm(new);
1.5       blymn      93:
1.1       blymn      94:        __winlistp = new->winlistp;
                     95:
                     96:        curscr = new->curscr;
                     97:        clearok(curscr, new->clearok);
                     98:        stdscr = new->stdscr;
                     99:        __virtscr = new->__virtscr;
                    100:
                    101:        _cursesi_reset_acs(new);
                    102:
                    103: #ifdef DEBUG
                    104:        __CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
                    105: #endif
                    106:
                    107:        return old_screen;
                    108: }
                    109:
                    110: /*
                    111:  * newterm --
                    112:  *      Set up a new screen.
                    113:  *
                    114:  */
                    115: SCREEN *
                    116: newterm(char *type, FILE *outfd, FILE *infd)
                    117: {
                    118:        SCREEN *new_screen;
                    119:        char *sp;
                    120:
                    121:        sp = type;
                    122:        if ((type == NULL) && (sp = getenv("TERM")) == NULL)
                    123:                return NULL;
1.5       blymn     124:
1.1       blymn     125:        if ((new_screen = (SCREEN *) malloc(sizeof(SCREEN))) == NULL)
                    126:                return NULL;
                    127:
                    128:        new_screen->infd = infd;
                    129:        new_screen->outfd = outfd;
                    130:        new_screen->echoit = 1;
                    131:         new_screen->pfast = new_screen->rawmode = new_screen->noqch = 0;
                    132:        new_screen->nca = A_NORMAL;
                    133:        new_screen->color_type = COLOR_NONE;
1.7       jdc       134:        new_screen->COLOR_PAIRS = 0;
1.1       blymn     135:        new_screen->old_mode = 2;
                    136:        new_screen->stdbuf = NULL;
                    137:        new_screen->stdscr = NULL;
                    138:        new_screen->curscr = NULL;
                    139:        new_screen->__virtscr = NULL;
                    140:        new_screen->curwin = 0;
1.6       itojun    141:        new_screen->notty = FALSE;
1.9     ! blymn     142:        new_screen->half_delay = FALSE;
1.5       blymn     143:
1.1       blymn     144:        if (_cursesi_gettmode(new_screen) == ERR)
                    145:                goto error_exit;
                    146:
                    147:        if (_cursesi_setterm((char *)sp, new_screen) == ERR)
                    148:                goto error_exit;
                    149:
                    150:        /* Need either homing or cursor motion for refreshes */
                    151:        if (!new_screen->tc_ho && !new_screen->tc_cm)
                    152:                goto error_exit;
1.5       blymn     153:
1.1       blymn     154:        new_screen->winlistp = NULL;
                    155:
                    156:        if ((new_screen->curscr = __newwin(new_screen, new_screen->LINES,
1.8       jdc       157:            new_screen->COLS, 0, 0, FALSE)) == ERR)
1.1       blymn     158:                goto error_exit;
                    159:
                    160:        if ((new_screen->stdscr = __newwin(new_screen, new_screen->LINES,
1.8       jdc       161:            new_screen->COLS, 0, 0, FALSE)) == ERR) {
1.1       blymn     162:                delwin(new_screen->curscr);
                    163:                goto error_exit;
                    164:        }
                    165:
                    166:        if ((new_screen->__virtscr = __newwin(new_screen, new_screen->LINES,
1.8       jdc       167:            new_screen->COLS, 0, 0, FALSE)) == ERR) {
1.1       blymn     168:                delwin(new_screen->curscr);
                    169:                delwin(new_screen->stdscr);
                    170:                goto error_exit;
                    171:        }
                    172:
                    173:        __init_getch(new_screen);
                    174:
                    175:        __init_acs(new_screen);
                    176:
                    177:        __set_stophandler();
                    178:
                    179:          /*
                    180:           * bleh - it seems that apps expect the first newterm to set
                    181:           * up the curses screen.... emulate this.
                    182:           */
1.3       blymn     183:        if (_cursesi_screen == NULL || _cursesi_screen->endwin) {
1.1       blymn     184:                set_term(new_screen);
                    185:        }
1.5       blymn     186:
1.1       blymn     187: #ifdef DEBUG
                    188:        __CTRACE("newterm: LINES = %d, COLS = %d\n", LINES, COLS);
                    189: #endif
                    190:        __startwin(new_screen);
                    191:
                    192:        return new_screen;
                    193:
                    194:   error_exit:
                    195:        free(new_screen);
                    196:        return NULL;
                    197: }
                    198:
                    199: /*
                    200:  * delscreen --
                    201:  *   Free resources used by the given screen and destroy it.
                    202:  *
                    203:  */
                    204: void
                    205: delscreen(SCREEN *screen)
                    206: {
                    207:         struct __winlist *list, *np;
                    208:
                    209:          /* free up the termcap entry stuff */
                    210:        t_freent(screen->cursesi_genbuf);
                    211:
                    212:          /* walk the window list and kill all the parent windows */
                    213:        for (list = screen->winlistp; list != NULL; list = list->nextp) {
                    214:                if (list->winp->orig == NULL)
                    215:                        delwin(list->winp);
                    216:        }
                    217:
                    218:          /* free the windows list structures */
                    219:        for (list = screen->winlistp; list;) {
                    220:                np = list->nextp;
                    221:                free(list);
                    222:                list = np;
                    223:        }
1.5       blymn     224:
1.1       blymn     225:          /* free the storage of the keymaps */
                    226:        _cursesi_free_keymap(screen->base_keymap);
                    227:
                    228:        free(screen->stdbuf);
                    229:        free(screen);
                    230: }

CVSweb <webmaster@jp.NetBSD.org>