2004-03-24 00:17:20 +03:00
|
|
|
/* $NetBSD: screen.c,v 1.17 2004/03/23 21:17:20 jdc Exp $ */
|
2001-12-02 12:14:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1981, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:42:00 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2001-12-02 12:14:20 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001";
|
|
|
|
#else
|
2004-03-24 00:17:20 +03:00
|
|
|
__RCSID("$NetBSD: screen.c,v 1.17 2004/03/23 21:17:20 jdc Exp $");
|
2001-12-02 12:14:20 +03:00
|
|
|
#endif
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "curses.h"
|
|
|
|
#include "curses_private.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set_term --
|
|
|
|
* Change the term to the given screen.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
SCREEN *
|
|
|
|
set_term(SCREEN *new)
|
|
|
|
{
|
2001-12-31 17:16:01 +03:00
|
|
|
SCREEN *old_screen = _cursesi_screen;
|
2001-12-02 12:14:20 +03:00
|
|
|
|
|
|
|
if (_cursesi_screen != NULL) {
|
|
|
|
/* save changes made to the current screen... */
|
|
|
|
old_screen->echoit = __echoit;
|
|
|
|
old_screen->pfast = __pfast;
|
|
|
|
old_screen->rawmode = __rawmode;
|
|
|
|
old_screen->noqch = __noqch;
|
|
|
|
old_screen->COLS = COLS;
|
|
|
|
old_screen->LINES = LINES;
|
|
|
|
old_screen->COLORS = COLORS;
|
|
|
|
old_screen->COLOR_PAIRS = COLOR_PAIRS;
|
|
|
|
old_screen->GT = __GT;
|
|
|
|
old_screen->NONL = __NONL;
|
|
|
|
old_screen->UPPERCASE = __UPPERCASE;
|
|
|
|
}
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
_cursesi_screen = new;
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
__echoit = new->echoit;
|
|
|
|
__pfast = new->pfast;
|
|
|
|
__rawmode = new->rawmode;
|
|
|
|
__noqch = new->noqch;
|
|
|
|
COLS = new->COLS;
|
|
|
|
LINES = new->LINES;
|
|
|
|
COLORS = new->COLORS;
|
|
|
|
COLOR_PAIRS = new->COLOR_PAIRS;
|
|
|
|
__GT = new->GT;
|
|
|
|
__NONL = new->NONL;
|
|
|
|
__UPPERCASE = new->UPPERCASE;
|
|
|
|
|
|
|
|
_cursesi_resetterm(new);
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
curscr = new->curscr;
|
|
|
|
clearok(curscr, new->clearok);
|
|
|
|
stdscr = new->stdscr;
|
|
|
|
__virtscr = new->__virtscr;
|
|
|
|
|
|
|
|
_cursesi_reset_acs(new);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return old_screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* newterm --
|
|
|
|
* Set up a new screen.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
SCREEN *
|
|
|
|
newterm(char *type, FILE *outfd, FILE *infd)
|
|
|
|
{
|
|
|
|
SCREEN *new_screen;
|
|
|
|
char *sp;
|
|
|
|
|
|
|
|
sp = type;
|
|
|
|
if ((type == NULL) && (sp = getenv("TERM")) == NULL)
|
|
|
|
return NULL;
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
if ((new_screen = (SCREEN *) malloc(sizeof(SCREEN))) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
new_screen->infd = infd;
|
|
|
|
new_screen->outfd = outfd;
|
2003-04-05 14:06:59 +04:00
|
|
|
new_screen->echoit = new_screen->nl = 1;
|
2001-12-02 12:14:20 +03:00
|
|
|
new_screen->pfast = new_screen->rawmode = new_screen->noqch = 0;
|
|
|
|
new_screen->nca = A_NORMAL;
|
|
|
|
new_screen->color_type = COLOR_NONE;
|
2002-08-04 20:43:04 +04:00
|
|
|
new_screen->COLOR_PAIRS = 0;
|
2001-12-02 12:14:20 +03:00
|
|
|
new_screen->old_mode = 2;
|
|
|
|
new_screen->stdbuf = NULL;
|
|
|
|
new_screen->stdscr = NULL;
|
|
|
|
new_screen->curscr = NULL;
|
|
|
|
new_screen->__virtscr = NULL;
|
|
|
|
new_screen->curwin = 0;
|
2002-06-26 22:23:28 +04:00
|
|
|
new_screen->notty = FALSE;
|
2003-01-09 15:48:04 +03:00
|
|
|
new_screen->half_delay = FALSE;
|
2004-03-22 21:57:10 +03:00
|
|
|
new_screen->resized = 0;
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
if (_cursesi_gettmode(new_screen) == ERR)
|
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
if (_cursesi_setterm((char *)sp, new_screen) == ERR)
|
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
/* Need either homing or cursor motion for refreshes */
|
|
|
|
if (!new_screen->tc_ho && !new_screen->tc_cm)
|
|
|
|
goto error_exit;
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
new_screen->winlistp = NULL;
|
|
|
|
|
2003-02-17 14:07:19 +03:00
|
|
|
if ((new_screen->curscr = __newwin(new_screen, 0,
|
2004-03-24 00:17:20 +03:00
|
|
|
0, 0, 0, FALSE)) == NULL)
|
2001-12-02 12:14:20 +03:00
|
|
|
goto error_exit;
|
|
|
|
|
2003-02-17 14:07:19 +03:00
|
|
|
if ((new_screen->stdscr = __newwin(new_screen, 0,
|
2004-03-24 00:17:20 +03:00
|
|
|
0, 0, 0, FALSE)) == NULL) {
|
2001-12-02 12:14:20 +03:00
|
|
|
delwin(new_screen->curscr);
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
2003-02-02 20:52:29 +03:00
|
|
|
clearok(new_screen->stdscr, 1);
|
|
|
|
|
2003-02-17 14:07:19 +03:00
|
|
|
if ((new_screen->__virtscr = __newwin(new_screen, 0,
|
2004-03-24 00:17:20 +03:00
|
|
|
0, 0, 0, FALSE)) == NULL) {
|
2001-12-02 12:14:20 +03:00
|
|
|
delwin(new_screen->curscr);
|
|
|
|
delwin(new_screen->stdscr);
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
__init_getch(new_screen);
|
|
|
|
|
|
|
|
__init_acs(new_screen);
|
|
|
|
|
|
|
|
__set_stophandler();
|
2004-03-22 21:57:10 +03:00
|
|
|
__set_winchhandler();
|
2001-12-02 12:14:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* bleh - it seems that apps expect the first newterm to set
|
|
|
|
* up the curses screen.... emulate this.
|
|
|
|
*/
|
2001-12-30 16:20:35 +03:00
|
|
|
if (_cursesi_screen == NULL || _cursesi_screen->endwin) {
|
2001-12-02 12:14:20 +03:00
|
|
|
set_term(new_screen);
|
|
|
|
}
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
__CTRACE("newterm: LINES = %d, COLS = %d\n", LINES, COLS);
|
|
|
|
#endif
|
|
|
|
__startwin(new_screen);
|
|
|
|
|
|
|
|
return new_screen;
|
|
|
|
|
|
|
|
error_exit:
|
|
|
|
free(new_screen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* delscreen --
|
|
|
|
* Free resources used by the given screen and destroy it.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
delscreen(SCREEN *screen)
|
|
|
|
{
|
2003-07-30 15:19:00 +04:00
|
|
|
struct __winlist *list;
|
2001-12-02 12:14:20 +03:00
|
|
|
|
|
|
|
/* free up the termcap entry stuff */
|
|
|
|
t_freent(screen->cursesi_genbuf);
|
|
|
|
|
|
|
|
/* walk the window list and kill all the parent windows */
|
2004-03-24 00:17:20 +03:00
|
|
|
while ((list = screen->winlistp) != NULL) {
|
2003-07-30 15:19:00 +04:00
|
|
|
delwin(list->winp);
|
|
|
|
if (list == screen->winlistp)
|
|
|
|
/* sanity - abort if window didn't remove itself */
|
|
|
|
break;
|
2001-12-02 12:14:20 +03:00
|
|
|
}
|
2002-01-02 13:38:27 +03:00
|
|
|
|
2001-12-02 12:14:20 +03:00
|
|
|
/* free the storage of the keymaps */
|
|
|
|
_cursesi_free_keymap(screen->base_keymap);
|
|
|
|
|
|
|
|
free(screen->stdbuf);
|
|
|
|
free(screen);
|
|
|
|
}
|