diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-01-02 22:06:52 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-01-02 22:06:52 +0000 |
commit | d058cd399506bf5b5e3d43742d30cdabda06a8e7 (patch) | |
tree | b17920dcead3b7816d7cd0f534c3aba3ac561c07 /lib/libcurses/base | |
parent | 4170262b3e51f04453aa1a283175a95e4f9cf41b (diff) |
+ corrected conversion from terminfo rs2 to termcap rs (cf: 980704)
+ make conversion to termcap ug (underline glitch) more consistently applied.
+ modify read_termtype(), fixing 'toe', which could dump core when it
found an incomplete entry such as "dumb" because it did not
initialize its buffer for _nc_read_file_entry().
+ use explicit VALID_NUMERIC() checks in a few places that had been
overlooked, and add a check to ensure that init_tabs is nonzero,
to avoid divide-by-zero (reported by Todd C Miller).
Diffstat (limited to 'lib/libcurses/base')
-rw-r--r-- | lib/libcurses/base/lib_color.c | 504 | ||||
-rw-r--r-- | lib/libcurses/base/lib_newterm.c | 213 | ||||
-rw-r--r-- | lib/libcurses/base/lib_set_term.c | 423 |
3 files changed, 578 insertions, 562 deletions
diff --git a/lib/libcurses/base/lib_color.c b/lib/libcurses/base/lib_color.c index a06b5bbf354..f60847d43cd 100644 --- a/lib/libcurses/base/lib_color.c +++ b/lib/libcurses/base/lib_color.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_color.c,v 1.4 1999/11/28 17:49:53 millert Exp $ */ +/* $OpenBSD: lib_color.c,v 1.5 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,8 +41,9 @@ #include <curses.priv.h> #include <term.h> +#include <tic.h> -MODULE_ID("$From: lib_color.c,v 1.40 1999/11/27 22:24:18 tom Exp $") +MODULE_ID("$From: lib_color.c,v 1.42 2000/01/01 16:42:37 tom Exp $") /* * These should be screen structure members. They need to be globals for @@ -58,43 +59,45 @@ int COLORS = 0; */ #define RGB_ON 680 #define RGB_OFF 0 - +/* *INDENT-OFF* */ static const color_t cga_palette[] = { - /* R G B */ - {RGB_OFF, RGB_OFF, RGB_OFF}, /* COLOR_BLACK */ - {RGB_ON, RGB_OFF, RGB_OFF}, /* COLOR_RED */ - {RGB_OFF, RGB_ON, RGB_OFF}, /* COLOR_GREEN */ - {RGB_ON, RGB_ON, RGB_OFF}, /* COLOR_YELLOW */ - {RGB_OFF, RGB_OFF, RGB_ON}, /* COLOR_BLUE */ - {RGB_ON, RGB_OFF, RGB_ON}, /* COLOR_MAGENTA */ - {RGB_OFF, RGB_ON, RGB_ON}, /* COLOR_CYAN */ - {RGB_ON, RGB_ON, RGB_ON}, /* COLOR_WHITE */ + /* R G B */ + {RGB_OFF, RGB_OFF, RGB_OFF}, /* COLOR_BLACK */ + {RGB_ON, RGB_OFF, RGB_OFF}, /* COLOR_RED */ + {RGB_OFF, RGB_ON, RGB_OFF}, /* COLOR_GREEN */ + {RGB_ON, RGB_ON, RGB_OFF}, /* COLOR_YELLOW */ + {RGB_OFF, RGB_OFF, RGB_ON}, /* COLOR_BLUE */ + {RGB_ON, RGB_OFF, RGB_ON}, /* COLOR_MAGENTA */ + {RGB_OFF, RGB_ON, RGB_ON}, /* COLOR_CYAN */ + {RGB_ON, RGB_ON, RGB_ON}, /* COLOR_WHITE */ }; + static const color_t hls_palette[] = { - /* H L S */ - {0, 0, 0}, /* COLOR_BLACK */ - {120, 50, 100}, /* COLOR_RED */ - {240, 50, 100}, /* COLOR_GREEN */ - {180, 50, 100}, /* COLOR_YELLOW */ - {330, 50, 100}, /* COLOR_BLUE */ - {60, 50, 100}, /* COLOR_MAGENTA */ - {300, 50, 100}, /* COLOR_CYAN */ - {0, 50, 100}, /* COLOR_WHITE */ + /* H L S */ + { 0, 0, 0}, /* COLOR_BLACK */ + { 120, 50, 100}, /* COLOR_RED */ + { 240, 50, 100}, /* COLOR_GREEN */ + { 180, 50, 100}, /* COLOR_YELLOW */ + { 330, 50, 100}, /* COLOR_BLUE */ + { 60, 50, 100}, /* COLOR_MAGENTA */ + { 300, 50, 100}, /* COLOR_CYAN */ + { 0, 50, 100}, /* COLOR_WHITE */ }; +/* *INDENT-ON* */ #ifdef NCURSES_EXT_FUNCS static int default_fg(void) { - return (SP->_default_fg >= 0) ? SP->_default_fg : COLOR_WHITE; + return (SP->_default_fg >= 0) ? SP->_default_fg : COLOR_WHITE; } static int default_bg(void) { - return (SP->_default_bg >= 0) ? SP->_default_bg : COLOR_BLACK; + return (SP->_default_bg >= 0) ? SP->_default_bg : COLOR_BLACK; } #else #define default_fg() COLOR_WHITE @@ -106,127 +109,125 @@ default_bg(void) * to maintain compatibility with a pre-ANSI scheme. The same scheme is * also used in the FreeBSD syscons. */ -static int toggled_colors(int c) +static int +toggled_colors(int c) { if (c < 16) { static const int table[] = - { 0, 4, 2, 6, 1, 5, 3, 7, - 8, 12, 10, 14, 9, 13, 11, 15}; + {0, 4, 2, 6, 1, 5, 3, 7, + 8, 12, 10, 14, 9, 13, 11, 15}; c = table[c]; } return c; } -static void set_background_color(int bg, int (*outc)(int)) +static void +set_background_color(int bg, int (*outc) (int)) { - if (set_a_background) - { - TPUTS_TRACE("set_a_background"); - tputs(tparm(set_a_background, bg), 1, outc); - } - else - { - TPUTS_TRACE("set_background"); - tputs(tparm(set_background, toggled_colors(bg)), 1, outc); - } + if (set_a_background) { + TPUTS_TRACE("set_a_background"); + tputs(tparm(set_a_background, bg), 1, outc); + } else { + TPUTS_TRACE("set_background"); + tputs(tparm(set_background, toggled_colors(bg)), 1, outc); + } } -static void set_foreground_color(int fg, int (*outc)(int)) +static void +set_foreground_color(int fg, int (*outc) (int)) { - if (set_a_foreground) - { - TPUTS_TRACE("set_a_foreground"); - tputs(tparm(set_a_foreground, fg), 1, outc); - } - else - { - TPUTS_TRACE("set_foreground"); - tputs(tparm(set_foreground, toggled_colors(fg)), 1, outc); - } + if (set_a_foreground) { + TPUTS_TRACE("set_a_foreground"); + tputs(tparm(set_a_foreground, fg), 1, outc); + } else { + TPUTS_TRACE("set_foreground"); + tputs(tparm(set_foreground, toggled_colors(fg)), 1, outc); + } } -static bool set_original_colors(void) +static bool +set_original_colors(void) { - if (orig_pair != 0) { - TPUTS_TRACE("orig_pair"); - putp(orig_pair); - return TRUE; - } - else if (orig_colors != NULL) - { - TPUTS_TRACE("orig_colors"); - putp(orig_colors); - return TRUE; - } - return FALSE; + if (orig_pair != 0) { + TPUTS_TRACE("orig_pair"); + putp(orig_pair); + return TRUE; + } else if (orig_colors != NULL) { + TPUTS_TRACE("orig_colors"); + putp(orig_colors); + return TRUE; + } + return FALSE; } -int start_color(void) +int +start_color(void) { - int n; - const color_t *tp; + int n; + const color_t *tp; - T((T_CALLED("start_color()"))); + T((T_CALLED("start_color()"))); - if (set_original_colors() != TRUE) - { - set_foreground_color(default_fg(), _nc_outch); - set_background_color(default_bg(), _nc_outch); - } + if (set_original_colors() != TRUE) { + set_foreground_color(default_fg(), _nc_outch); + set_background_color(default_bg(), _nc_outch); + } - if (max_pairs != -1) - COLOR_PAIRS = SP->_pair_count = max_pairs; - else - returnCode(ERR); - if ((SP->_color_pairs = typeCalloc(unsigned short, max_pairs)) == 0) - returnCode(ERR); - SP->_color_pairs[0] = PAIR_OF(default_fg(), default_bg()); - if (max_colors != -1) - COLORS = SP->_color_count = max_colors; - else - returnCode(ERR); - SP->_coloron = 1; - - if ((SP->_color_table = typeMalloc(color_t, COLORS)) == 0) - returnCode(ERR); - tp = (hue_lightness_saturation) ? hls_palette : cga_palette; - for (n = 0; n < COLORS; n++) { - if (n < 8) { - SP->_color_table[n] = tp[n]; - } else { - SP->_color_table[n] = tp[n % 8]; - if (hue_lightness_saturation) { - SP->_color_table[n].green = 100; - } else { - if (SP->_color_table[n].red) - SP->_color_table[n].red = 1000; - if (SP->_color_table[n].green) - SP->_color_table[n].green = 1000; - if (SP->_color_table[n].blue) - SP->_color_table[n].blue = 1000; - } - } + if (VALID_NUMERIC(max_pairs)) + COLOR_PAIRS = SP->_pair_count = max_pairs; + else + returnCode(ERR); + if ((SP->_color_pairs = typeCalloc(unsigned short, max_pairs)) == 0) + returnCode(ERR); + SP->_color_pairs[0] = PAIR_OF(default_fg(), default_bg()); + if (VALID_NUMERIC(max_colors)) + COLORS = SP->_color_count = max_colors; + else + returnCode(ERR); + SP->_coloron = 1; + + if ((SP->_color_table = typeMalloc(color_t, COLORS)) == 0) + returnCode(ERR); + tp = (hue_lightness_saturation) ? hls_palette : cga_palette; + for (n = 0; n < COLORS; n++) { + if (n < 8) { + SP->_color_table[n] = tp[n]; + } else { + SP->_color_table[n] = tp[n % 8]; + if (hue_lightness_saturation) { + SP->_color_table[n].green = 100; + } else { + if (SP->_color_table[n].red) + SP->_color_table[n].red = 1000; + if (SP->_color_table[n].green) + SP->_color_table[n].green = 1000; + if (SP->_color_table[n].blue) + SP->_color_table[n].blue = 1000; + } } + } - T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); + T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); - returnCode(OK); + returnCode(OK); } /* This function was originally written by Daniel Weaver <danw@znyx.com> */ -static void rgb2hls(short r, short g, short b, short *h, short *l, short *s) +static void +rgb2hls(short r, short g, short b, short *h, short *l, short *s) /* convert RGB to HLS system */ { short min, max, t; - if ((min = g < r ? g : r) > b) min = b; - if ((max = g > r ? g : r) < b) max = b; + if ((min = g < r ? g : r) > b) + min = b; + if ((max = g > r ? g : r) < b) + max = b; /* calculate lightness */ *l = (min + max) / 20; - if (min == max) /* black, white and all shades of gray */ - { + if (min == max) { /* black, white and all shades of gray */ *h = 0; *s = 0; return; @@ -235,16 +236,16 @@ static void rgb2hls(short r, short g, short b, short *h, short *l, short *s) /* calculate saturation */ if (*l < 50) *s = ((max - min) * 100) / (max + min); - else *s = ((max - min) * 100) / (2000 - max - min); + else + *s = ((max - min) * 100) / (2000 - max - min); /* calculate hue */ if (r == max) t = 120 + ((g - b) * 60) / (max - min); + else if (g == max) + t = 240 + ((b - r) * 60) / (max - min); else - if (g == max) - t = 240 + ((b - r) * 60) / (max - min); - else - t = 360 + ((r - g) * 60) / (max - min); + t = 360 + ((r - g) * 60) / (max - min); *h = t % 360; } @@ -253,181 +254,180 @@ static void rgb2hls(short r, short g, short b, short *h, short *l, short *s) * Extension (1997/1/18) - Allow negative f/b values to set default color * values. */ -int init_pair(short pair, short f, short b) +int +init_pair(short pair, short f, short b) { - unsigned result; + unsigned result; - T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b)); + T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b)); - if ((pair < 1) || (pair >= COLOR_PAIRS)) - returnCode(ERR); + if ((pair < 1) || (pair >= COLOR_PAIRS)) + returnCode(ERR); #ifdef NCURSES_EXT_FUNCS - if (SP->_default_color) - { - if (f < 0) - f = C_MASK; - if (b < 0) - b = C_MASK; - if (f >= COLORS && f != C_MASK) - returnCode(ERR); - if (b >= COLORS && b != C_MASK) - returnCode(ERR); - } - else + if (SP->_default_color) { + if (f < 0) + f = C_MASK; + if (b < 0) + b = C_MASK; + if (f >= COLORS && f != C_MASK) + returnCode(ERR); + if (b >= COLORS && b != C_MASK) + returnCode(ERR); + } else #endif if ((f < 0) || (f >= COLORS) - || (b < 0) || (b >= COLORS)) - returnCode(ERR); - - /* - * When a pair's content is changed, replace its colors (if pair was - * initialized before a screen update is performed replacing original - * pair colors with the new ones). - */ - result = PAIR_OF(f,b); - if (SP->_color_pairs[pair] != 0 - && SP->_color_pairs[pair] != result) { - int y, x; - attr_t z = COLOR_PAIR(pair); - - for (y = 0; y <= curscr->_maxy; y++) { - struct ldat *ptr = &(curscr->_line[y]); - bool changed = FALSE; - for (x = 0; x <= curscr->_maxx; x++) { - if ((ptr->text[x] & A_COLOR) == z) { - /* Set the old cell to zero to ensure it will be - updated on the next doupdate() */ - ptr->text[x] = 0; - CHANGED_CELL(ptr,x); - changed = TRUE; - } + || (b < 0) || (b >= COLORS)) + returnCode(ERR); + + /* + * When a pair's content is changed, replace its colors (if pair was + * initialized before a screen update is performed replacing original + * pair colors with the new ones). + */ + result = PAIR_OF(f, b); + if (SP->_color_pairs[pair] != 0 + && SP->_color_pairs[pair] != result) { + int y, x; + attr_t z = COLOR_PAIR(pair); + + for (y = 0; y <= curscr->_maxy; y++) { + struct ldat *ptr = &(curscr->_line[y]); + bool changed = FALSE; + for (x = 0; x <= curscr->_maxx; x++) { + if ((ptr->text[x] & A_COLOR) == z) { + /* Set the old cell to zero to ensure it will be + updated on the next doupdate() */ + ptr->text[x] = 0; + CHANGED_CELL(ptr, x); + changed = TRUE; } - if (changed) - _nc_make_oldhash(y); } + if (changed) + _nc_make_oldhash(y); } - SP->_color_pairs[pair] = result; - - if (initialize_pair) - { - const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; - - T(("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)", - pair, - tp[f].red, tp[f].green, tp[f].blue, - tp[b].red, tp[b].green, tp[b].blue)); - - if (initialize_pair) - { - TPUTS_TRACE("initialize_pair"); - putp(tparm(initialize_pair, - pair, - tp[f].red, tp[f].green, tp[f].blue, - tp[b].red, tp[b].green, tp[b].blue)); - } + } + SP->_color_pairs[pair] = result; + + if (initialize_pair) { + const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; + + T(("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)", + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); + + if (initialize_pair) { + TPUTS_TRACE("initialize_pair"); + putp(tparm(initialize_pair, + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); } + } - returnCode(OK); + returnCode(OK); } -int init_color(short color, short r, short g, short b) +int +init_color(short color, short r, short g, short b) { - T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); - - if (initialize_color == NULL) - returnCode(ERR); - - if (color < 0 || color >= COLORS) - returnCode(ERR); - if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) - returnCode(ERR); - - if (hue_lightness_saturation) - rgb2hls(r, g, b, - &SP->_color_table[color].red, - &SP->_color_table[color].green, - &SP->_color_table[color].blue); - else - { - SP->_color_table[color].red = r; - SP->_color_table[color].green = g; - SP->_color_table[color].blue = b; - } + T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); - if (initialize_color) - { - TPUTS_TRACE("initialize_color"); - putp(tparm(initialize_color, color, r, g, b)); - } - returnCode(OK); + if (initialize_color == NULL) + returnCode(ERR); + + if (color < 0 || color >= COLORS) + returnCode(ERR); + if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) + returnCode(ERR); + + if (hue_lightness_saturation) + rgb2hls(r, g, b, + &SP->_color_table[color].red, + &SP->_color_table[color].green, + &SP->_color_table[color].blue); + else { + SP->_color_table[color].red = r; + SP->_color_table[color].green = g; + SP->_color_table[color].blue = b; + } + + if (initialize_color) { + TPUTS_TRACE("initialize_color"); + putp(tparm(initialize_color, color, r, g, b)); + } + returnCode(OK); } -bool can_change_color(void) +bool +can_change_color(void) { - T((T_CALLED("can_change_color()"))); - returnCode ((can_change != 0) ? TRUE : FALSE); + T((T_CALLED("can_change_color()"))); + returnCode((can_change != 0) ? TRUE : FALSE); } -bool has_colors(void) +bool +has_colors(void) { - T((T_CALLED("has_colors()"))); - returnCode (((max_colors != -1) && (max_pairs != -1) - && (((set_foreground != NULL) - && (set_background != NULL)) - || ((set_a_foreground != NULL) - && (set_a_background != NULL)) - || set_color_pair)) ? TRUE : FALSE); + T((T_CALLED("has_colors()"))); + returnCode((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs) + && (((set_foreground != NULL) + && (set_background != NULL)) + || ((set_a_foreground != NULL) + && (set_a_background != NULL)) + || set_color_pair)) ? TRUE : FALSE); } -int color_content(short color, short *r, short *g, short *b) +int +color_content(short color, short *r, short *g, short *b) { T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b)); if (color < 0 || color >= COLORS) returnCode(ERR); - if (r) *r = SP->_color_table[color].red; - if (g) *g = SP->_color_table[color].green; - if (b) *b = SP->_color_table[color].blue; + if (r) + *r = SP->_color_table[color].red; + if (g) + *g = SP->_color_table[color].green; + if (b) + *b = SP->_color_table[color].blue; returnCode(OK); } -int pair_content(short pair, short *f, short *b) +int +pair_content(short pair, short *f, short *b) { - T((T_CALLED("pair_content(%d,%p,%p)"), pair, f, b)); + T((T_CALLED("pair_content(%d,%p,%p)"), pair, f, b)); - if ((pair < 0) || (pair >= COLOR_PAIRS)) - returnCode(ERR); - if (f) *f = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); - if (b) *b = (SP->_color_pairs[pair] & C_MASK); + if ((pair < 0) || (pair >= COLOR_PAIRS)) + returnCode(ERR); + if (f) + *f = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); + if (b) + *b = (SP->_color_pairs[pair] & C_MASK); - returnCode(OK); + returnCode(OK); } -void _nc_do_color(int pair, bool reverse, int (*outc)(int)) +void +_nc_do_color(int pair, bool reverse, int (*outc) (int)) { short fg, bg; - if (pair == 0) - { + if (pair == 0) { if ( #ifdef NCURSES_EXT_FUNCS !SP->_default_color || #endif - !set_original_colors()) - { + !set_original_colors()) { set_foreground_color(default_fg(), outc); set_background_color(default_bg(), outc); } - } - else - { - if (set_color_pair) - { + } else { + if (set_color_pair) { TPUTS_TRACE("set_color_pair"); tputs(tparm(set_color_pair, pair), 1, outc); - } - else - { + } else { pair_content(pair, &fg, &bg); if (reverse) { short xx = fg; @@ -437,22 +437,18 @@ void _nc_do_color(int pair, bool reverse, int (*outc)(int)) T(("setting colors: pair = %d, fg = %d, bg = %d", pair, fg, bg)); - if (fg == C_MASK || bg == C_MASK) - { - if (set_original_colors() != TRUE) - { - if (fg == C_MASK) - set_foreground_color(default_fg(), outc); - if (bg == C_MASK) - set_background_color(default_bg(), outc); + if (fg == C_MASK || bg == C_MASK) { + if (set_original_colors() != TRUE) { + if (fg == C_MASK) + set_foreground_color(default_fg(), outc); + if (bg == C_MASK) + set_background_color(default_bg(), outc); } } - if (fg != C_MASK) - { + if (fg != C_MASK) { set_foreground_color(fg, outc); } - if (bg != C_MASK) - { + if (bg != C_MASK) { set_background_color(bg, outc); } } diff --git a/lib/libcurses/base/lib_newterm.c b/lib/libcurses/base/lib_newterm.c index 7f6632c4cc8..3360ebcd704 100644 --- a/lib/libcurses/base/lib_newterm.c +++ b/lib/libcurses/base/lib_newterm.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_newterm.c,v 1.5 1999/08/15 11:40:55 millert Exp $ */ +/* $OpenBSD: lib_newterm.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_newterm.c ** @@ -48,11 +46,12 @@ #define _POSIX_SOURCE #endif -#include <term.h> /* clear_screen, cup & friends, cur_term */ +#include <term.h> /* clear_screen, cup & friends, cur_term */ +#include <tic.h> -MODULE_ID("$From: lib_newterm.c,v 1.41 1999/07/24 20:07:48 tom Exp $") +MODULE_ID("$From: lib_newterm.c,v 1.43 2000/01/01 16:56:20 tom Exp $") -#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ +#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 #endif @@ -64,20 +63,21 @@ MODULE_ID("$From: lib_newterm.c,v 1.41 1999/07/24 20:07:48 tom Exp $") * The newterm function also initializes terminal settings, and since initscr * is supposed to behave as if it calls newterm, we do it here. */ -static inline int _nc_initscr(void) +static inline int +_nc_initscr(void) { - /* for extended XPG4 conformance requires cbreak() at this point */ - /* (SVr4 curses does this anyway) */ - cbreak(); + /* for extended XPG4 conformance requires cbreak() at this point */ + /* (SVr4 curses does this anyway) */ + cbreak(); #ifdef TERMIOS - cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL); - cur_term->Nttyb.c_iflag &= ~(ICRNL|INLCR|IGNCR); - cur_term->Nttyb.c_oflag &= ~(ONLCR); + cur_term->Nttyb.c_lflag &= ~(ECHO | ECHONL); + cur_term->Nttyb.c_iflag &= ~(ICRNL | INLCR | IGNCR); + cur_term->Nttyb.c_oflag &= ~(ONLCR); #else - cur_term->Nttyb.sg_flags &= ~(ECHO|CRMOD); + cur_term->Nttyb.sg_flags &= ~(ECHO | CRMOD); #endif - return _nc_set_tty_mode(&cur_term->Nttyb); + return _nc_set_tty_mode(&cur_term->Nttyb); } /* @@ -88,121 +88,122 @@ static inline int _nc_initscr(void) */ static int filter_mode = FALSE; -void filter(void) +void +filter(void) { filter_mode = TRUE; } -SCREEN * newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) +SCREEN * +newterm(NCURSES_CONST char *name, FILE * ofp, FILE * ifp) { -int errret; -int slk_format = _nc_slk_format; -SCREEN* current; + int errret; + int slk_format = _nc_slk_format; + SCREEN *current; #ifdef TRACE -int t = _nc_getenv_num("NCURSES_TRACE"); + int t = _nc_getenv_num("NCURSES_TRACE"); - if (t >= 0) - trace(t); + if (t >= 0) + trace(t); #endif - T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); + T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); - /* this loads the capability entry, then sets LINES and COLS */ - if (setupterm(name, fileno(ofp), &errret) == ERR) - return 0; + /* this loads the capability entry, then sets LINES and COLS */ + if (setupterm(name, fileno(ofp), &errret) == ERR) + return 0; - /* implement filter mode */ - if (filter_mode) { - LINES = 1; + /* implement filter mode */ + if (filter_mode) { + LINES = 1; - if (init_tabs != -1) - TABSIZE = init_tabs; - else - TABSIZE = 8; + if (VALID_NUMERIC(init_tabs)) + TABSIZE = init_tabs; + else + TABSIZE = 8; - T(("TABSIZE = %d", TABSIZE)); + T(("TABSIZE = %d", TABSIZE)); - clear_screen = 0; - cursor_down = parm_down_cursor = 0; - cursor_address = 0; - cursor_up = parm_up_cursor = 0; - row_address = 0; + clear_screen = 0; + cursor_down = parm_down_cursor = 0; + cursor_address = 0; + cursor_up = parm_up_cursor = 0; + row_address = 0; - cursor_home = carriage_return; - } + cursor_home = carriage_return; + } - /* If we must simulate soft labels, grab off the line to be used. - We assume that we must simulate, if it is none of the standard - formats (4-4 or 3-2-3) for which there may be some hardware - support. */ - if (num_labels <= 0 || !SLK_STDFMT(slk_format)) - if (slk_format) - { - if (ERR==_nc_ripoffline(-SLK_LINES(slk_format), - _nc_slk_initialize)) - return 0; - } - /* this actually allocates the screen structure, and saves the - * original terminal settings. - */ - current = SP; - _nc_set_screen(0); - if (_nc_setupscreen(LINES, COLS, ofp) == ERR) { - _nc_set_screen(current); + /* If we must simulate soft labels, grab off the line to be used. + We assume that we must simulate, if it is none of the standard + formats (4-4 or 3-2-3) for which there may be some hardware + support. */ + if (num_labels <= 0 || !SLK_STDFMT(slk_format)) + if (slk_format) { + if (ERR == _nc_ripoffline(-SLK_LINES(slk_format), + _nc_slk_initialize)) return 0; } - - /* if the terminal type has real soft labels, set those up */ - if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) - _nc_slk_initialize(stdscr, COLS); - - SP->_ifd = fileno(ifp); - SP->_checkfd = fileno(ifp); - typeahead(fileno(ifp)); + /* this actually allocates the screen structure, and saves the + * original terminal settings. + */ + current = SP; + _nc_set_screen(0); + if (_nc_setupscreen(LINES, COLS, ofp) == ERR) { + _nc_set_screen(current); + return 0; + } + + /* if the terminal type has real soft labels, set those up */ + if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) + _nc_slk_initialize(stdscr, COLS); + + SP->_ifd = fileno(ifp); + SP->_checkfd = fileno(ifp); + typeahead(fileno(ifp)); #ifdef TERMIOS - SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && - !(cur_term->Ottyb.c_iflag & ISTRIP)); + SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && + !(cur_term->Ottyb.c_iflag & ISTRIP)); #else - SP->_use_meta = FALSE; + SP->_use_meta = FALSE; #endif - SP->_endwin = FALSE; - - /* Check whether we can optimize scrolling under dumb terminals in case - * we do not have any of these capabilities, scrolling optimization - * will be useless. - */ - SP->_scrolling = ((scroll_forward && scroll_reverse) || - ((parm_rindex || parm_insert_line || insert_line) && - (parm_index || parm_delete_line || delete_line))); - - baudrate(); /* sets a field in the SP structure */ - - SP->_keytry = 0; - - /* - * Check for mismatched graphic-rendition capabilities. Most SVr4 - * terminfo trees contain entries that have rmul or rmso equated to - * sgr0 (Solaris curses copes with those entries). We do this only for - * curses, since many termcap applications assume that smso/rmso and - * smul/rmul are paired, and will not function properly if we remove - * rmso or rmul. Curses applications shouldn't be looking at this - * detail. - */ + SP->_endwin = FALSE; + + /* Check whether we can optimize scrolling under dumb terminals in case + * we do not have any of these capabilities, scrolling optimization + * will be useless. + */ + SP->_scrolling = ((scroll_forward && scroll_reverse) || + ((parm_rindex || parm_insert_line || insert_line) && + (parm_index || parm_delete_line || delete_line))); + + baudrate(); /* sets a field in the SP structure */ + + SP->_keytry = 0; + + /* + * Check for mismatched graphic-rendition capabilities. Most SVr4 + * terminfo trees contain entries that have rmul or rmso equated to + * sgr0 (Solaris curses copes with those entries). We do this only for + * curses, since many termcap applications assume that smso/rmso and + * smul/rmul are paired, and will not function properly if we remove + * rmso or rmul. Curses applications shouldn't be looking at this + * detail. + */ #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) - SP->_use_rmso = SGR0_TEST(exit_standout_mode); - SP->_use_rmul = SGR0_TEST(exit_underline_mode); + SP->_use_rmso = SGR0_TEST(exit_standout_mode); + SP->_use_rmul = SGR0_TEST(exit_underline_mode); - /* compute movement costs so we can do better move optimization */ - _nc_mvcur_init(); + /* compute movement costs so we can do better move optimization */ + _nc_mvcur_init(); - /* initialize terminal to a sane state */ - _nc_screen_init(); + /* initialize terminal to a sane state */ + _nc_screen_init(); - /* Initialize the terminal line settings. */ - _nc_initscr(); + /* Initialize the terminal line settings. */ + _nc_initscr(); - _nc_signal_handler(TRUE); + _nc_signal_handler(TRUE); - T((T_RETURN("%p"), SP)); - return(SP); + T((T_RETURN("%p"), SP)); + return (SP); } diff --git a/lib/libcurses/base/lib_set_term.c b/lib/libcurses/base/lib_set_term.c index ab67435081b..67d84e53e0d 100644 --- a/lib/libcurses/base/lib_set_term.c +++ b/lib/libcurses/base/lib_set_term.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_set_term.c,v 1.5 1999/11/28 17:49:53 millert Exp $ */ +/* $OpenBSD: lib_set_term.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,280 +42,299 @@ #include <curses.priv.h> -#include <term.h> /* cur_term */ +#include <term.h> /* cur_term */ +#include <tic.h> -MODULE_ID("$From: lib_set_term.c,v 1.47 1999/11/14 00:14:39 tom Exp $") +MODULE_ID("$From: lib_set_term.c,v 1.49 2000/01/01 16:44:29 tom Exp $") -SCREEN * set_term(SCREEN *screenp) +SCREEN * +set_term(SCREEN * screenp) { -SCREEN *oldSP; + SCREEN *oldSP; - T((T_CALLED("set_term(%p)"), screenp)); + T((T_CALLED("set_term(%p)"), screenp)); - oldSP = SP; - _nc_set_screen(screenp); + oldSP = SP; + _nc_set_screen(screenp); - set_curterm(SP->_term); - curscr = SP->_curscr; - newscr = SP->_newscr; - stdscr = SP->_stdscr; - COLORS = SP->_color_count; - COLOR_PAIRS = SP->_pair_count; - memcpy(acs_map, SP->_acs_map, sizeof(chtype)*ACS_LEN); + set_curterm(SP->_term); + curscr = SP->_curscr; + newscr = SP->_newscr; + stdscr = SP->_stdscr; + COLORS = SP->_color_count; + COLOR_PAIRS = SP->_pair_count; + memcpy(acs_map, SP->_acs_map, sizeof(chtype) * ACS_LEN); - T((T_RETURN("%p"), oldSP)); - return(oldSP); + T((T_RETURN("%p"), oldSP)); + return (oldSP); } -static void _nc_free_keytry(struct tries *kt) +static void +_nc_free_keytry(struct tries *kt) { - if (kt != 0) { - _nc_free_keytry(kt->child); - _nc_free_keytry(kt->sibling); - free(kt); - } + if (kt != 0) { + _nc_free_keytry(kt->child); + _nc_free_keytry(kt->sibling); + free(kt); + } } /* * Free the storage associated with the given SCREEN sp. */ -void delscreen(SCREEN *sp) +void +delscreen(SCREEN * sp) { - SCREEN **scan = &_nc_screen_chain; - - T((T_CALLED("delscreen(%p)"), sp)); - - while(*scan) - { - if (*scan == sp) - { - *scan = sp->_next_screen; - break; - } - scan = &(*scan)->_next_screen; - } - - _nc_freewin(sp->_curscr); - _nc_freewin(sp->_newscr); - _nc_freewin(sp->_stdscr); - _nc_free_keytry(sp->_keytry); - _nc_free_keytry(sp->_key_ok); - - FreeIfNeeded(sp->_color_table); - FreeIfNeeded(sp->_color_pairs); + SCREEN **scan = &_nc_screen_chain; - FreeIfNeeded(sp->oldhash); - FreeIfNeeded(sp->newhash); + T((T_CALLED("delscreen(%p)"), sp)); - del_curterm(sp->_term); - - free(sp); - - /* - * If this was the current screen, reset everything that the - * application might try to use (except cur_term, which may have - * multiple references in different screens). - */ - if (sp == SP) { - curscr = 0; - newscr = 0; - stdscr = 0; - COLORS = 0; - COLOR_PAIRS = 0; - _nc_set_screen(0); + while (*scan) { + if (*scan == sp) { + *scan = sp->_next_screen; + break; } - returnVoid; + scan = &(*scan)->_next_screen; + } + + _nc_freewin(sp->_curscr); + _nc_freewin(sp->_newscr); + _nc_freewin(sp->_stdscr); + _nc_free_keytry(sp->_keytry); + _nc_free_keytry(sp->_key_ok); + + FreeIfNeeded(sp->_color_table); + FreeIfNeeded(sp->_color_pairs); + + FreeIfNeeded(sp->oldhash); + FreeIfNeeded(sp->newhash); + + del_curterm(sp->_term); + + free(sp); + + /* + * If this was the current screen, reset everything that the + * application might try to use (except cur_term, which may have + * multiple references in different screens). + */ + if (sp == SP) { + curscr = 0; + newscr = 0; + stdscr = 0; + COLORS = 0; + COLOR_PAIRS = 0; + _nc_set_screen(0); + } + returnVoid; } static ripoff_t rippedoff[5]; static ripoff_t *rsp = rippedoff; #define N_RIPS SIZEOF(rippedoff) -static bool no_mouse_event (SCREEN *sp GCC_UNUSED) { return FALSE; } -static bool no_mouse_inline(SCREEN *sp GCC_UNUSED) { return FALSE; } -static bool no_mouse_parse (int code GCC_UNUSED) { return TRUE; } -static void no_mouse_resume(SCREEN *sp GCC_UNUSED) { } -static void no_mouse_wrap (SCREEN *sp GCC_UNUSED) { } +static bool +no_mouse_event(SCREEN * sp GCC_UNUSED) +{ + return FALSE; +} +static bool +no_mouse_inline(SCREEN * sp GCC_UNUSED) +{ + return FALSE; +} +static bool +no_mouse_parse(int code GCC_UNUSED) +{ + return TRUE; +} +static void +no_mouse_resume(SCREEN * sp GCC_UNUSED) +{ +} +static void +no_mouse_wrap(SCREEN * sp GCC_UNUSED) +{ +} -int _nc_setupscreen(short slines, short const scolumns, FILE *output) +int +_nc_setupscreen(short slines, short const scolumns, FILE * output) /* OS-independent screen initializations */ { -int bottom_stolen = 0; -size_t i; - - assert(SP==0); /* has been reset in newterm() ! */ - if (!_nc_alloc_screen()) - return ERR; - - SP->_next_screen = _nc_screen_chain; - _nc_screen_chain = SP; - - _nc_set_buffer(output, TRUE); - SP->_term = cur_term; - SP->_lines = slines; - SP->_lines_avail = slines; - SP->_columns = scolumns; - SP->_cursrow = -1; - SP->_curscol = -1; - SP->_nl = TRUE; - SP->_raw = FALSE; - SP->_cbreak = 0; - SP->_echo = TRUE; - SP->_fifohead = -1; - SP->_endwin = TRUE; - SP->_ofp = output; - SP->_cursor = -1; /* cannot know real cursor shape */ + int bottom_stolen = 0; + size_t i; + + assert(SP == 0); /* has been reset in newterm() ! */ + if (!_nc_alloc_screen()) + return ERR; + + SP->_next_screen = _nc_screen_chain; + _nc_screen_chain = SP; + + _nc_set_buffer(output, TRUE); + SP->_term = cur_term; + SP->_lines = slines; + SP->_lines_avail = slines; + SP->_columns = scolumns; + SP->_cursrow = -1; + SP->_curscol = -1; + SP->_nl = TRUE; + SP->_raw = FALSE; + SP->_cbreak = 0; + SP->_echo = TRUE; + SP->_fifohead = -1; + SP->_endwin = TRUE; + SP->_ofp = output; + SP->_cursor = -1; /* cannot know real cursor shape */ #ifdef NCURSES_NO_PADDING - SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0; + SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0; #endif #ifdef NCURSES_EXT_FUNCS - SP->_default_fg = COLOR_WHITE; - SP->_default_bg = COLOR_BLACK; + SP->_default_fg = COLOR_WHITE; + SP->_default_bg = COLOR_BLACK; #endif - SP->_maxclick = DEFAULT_MAXCLICK; - SP->_mouse_event = no_mouse_event; - SP->_mouse_inline = no_mouse_inline; - SP->_mouse_parse = no_mouse_parse; - SP->_mouse_resume = no_mouse_resume; - SP->_mouse_wrap = no_mouse_wrap; - SP->_mouse_fd = -1; - - /* initialize the panel hooks */ - SP->_panelHook.top_panel = (struct panel*)0; - SP->_panelHook.bottom_panel = (struct panel*)0; - SP->_panelHook.stdscr_pseudo_panel = (struct panel*)0; - + SP->_maxclick = DEFAULT_MAXCLICK; + SP->_mouse_event = no_mouse_event; + SP->_mouse_inline = no_mouse_inline; + SP->_mouse_parse = no_mouse_parse; + SP->_mouse_resume = no_mouse_resume; + SP->_mouse_wrap = no_mouse_wrap; + SP->_mouse_fd = -1; + + /* initialize the panel hooks */ + SP->_panelHook.top_panel = (struct panel *) 0; + SP->_panelHook.bottom_panel = (struct panel *) 0; + SP->_panelHook.stdscr_pseudo_panel = (struct panel *) 0; + + /* + * If we've no magic cookie support, we suppress attributes that xmc + * would affect, i.e., the attributes that affect the rendition of a + * space. Note that this impacts the alternate character set mapping + * as well. + */ + if (magic_cookie_glitch > 0) { + + SP->_xmc_triggers = termattrs() & ( + A_ALTCHARSET | + A_BLINK | + A_BOLD | + A_REVERSE | + A_STANDOUT | + A_UNDERLINE + ); + SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~ (A_BOLD); + + T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress))); +#if USE_XMC_SUPPORT /* - * If we've no magic cookie support, we suppress attributes that xmc - * would affect, i.e., the attributes that affect the rendition of a - * space. Note that this impacts the alternate character set mapping - * as well. + * To keep this simple, suppress all of the optimization hooks + * except for clear_screen and the cursor addressing. */ - if (magic_cookie_glitch > 0) { - - SP->_xmc_triggers = termattrs() & ( - A_ALTCHARSET | - A_BLINK | - A_BOLD | - A_REVERSE | - A_STANDOUT | - A_UNDERLINE - ); - SP->_xmc_suppress = SP->_xmc_triggers & (chtype)~(A_BOLD); - - T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress))); -#if USE_XMC_SUPPORT - /* - * To keep this simple, suppress all of the optimization hooks - * except for clear_screen and the cursor addressing. - */ - clr_eol = 0; - clr_eos = 0; - set_attributes = 0; + clr_eol = 0; + clr_eos = 0; + set_attributes = 0; #else - magic_cookie_glitch = -1; - acs_chars = 0; + magic_cookie_glitch = ABSENT_NUMERIC; + acs_chars = 0; #endif - } - _nc_init_acs(); - memcpy(SP->_acs_map, acs_map, sizeof(chtype)*ACS_LEN); + } + _nc_init_acs(); + memcpy(SP->_acs_map, acs_map, sizeof(chtype) * ACS_LEN); - _nc_idcok = TRUE; - _nc_idlok = FALSE; + _nc_idcok = TRUE; + _nc_idlok = FALSE; - _nc_windows = 0; /* no windows yet */ + _nc_windows = 0; /* no windows yet */ - SP->oldhash = 0; - SP->newhash = 0; + SP->oldhash = 0; + SP->newhash = 0; - T(("creating newscr")); - if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) - return ERR; + T(("creating newscr")); + if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) + return ERR; - T(("creating curscr")); - if ((curscr = newwin(slines, scolumns, 0, 0)) == 0) - return ERR; + T(("creating curscr")); + if ((curscr = newwin(slines, scolumns, 0, 0)) == 0) + return ERR; - SP->_newscr = newscr; - SP->_curscr = curscr; + SP->_newscr = newscr; + SP->_curscr = curscr; #if USE_SIZECHANGE - SP->_resize = resizeterm; + SP->_resize = resizeterm; #endif - newscr->_clear = TRUE; - curscr->_clear = FALSE; - - for (i=0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, i++) { - if (rsp->hook) { - WINDOW *w; - int count = (rsp->line < 0) ? -rsp->line : rsp->line; - - if (rsp->line < 0) { - w = newwin(count,scolumns,SP->_lines_avail - count,0); - if (w) { - rsp->w = w; - rsp->hook(w, scolumns); - bottom_stolen += count; - } - else + newscr->_clear = TRUE; + curscr->_clear = FALSE; + + for (i = 0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, i++) { + if (rsp->hook) { + WINDOW *w; + int count = (rsp->line < 0) ? -rsp->line : rsp->line; + + if (rsp->line < 0) { + w = newwin(count, scolumns, SP->_lines_avail - count, 0); + if (w) { + rsp->w = w; + rsp->hook(w, scolumns); + bottom_stolen += count; + } else return ERR; - } else { - w = newwin(count,scolumns, 0, 0); - if (w) { - rsp->w = w; - rsp->hook(w, scolumns); - SP->_topstolen += count; - } - else + } else { + w = newwin(count, scolumns, 0, 0); + if (w) { + rsp->w = w; + rsp->hook(w, scolumns); + SP->_topstolen += count; + } else return ERR; - } - SP->_lines_avail -= count; - } - rsp->line = 0; + } + SP->_lines_avail -= count; } - /* reset the stack */ - rsp = rippedoff; + rsp->line = 0; + } + /* reset the stack */ + rsp = rippedoff; - T(("creating stdscr")); - assert ((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines); - if ((stdscr = newwin(LINES = SP->_lines_avail, scolumns, 0, 0)) == 0) - return ERR; - SP->_stdscr = stdscr; + T(("creating stdscr")); + assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines); + if ((stdscr = newwin(LINES = SP->_lines_avail, scolumns, 0, 0)) == 0) + return ERR; + SP->_stdscr = stdscr; - def_shell_mode(); - def_prog_mode(); + def_shell_mode(); + def_prog_mode(); - return OK; + return OK; } /* The internal implementation interprets line as the number of lines to rip off from the top or bottom. */ int -_nc_ripoffline(int line, int (*init)(WINDOW *,int)) +_nc_ripoffline(int line, int (*init) (WINDOW *, int)) { if (line == 0) - return(OK); + return (OK); if (rsp >= rippedoff + N_RIPS) - return(ERR); + return (ERR); rsp->line = line; rsp->hook = init; - rsp->w = 0; + rsp->w = 0; rsp++; - return(OK); + return (OK); } int -ripoffline(int line, int (*init)(WINDOW *, int)) +ripoffline(int line, int (*init) (WINDOW *, int)) { T((T_CALLED("ripoffline(%d,%p)"), line, init)); if (line == 0) returnCode(OK); - returnCode(_nc_ripoffline ((line<0) ? -1 : 1, init)); + returnCode(_nc_ripoffline((line < 0) ? -1 : 1, init)); } |