summaryrefslogtreecommitdiff
path: root/lib/libcurses
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-01-02 22:06:52 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-01-02 22:06:52 +0000
commitd058cd399506bf5b5e3d43742d30cdabda06a8e7 (patch)
treeb17920dcead3b7816d7cd0f534c3aba3ac561c07 /lib/libcurses
parent4170262b3e51f04453aa1a283175a95e4f9cf41b (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')
-rw-r--r--lib/libcurses/base/lib_color.c504
-rw-r--r--lib/libcurses/base/lib_newterm.c213
-rw-r--r--lib/libcurses/base/lib_set_term.c423
-rw-r--r--lib/libcurses/capdefaults.c95
-rw-r--r--lib/libcurses/curs_scroll.37
-rw-r--r--lib/libcurses/curses.h4
-rw-r--r--lib/libcurses/tinfo/lib_options.c288
-rw-r--r--lib/libcurses/tinfo/lib_setup.c446
-rw-r--r--lib/libcurses/tinfo/lib_termcap.c147
-rw-r--r--lib/libcurses/tinfo/lib_ti.c96
-rw-r--r--lib/libcurses/tinfo/read_entry.c346
-rw-r--r--lib/libcurses/tinfo/write_entry.c654
-rw-r--r--lib/libcurses/tty/lib_mvcur.c642
13 files changed, 1920 insertions, 1945 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));
}
diff --git a/lib/libcurses/capdefaults.c b/lib/libcurses/capdefaults.c
index ee09b013209..4f1ec7e5e42 100644
--- a/lib/libcurses/capdefaults.c
+++ b/lib/libcurses/capdefaults.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * 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 *
@@ -31,58 +31,55 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-/* $OpenBSD: capdefaults.c,v 1.1 1998/07/23 21:17:25 millert Exp $ */
-/* $From: capdefaults.c,v 1.8 1998/07/04 22:31:04 tom Exp $ */
+/* $OpenBSD: capdefaults.c,v 1.2 2000/01/02 22:06:50 millert Exp $ */
+/* $From: capdefaults.c,v 1.12 2000/01/02 02:34:56 tom Exp $ */
- /*
- * Compute obsolete capabilities. The reason this is an include file
- * is that the two places where it's needed want the macros to
- * generate offsets to different structures. See the file Caps for
- * explanations of these conversions.
- *
- * Note: This code is the functional inverse of the first part
- * of postprocess_entry().
- */
- {
- char *sp;
- int capval;
+ /*
+ * Compute obsolete capabilities. The reason this is an include file is
+ * that the two places where it's needed want the macros to generate
+ * offsets to different structures. See the file Caps for explanations of
+ * these conversions.
+ *
+ * Note: This code is the functional inverse of the first part of
+ * postprocess_termcap().
+ */
+{
+ char *sp;
+ int capval;
#define EXTRACT_DELAY(str) (sp = strchr(str, '*'), sp ? atoi(sp+1) : 0)
- /* current (4.4BSD) capabilities marked obsolete */
- if (VALID_STRING(carriage_return)
- && (capval = EXTRACT_DELAY(carriage_return)))
- carriage_return_delay = capval;
- if (VALID_STRING(newline) && (capval = EXTRACT_DELAY(newline)))
- new_line_delay = capval;
+ /* current (4.4BSD) capabilities marked obsolete */
+ if (VALID_STRING(carriage_return)
+ && (capval = EXTRACT_DELAY(carriage_return)))
+ carriage_return_delay = capval;
+ if (VALID_STRING(newline) && (capval = EXTRACT_DELAY(newline)))
+ new_line_delay = capval;
- /* current (4.4BSD) capabilities not obsolete */
- if (!VALID_STRING(termcap_init2) && VALID_STRING(init_3string))
- {
- termcap_init2 = init_3string;
- init_3string = (char *)0;
- }
- if (VALID_STRING(reset_1string)
- && !VALID_STRING(reset_2string)
- && VALID_STRING(reset_3string))
- {
- termcap_reset = reset_2string;
- reset_2string = (char *)0;
- }
-#if USE_XMC_SUPPORT
- if (magic_cookie_glitch_ul < 0 && magic_cookie_glitch && VALID_STRING(enter_underline_mode))
- magic_cookie_glitch_ul = magic_cookie_glitch;
-#else
- magic_cookie_glitch_ul = -1;
-#endif
+ /* current (4.4BSD) capabilities not obsolete */
+ if (!VALID_STRING(termcap_init2) && VALID_STRING(init_3string)) {
+ termcap_init2 = init_3string;
+ init_3string = ABSENT_STRING;
+ }
+ if (!VALID_STRING(termcap_reset)
+ && VALID_STRING(reset_2string)
+ && !VALID_STRING(reset_1string)
+ && !VALID_STRING(reset_3string)) {
+ termcap_reset = reset_2string;
+ reset_2string = ABSENT_STRING;
+ }
+ if (magic_cookie_glitch_ul == ABSENT_NUMERIC
+ && magic_cookie_glitch != ABSENT_NUMERIC
+ && VALID_STRING(enter_underline_mode))
+ magic_cookie_glitch_ul = magic_cookie_glitch;
- /* totally obsolete capabilities */
- linefeed_is_newline = VALID_STRING(newline)
- && (strcmp("\n", newline) == 0);
- if (VALID_STRING(cursor_left)
- && (capval = EXTRACT_DELAY(cursor_left)))
- backspace_delay = capval;
- if (VALID_STRING(tab) && (capval = EXTRACT_DELAY(tab)))
- horizontal_tab_delay = capval;
+ /* totally obsolete capabilities */
+ linefeed_is_newline = VALID_STRING(newline)
+ && (strcmp("\n", newline) == 0);
+ if (VALID_STRING(cursor_left)
+ && (capval = EXTRACT_DELAY(cursor_left)))
+ backspace_delay = capval;
+ if (VALID_STRING(tab) && (capval = EXTRACT_DELAY(tab)))
+ horizontal_tab_delay = capval;
#undef EXTRACT_DELAY
- }
+}
diff --git a/lib/libcurses/curs_scroll.3 b/lib/libcurses/curs_scroll.3
index cd2e7affb32..78f5dbe881b 100644
--- a/lib/libcurses/curs_scroll.3
+++ b/lib/libcurses/curs_scroll.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: curs_scroll.3,v 1.5 1998/09/13 19:16:22 millert Exp $
+.\" $OpenBSD: curs_scroll.3,v 1.6 2000/01/02 22:06:50 millert Exp $
.\"
.\"***************************************************************************
.\" Copyright (c) 1998 Free Software Foundation, Inc. *
@@ -28,7 +28,7 @@
.\" authorization. *
.\"***************************************************************************
.\"
-.\" $From: curs_scroll.3x,v 1.6 1998/03/11 21:12:53 juergen Exp $
+.\" $From: curs_scroll.3x,v 1.7 1999/12/25 21:40:45 tom Exp $
.TH curs_scroll 3 ""
.SH NAME
\fBscroll\fR, \fBsrcl\fR, \fBwscrl\fR - scroll a \fBcurses\fR window
@@ -65,7 +65,8 @@ immediately if the scroll region is the entire screen "is" performed, not
that this will occur, in order to leave open the possibility of smarter
optimization of multiple scroll actions on the next update.
-Neither the SVr4 documentation specifies whether the current attribute or
+Neither the SVr4 nor the XSI documentation specify whether the current
+attribute or
current color-pair of blanks generated by the scroll function is zeroed.
Under this implementation it is.
.SH PORTABILITY
diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h
index 27d21ec267d..11dba55f958 100644
--- a/lib/libcurses/curses.h
+++ b/lib/libcurses/curses.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: curses.h,v 1.41 1999/12/28 19:16:24 millert Exp $ */
+/* $OpenBSD: curses.h,v 1.42 2000/01/02 22:06:50 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998 Free Software Foundation, Inc. *
@@ -50,7 +50,7 @@
/* These are defined only in curses.h, and are used for conditional compiles */
#define NCURSES_VERSION_MAJOR 5
#define NCURSES_VERSION_MINOR 0
-#define NCURSES_VERSION_PATCH 19991218
+#define NCURSES_VERSION_PATCH 20000101
/* This is defined in more than one ncurses header, for identification */
#undef NCURSES_VERSION
diff --git a/lib/libcurses/tinfo/lib_options.c b/lib/libcurses/tinfo/lib_options.c
index 5420fa1964f..9cef80e29fb 100644
--- a/lib/libcurses/tinfo/lib_options.c
+++ b/lib/libcurses/tinfo/lib_options.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_options.c,v 1.4 1999/11/28 17:49:54 millert Exp $ */
+/* $OpenBSD: lib_options.c,v 1.5 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,7 +33,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
** lib_options.c
**
@@ -43,168 +42,163 @@
#include <curses.priv.h>
-#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */
- /* cursor_visible,cursor_normal,cursor_invisible */
+#include <term.h>
-MODULE_ID("$From: lib_options.c,v 1.36 1999/10/22 21:38:57 tom Exp $")
+MODULE_ID("$From: lib_options.c,v 1.37 2000/01/01 16:59:50 tom Exp $")
-int idlok(WINDOW *win, bool flag)
+int
+idlok(WINDOW *win, bool flag)
{
- T((T_CALLED("idlok(%p,%d)"), win, flag));
+ T((T_CALLED("idlok(%p,%d)"), win, flag));
- if (win) {
- _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region);
- returnCode(OK);
- }
- else
- returnCode(ERR);
+ if (win) {
+ _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region);
+ returnCode(OK);
+ } else
+ returnCode(ERR);
}
-
-void idcok(WINDOW *win, bool flag)
+void
+idcok(WINDOW *win, bool flag)
{
- T((T_CALLED("idcok(%p,%d)"), win, flag));
+ T((T_CALLED("idcok(%p,%d)"), win, flag));
- if (win)
- _nc_idcok = win->_idcok = flag && has_ic();
+ if (win)
+ _nc_idcok = win->_idcok = flag && has_ic();
- returnVoid;
+ returnVoid;
}
-int halfdelay(int t)
+int
+halfdelay(int t)
{
- T((T_CALLED("halfdelay(%d)"), t));
+ T((T_CALLED("halfdelay(%d)"), t));
- if (t < 1 || t > 255)
- returnCode(ERR);
+ if (t < 1 || t > 255)
+ returnCode(ERR);
- cbreak();
- SP->_cbreak = t+1;
- returnCode(OK);
+ cbreak();
+ SP->_cbreak = t + 1;
+ returnCode(OK);
}
-int nodelay(WINDOW *win, bool flag)
+int
+nodelay(WINDOW *win, bool flag)
{
- T((T_CALLED("nodelay(%p,%d)"), win, flag));
+ T((T_CALLED("nodelay(%p,%d)"), win, flag));
- if (win) {
- if (flag == TRUE)
+ if (win) {
+ if (flag == TRUE)
win->_delay = 0;
- else win->_delay = -1;
- returnCode(OK);
- }
else
- returnCode(ERR);
+ win->_delay = -1;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
}
-int notimeout(WINDOW *win, bool f)
+int
+notimeout(WINDOW *win, bool f)
{
- T((T_CALLED("notimout(%p,%d)"), win, f));
+ T((T_CALLED("notimout(%p,%d)"), win, f));
- if (win) {
- win->_notimeout = f;
- returnCode(OK);
- }
- else
- returnCode(ERR);
+ if (win) {
+ win->_notimeout = f;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
}
-void wtimeout(WINDOW *win, int delay)
+void
+wtimeout(WINDOW *win, int delay)
{
- T((T_CALLED("wtimeout(%p,%d)"), win, delay));
+ T((T_CALLED("wtimeout(%p,%d)"), win, delay));
- if (win) {
- win->_delay = delay;
- }
+ if (win) {
+ win->_delay = delay;
+ }
}
-int keypad(WINDOW *win, bool flag)
+int
+keypad(WINDOW *win, bool flag)
{
- T((T_CALLED("keypad(%p,%d)"), win, flag));
+ T((T_CALLED("keypad(%p,%d)"), win, flag));
- if (win) {
- win->_use_keypad = flag;
- returnCode(_nc_keypad(flag));
- }
- else
- returnCode(ERR);
+ if (win) {
+ win->_use_keypad = flag;
+ returnCode(_nc_keypad(flag));
+ } else
+ returnCode(ERR);
}
-
-int meta(WINDOW *win GCC_UNUSED, bool flag)
+int
+meta(WINDOW *win GCC_UNUSED, bool flag)
{
- /* Ok, we stay relaxed and don't signal an error if win is NULL */
- T((T_CALLED("meta(%p,%d)"), win, flag));
-
- SP->_use_meta = flag;
-
- if (flag && meta_on)
- {
- TPUTS_TRACE("meta_on");
- putp(meta_on);
- }
- else if (! flag && meta_off)
- {
- TPUTS_TRACE("meta_off");
- putp(meta_off);
- }
- returnCode(OK);
+ /* Ok, we stay relaxed and don't signal an error if win is NULL */
+ T((T_CALLED("meta(%p,%d)"), win, flag));
+
+ SP->_use_meta = flag;
+
+ if (flag && meta_on) {
+ TPUTS_TRACE("meta_on");
+ putp(meta_on);
+ } else if (!flag && meta_off) {
+ TPUTS_TRACE("meta_off");
+ putp(meta_off);
+ }
+ returnCode(OK);
}
/* curs_set() moved here to narrow the kernel interface */
-int curs_set(int vis)
+int
+curs_set(int vis)
{
-int cursor = SP->_cursor;
-
- T((T_CALLED("curs_set(%d)"), vis));
-
- if (vis < 0 || vis > 2)
- returnCode(ERR);
-
- if (vis == cursor)
- returnCode(cursor);
-
- switch(vis) {
- case 2:
- if (cursor_visible)
- {
- TPUTS_TRACE("cursor_visible");
- putp(cursor_visible);
- }
- else
- returnCode(ERR);
- break;
- case 1:
- if (cursor_normal)
- {
- TPUTS_TRACE("cursor_normal");
- putp(cursor_normal);
- }
- else
- returnCode(ERR);
- break;
- case 0:
- if (cursor_invisible)
- {
- TPUTS_TRACE("cursor_invisible");
- putp(cursor_invisible);
- }
- else
- returnCode(ERR);
- break;
- }
- SP->_cursor = vis;
- _nc_flush();
-
- returnCode(cursor==-1 ? 1 : cursor);
+ int cursor = SP->_cursor;
+
+ T((T_CALLED("curs_set(%d)"), vis));
+
+ if (vis < 0 || vis > 2)
+ returnCode(ERR);
+
+ if (vis == cursor)
+ returnCode(cursor);
+
+ switch (vis) {
+ case 2:
+ if (cursor_visible) {
+ TPUTS_TRACE("cursor_visible");
+ putp(cursor_visible);
+ } else
+ returnCode(ERR);
+ break;
+ case 1:
+ if (cursor_normal) {
+ TPUTS_TRACE("cursor_normal");
+ putp(cursor_normal);
+ } else
+ returnCode(ERR);
+ break;
+ case 0:
+ if (cursor_invisible) {
+ TPUTS_TRACE("cursor_invisible");
+ putp(cursor_invisible);
+ } else
+ returnCode(ERR);
+ break;
+ }
+ SP->_cursor = vis;
+ _nc_flush();
+
+ returnCode(cursor == -1 ? 1 : cursor);
}
-int typeahead(int fd)
+int
+typeahead(int fd)
{
- T((T_CALLED("typeahead(%d)"), fd));
- SP->_checkfd = fd;
- returnCode(OK);
+ T((T_CALLED("typeahead(%d)"), fd));
+ SP->_checkfd = fd;
+ returnCode(OK);
}
/*
@@ -215,18 +209,20 @@ int typeahead(int fd)
*/
#ifdef NCURSES_EXT_FUNCS
-static int has_key_internal(int keycode, struct tries *tp)
+static int
+has_key_internal(int keycode, struct tries *tp)
{
if (tp == 0)
- return(FALSE);
+ return (FALSE);
else if (tp->value == keycode)
- return(TRUE);
+ return (TRUE);
else
- return(has_key_internal(keycode, tp->child)
- || has_key_internal(keycode, tp->sibling));
+ return (has_key_internal(keycode, tp->child)
+ || has_key_internal(keycode, tp->sibling));
}
-int has_key(int keycode)
+int
+has_key(int keycode)
{
T((T_CALLED("has_key(%d)"), keycode));
returnCode(has_key_internal(keycode, SP->_keytry));
@@ -240,24 +236,22 @@ int has_key(int keycode)
* flush, then the next wgetch may get the escape sequence that corresponds to
* the terminal state _before_ switching modes.
*/
-int _nc_keypad(bool flag)
+int
+_nc_keypad(bool flag)
{
- if (flag && keypad_xmit)
- {
- TPUTS_TRACE("keypad_xmit");
- putp(keypad_xmit);
- _nc_flush();
- }
- else if (! flag && keypad_local)
- {
- TPUTS_TRACE("keypad_local");
- putp(keypad_local);
- _nc_flush();
- }
-
- if (flag && !SP->_tried) {
- _nc_init_keytry();
- SP->_tried = TRUE;
- }
- return(OK);
+ if (flag && keypad_xmit) {
+ TPUTS_TRACE("keypad_xmit");
+ putp(keypad_xmit);
+ _nc_flush();
+ } else if (!flag && keypad_local) {
+ TPUTS_TRACE("keypad_local");
+ putp(keypad_local);
+ _nc_flush();
+ }
+
+ if (flag && !SP->_tried) {
+ _nc_init_keytry();
+ SP->_tried = TRUE;
+ }
+ return (OK);
}
diff --git a/lib/libcurses/tinfo/lib_setup.c b/lib/libcurses/tinfo/lib_setup.c
index 36fd188c42d..2f722cee697 100644
--- a/lib/libcurses/tinfo/lib_setup.c
+++ b/lib/libcurses/tinfo/lib_setup.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_setup.c,v 1.7 1999/11/28 17:49:54 millert Exp $ */
+/* $OpenBSD: lib_setup.c,v 1.8 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 *
@@ -33,7 +33,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* Terminal setup routines common to termcap and terminfo:
*
@@ -42,16 +41,16 @@
*/
#include <curses.priv.h>
-#include <tic.h> /* for MAX_NAME_SIZE */
+#include <tic.h> /* for MAX_NAME_SIZE */
#include <term_entry.h>
#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
-#include <term.h> /* lines, columns, cur_term */
+#include <term.h> /* lines, columns, cur_term */
-MODULE_ID("$From: lib_setup.c,v 1.56 1999/10/30 23:00:16 tom Exp $")
+MODULE_ID("$From: lib_setup.c,v 1.58 2000/01/01 16:46:57 tom Exp $")
/****************************************************************************
*
@@ -97,120 +96,116 @@ static int _use_env = TRUE;
static void do_prototype(void);
-void use_env(bool f)
+void
+use_env(bool f)
{
- _use_env = f;
+ _use_env = f;
}
int LINES = 0, COLS = 0, TABSIZE = 0;
-static void _nc_get_screensize(int *linep, int *colp)
+static void
+_nc_get_screensize(int *linep, int *colp)
/* Obtain lines/columns values from the environment and/or terminfo entry */
{
- /* figure out the size of the screen */
- T(("screen size: terminfo lines = %d columns = %d", lines, columns));
+ /* figure out the size of the screen */
+ T(("screen size: terminfo lines = %d columns = %d", lines, columns));
- if (!_use_env)
- {
- *linep = (int)lines;
- *colp = (int)columns;
- }
- else /* usually want to query LINES and COLUMNS from environment */
- {
- int value;
+ if (!_use_env) {
+ *linep = (int) lines;
+ *colp = (int) columns;
+ } else { /* usually want to query LINES and COLUMNS from environment */
+ int value;
- *linep = *colp = 0;
+ *linep = *colp = 0;
- /* first, look for environment variables */
- if ((value = _nc_getenv_num("LINES")) > 0) {
- *linep = value;
- }
- if ((value = _nc_getenv_num("COLUMNS")) > 0) {
- *colp = value;
- }
- T(("screen size: environment LINES = %d COLUMNS = %d",*linep,*colp));
+ /* first, look for environment variables */
+ if ((value = _nc_getenv_num("LINES")) > 0) {
+ *linep = value;
+ }
+ if ((value = _nc_getenv_num("COLUMNS")) > 0) {
+ *colp = value;
+ }
+ T(("screen size: environment LINES = %d COLUMNS = %d", *linep, *colp));
#ifdef __EMX__
- if (*linep <= 0 || *colp <= 0)
- {
- int screendata[2];
- _scrsize(screendata);
- *colp = screendata[0];
- *linep = screendata[1];
- T(("EMX screen size: environment LINES = %d COLUMNS = %d",*linep,*colp));
- }
+ if (*linep <= 0 || *colp <= 0) {
+ int screendata[2];
+ _scrsize(screendata);
+ *colp = screendata[0];
+ *linep = screendata[1];
+ T(("EMX screen size: environment LINES = %d COLUMNS = %d",
+ *linep, *colp));
+ }
#endif
#if HAVE_SIZECHANGE
- /* if that didn't work, maybe we can try asking the OS */
- if (*linep <= 0 || *colp <= 0)
- {
- if (isatty(cur_term->Filedes))
- {
- STRUCT_WINSIZE size;
-
- errno = 0;
- do {
- if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0
- && errno != EINTR)
- goto failure;
- } while
- (errno == EINTR);
-
- /*
- * Solaris lets users override either dimension with an
- * environment variable.
- */
- if (*linep <= 0)
- *linep = WINSIZE_ROWS(size);
- if (*colp <= 0)
- *colp = WINSIZE_COLS(size);
- }
- /* FALLTHRU */
- failure:;
+ /* if that didn't work, maybe we can try asking the OS */
+ if (*linep <= 0 || *colp <= 0) {
+ if (isatty(cur_term->Filedes)) {
+ STRUCT_WINSIZE size;
+
+ errno = 0;
+ do {
+ if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0
+ && errno != EINTR)
+ goto failure;
+ } while
+ (errno == EINTR);
+
+ /*
+ * Solaris lets users override either dimension with an
+ * environment variable.
+ */
+ if (*linep <= 0)
+ *linep = WINSIZE_ROWS(size);
+ if (*colp <= 0)
+ *colp = WINSIZE_COLS(size);
}
+ /* FALLTHRU */
+ failure:;
+ }
#endif /* HAVE_SIZECHANGE */
- /* if we can't get dynamic info about the size, use static */
- if (*linep <= 0 || *colp <= 0)
- if (lines > 0 && columns > 0)
- {
- *linep = (int)lines;
- *colp = (int)columns;
- }
-
- /* the ultimate fallback, assume fixed 24x80 size */
- if (*linep <= 0 || *colp <= 0)
- {
- *linep = 24;
- *colp = 80;
+ /* if we can't get dynamic info about the size, use static */
+ if (*linep <= 0 || *colp <= 0)
+ if (lines > 0 && columns > 0) {
+ *linep = (int) lines;
+ *colp = (int) columns;
}
- /*
- * Put the derived values back in the screen-size caps, so
- * tigetnum() and tgetnum() will do the right thing.
- */
- lines = (short)(*linep);
- columns = (short)(*colp);
+ /* the ultimate fallback, assume fixed 24x80 size */
+ if (*linep <= 0 || *colp <= 0) {
+ *linep = 24;
+ *colp = 80;
}
- T(("screen size is %dx%d", *linep, *colp));
+ /*
+ * Put the derived values back in the screen-size caps, so
+ * tigetnum() and tgetnum() will do the right thing.
+ */
+ lines = (short) (*linep);
+ columns = (short) (*colp);
+ }
+
+ T(("screen size is %dx%d", *linep, *colp));
- if (init_tabs != -1)
- TABSIZE = (int)init_tabs;
- else
- TABSIZE = 8;
- T(("TABSIZE = %d", TABSIZE));
+ if (VALID_NUMERIC(init_tabs))
+ TABSIZE = (int) init_tabs;
+ else
+ TABSIZE = 8;
+ T(("TABSIZE = %d", TABSIZE));
}
#if USE_SIZECHANGE
-void _nc_update_screensize(void)
+void
+_nc_update_screensize(void)
{
- int my_lines, my_cols;
+ int my_lines, my_cols;
- _nc_get_screensize(&my_lines, &my_cols);
- if (SP != 0 && SP->_resize != 0)
- SP->_resize(my_lines, my_cols);
+ _nc_get_screensize(&my_lines, &my_cols);
+ if (SP != 0 && SP->_resize != 0)
+ SP->_resize(my_lines, my_cols);
}
#endif
@@ -237,48 +232,49 @@ void _nc_update_screensize(void)
}
#if USE_DATABASE
-static int grab_entry(const char *const tn, TERMTYPE *const tp)
+static int
+grab_entry(const char *const tn, TERMTYPE * const tp)
/* return 1 if entry found, 0 if not found, -1 if database not accessible */
{
- char filename[PATH_MAX];
- int status;
+ char filename[PATH_MAX];
+ int status;
- /*
- * $TERM shouldn't contain pathname delimiters.
- */
- if (strchr(tn, '/'))
- return 0;
+ /*
+ * $TERM shouldn't contain pathname delimiters.
+ */
+ if (strchr(tn, '/'))
+ return 0;
- if ((status = _nc_read_entry(tn, filename, tp)) != 1) {
+ if ((status = _nc_read_entry(tn, filename, tp)) != 1) {
#ifndef PURE_TERMINFO
- /*
- * Try falling back on the termcap file.
- * Note: allowing this call links the entire terminfo/termcap
- * compiler into the startup code. It's preferable to build a
- * real terminfo database and use that.
- */
- status = _nc_read_termcap_entry(tn, tp);
-#endif /* PURE_TERMINFO */
-
- }
-
/*
- * If we have an entry, force all of the cancelled strings to null
- * pointers so we don't have to test them in the rest of the library.
- * (The terminfo compiler bypasses this logic, since it must know if
- * a string is cancelled, for merging entries).
+ * Try falling back on the termcap file.
+ * Note: allowing this call links the entire terminfo/termcap
+ * compiler into the startup code. It's preferable to build a
+ * real terminfo database and use that.
*/
- if (status == 1) {
- int n;
- for_each_boolean(n,tp)
- if (!VALID_BOOLEAN(tp->Booleans[n]))
- tp->Booleans[n] = FALSE;
- for_each_string(n,tp)
- if (tp->Strings[n] == CANCELLED_STRING)
- tp->Strings[n] = ABSENT_STRING;
- }
- return(status);
+ status = _nc_read_termcap_entry(tn, tp);
+#endif /* PURE_TERMINFO */
+
+ }
+
+ /*
+ * If we have an entry, force all of the cancelled strings to null
+ * pointers so we don't have to test them in the rest of the library.
+ * (The terminfo compiler bypasses this logic, since it must know if
+ * a string is cancelled, for merging entries).
+ */
+ if (status == 1) {
+ int n;
+ for_each_boolean(n, tp)
+ if (!VALID_BOOLEAN(tp->Booleans[n]))
+ tp->Booleans[n] = FALSE;
+ for_each_string(n, tp)
+ if (tp->Strings[n] == CANCELLED_STRING)
+ tp->Strings[n] = ABSENT_STRING;
+ }
+ return (status);
}
#endif
@@ -292,106 +288,102 @@ char ttytype[NAMESIZE] = "";
*
*/
-int setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
+int
+setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
{
-struct term *term_ptr;
-int status;
+ struct term *term_ptr;
+ int status;
- T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
+ T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
- if (tname == 0) {
- tname = getenv("TERM");
- if (tname == 0 || *tname == '\0') {
- ret_error0(-1, "TERM environment variable not set.\n");
- }
- }
- if (strlen(tname) > MAX_NAME_SIZE) {
- ret_error(-1, "TERM environment must be <= %d characters.\n",
- MAX_NAME_SIZE);
+ if (tname == 0) {
+ tname = getenv("TERM");
+ if (tname == 0 || *tname == '\0') {
+ ret_error0(-1, "TERM environment variable not set.\n");
}
+ }
+ if (strlen(tname) > MAX_NAME_SIZE) {
+ ret_error(-1, "TERM environment must be <= %d characters.\n",
+ MAX_NAME_SIZE);
+ }
- T(("your terminal name is %s", tname));
+ T(("your terminal name is %s", tname));
- term_ptr = typeCalloc(TERMINAL, 1);
+ term_ptr = typeCalloc(TERMINAL, 1);
- if (term_ptr == 0) {
- ret_error0(-1, "Not enough memory to create terminal structure.\n") ;
- }
+ if (term_ptr == 0) {
+ ret_error0(-1, "Not enough memory to create terminal structure.\n");
+ }
#if USE_DATABASE
- status = grab_entry(tname, &term_ptr->type);
+ status = grab_entry(tname, &term_ptr->type);
#else
- status = 0;
+ status = 0;
#endif
- /* try fallback list if entry on disk */
- if (status != 1)
- {
- const TERMTYPE *fallback = _nc_fallback(tname);
-
- if (fallback)
- {
- term_ptr->type = *fallback;
- status = 1;
- }
- }
-
- if (status == -1)
- {
- ret_error0(-1, "terminals database is inaccessible\n");
- }
- else if (status == 0)
- {
- ret_error(0, "'%s': unknown terminal type.\n", tname);
- }
-
- /*
- * Improve on SVr4 curses. If an application mixes curses and termcap
- * calls, it may call both initscr and tgetent. This is not really a
- * good thing to do, but can happen if someone tries using ncurses with
- * the readline library. The problem we are fixing is that when
- * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
- * zeroed. A subsequent call to endwin uses the zeroed terminal
- * settings rather than the ones saved in initscr. So we check if
- * cur_term appears to contain terminal settings for the same output
- * file as our current call - and copy those terminal settings. (SVr4
- * curses does not do this, however applications that are working
- * around the problem will still work properly with this feature).
- */
- if (cur_term != 0) {
- if (cur_term->Filedes == Filedes)
- term_ptr->Ottyb = cur_term->Ottyb;
- }
-
- set_curterm(term_ptr);
-
- if (command_character && getenv("CC"))
- do_prototype();
-
- strlcpy(ttytype, cur_term->type.term_names, NAMESIZE);
-
- /*
- * Allow output redirection. This is what SVr3 does.
- * If stdout is directed to a file, screen updates go
- * to standard error.
- */
- if (Filedes == STDOUT_FILENO && !isatty(Filedes))
- Filedes = STDERR_FILENO;
- cur_term->Filedes = Filedes;
-
- _nc_get_screensize(&LINES, &COLS);
-
- if (errret)
- *errret = 1;
+ /* try fallback list if entry on disk */
+ if (status != 1) {
+ const TERMTYPE *fallback = _nc_fallback(tname);
- T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
-
- if (generic_type) {
- ret_error(0, "'%s': I need something more specific.\n", tname);
- }
- if (hard_copy) {
- ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
+ if (fallback) {
+ term_ptr->type = *fallback;
+ status = 1;
}
- returnCode(OK);
+ }
+
+ if (status == -1) {
+ ret_error0(-1, "terminals database is inaccessible\n");
+ } else if (status == 0) {
+ ret_error(0, "'%s': unknown terminal type.\n", tname);
+ }
+
+ /*
+ * Improve on SVr4 curses. If an application mixes curses and termcap
+ * calls, it may call both initscr and tgetent. This is not really a
+ * good thing to do, but can happen if someone tries using ncurses with
+ * the readline library. The problem we are fixing is that when
+ * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
+ * zeroed. A subsequent call to endwin uses the zeroed terminal
+ * settings rather than the ones saved in initscr. So we check if
+ * cur_term appears to contain terminal settings for the same output
+ * file as our current call - and copy those terminal settings. (SVr4
+ * curses does not do this, however applications that are working
+ * around the problem will still work properly with this feature).
+ */
+ if (cur_term != 0) {
+ if (cur_term->Filedes == Filedes)
+ term_ptr->Ottyb = cur_term->Ottyb;
+ }
+
+ set_curterm(term_ptr);
+
+ if (command_character && getenv("CC"))
+ do_prototype();
+
+ strlcpy(ttytype, cur_term->type.term_names, NAMESIZE);
+
+ /*
+ * Allow output redirection. This is what SVr3 does.
+ * If stdout is directed to a file, screen updates go
+ * to standard error.
+ */
+ if (Filedes == STDOUT_FILENO && !isatty(Filedes))
+ Filedes = STDERR_FILENO;
+ cur_term->Filedes = Filedes;
+
+ _nc_get_screensize(&LINES, &COLS);
+
+ if (errret)
+ *errret = 1;
+
+ T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
+
+ if (generic_type) {
+ ret_error(0, "'%s': I need something more specific.\n", tname);
+ }
+ if (hard_copy) {
+ ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
+ }
+ returnCode(OK);
}
/*
@@ -405,19 +397,19 @@ int status;
static void
do_prototype(void)
{
-int i;
-char CC;
-char proto;
-char *tmp;
-
- tmp = getenv("CC");
- CC = *tmp;
- proto = *command_character;
-
- for_each_string(i, &(cur_term->type)) {
- for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) {
- if (*tmp == proto)
- *tmp = CC;
- }
+ int i;
+ char CC;
+ char proto;
+ char *tmp;
+
+ tmp = getenv("CC");
+ CC = *tmp;
+ proto = *command_character;
+
+ for_each_string(i, &(cur_term->type)) {
+ for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) {
+ if (*tmp == proto)
+ *tmp = CC;
}
+ }
}
diff --git a/lib/libcurses/tinfo/lib_termcap.c b/lib/libcurses/tinfo/lib_termcap.c
index 2ead2fded90..d99749636e0 100644
--- a/lib/libcurses/tinfo/lib_termcap.c
+++ b/lib/libcurses/tinfo/lib_termcap.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_termcap.c,v 1.3 1999/11/28 17:49:54 millert Exp $ */
+/* $OpenBSD: lib_termcap.c,v 1.4 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,7 +41,7 @@
#define __INTERNAL_CAPS_VISIBLE
#include <term_entry.h>
-MODULE_ID("$From: lib_termcap.c,v 1.30 1999/10/30 23:00:16 tom Exp $")
+MODULE_ID("$From: lib_termcap.c,v 1.32 2000/01/01 16:49:54 tom Exp $")
/*
some of the code in here was contributed by:
@@ -66,29 +66,30 @@ char *BC = 0;
*
***************************************************************************/
-int tgetent(char *bufp GCC_UNUSED, const char *name)
+int
+tgetent(char *bufp GCC_UNUSED, const char *name)
{
-int errcode;
+ int errcode;
- T((T_CALLED("tgetent()")));
+ T((T_CALLED("tgetent()")));
- setupterm((NCURSES_CONST char *)name, STDOUT_FILENO, &errcode);
+ setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode);
- if (errcode == 1) {
+ if (errcode == 1) {
- if (cursor_left)
- if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
- backspace_if_not_bs = cursor_left;
+ if (cursor_left)
+ if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
+ backspace_if_not_bs = cursor_left;
- /* we're required to export these */
- if (pad_char != NULL)
- PC = pad_char[0];
- if (cursor_up != NULL)
- UP = cursor_up;
- if (backspace_if_not_bs != NULL)
- BC = backspace_if_not_bs;
+ /* we're required to export these */
+ if (pad_char != NULL)
+ PC = pad_char[0];
+ if (cursor_up != NULL)
+ UP = cursor_up;
+ if (backspace_if_not_bs != NULL)
+ BC = backspace_if_not_bs;
- (void) baudrate(); /* sets ospeed as a side-effect */
+ (void) baudrate(); /* sets ospeed as a side-effect */
/* LINT_PREPRO
#if 0*/
@@ -96,8 +97,8 @@ int errcode;
/* LINT_PREPRO
#endif*/
- }
- returnCode(errcode);
+ }
+ returnCode(errcode);
}
/***************************************************************************
@@ -109,22 +110,23 @@ int errcode;
*
***************************************************************************/
-int tgetflag(NCURSES_CONST char *id)
+int
+tgetflag(NCURSES_CONST char *id)
{
-int i;
-
- T((T_CALLED("tgetflag(%s)"), id));
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_boolean(i, tp) {
- const char *capname = ExtBoolname(tp, i, boolcodes);
- if (!strncmp(id, capname, 2)) {
- /* setupterm forces invalid booleans to false */
- returnCode(tp->Booleans[i]);
- }
+ int i;
+
+ T((T_CALLED("tgetflag(%s)"), id));
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_boolean(i, tp) {
+ const char *capname = ExtBoolname(tp, i, boolcodes);
+ if (!strncmp(id, capname, 2)) {
+ /* setupterm forces invalid booleans to false */
+ returnCode(tp->Booleans[i]);
}
}
- returnCode(0); /* Solaris does this */
+ }
+ returnCode(0); /* Solaris does this */
}
/***************************************************************************
@@ -136,23 +138,24 @@ int i;
*
***************************************************************************/
-int tgetnum(NCURSES_CONST char *id)
+int
+tgetnum(NCURSES_CONST char *id)
{
-int i;
-
- T((T_CALLED("tgetnum(%s)"), id));
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_number(i, tp) {
- const char *capname = ExtNumname(tp, i, numcodes);
- if (!strncmp(id, capname, 2)) {
- if (!VALID_NUMERIC(tp->Numbers[i]))
- return -1;
- returnCode(tp->Numbers[i]);
- }
+ int i;
+
+ T((T_CALLED("tgetnum(%s)"), id));
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_number(i, tp) {
+ const char *capname = ExtNumname(tp, i, numcodes);
+ if (!strncmp(id, capname, 2)) {
+ if (!VALID_NUMERIC(tp->Numbers[i]))
+ return ABSENT_NUMERIC;
+ returnCode(tp->Numbers[i]);
}
}
- returnCode(ERR);
+ }
+ returnCode(ABSENT_NUMERIC);
}
/***************************************************************************
@@ -164,30 +167,31 @@ int i;
*
***************************************************************************/
-char *tgetstr(NCURSES_CONST char *id, char **area)
+char *
+tgetstr(NCURSES_CONST char *id, char **area)
{
-int i;
-
- T((T_CALLED("tgetstr(%s,%p)"), id, area));
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_string(i, tp) {
- const char *capname = ExtStrname(tp, i, strcodes);
- T(("trying %s", capname));
- if (!strncmp(id, capname, 2)) {
- T(("found match : %s", _nc_visbuf(tp->Strings[i])));
- /* setupterm forces cancelled strings to null */
- if (area != 0
- && *area != 0
- && VALID_STRING(tp->Strings[i])) {
- (void) strcpy(*area, tp->Strings[i]);
- *area += strlen(*area) + 1;
- }
- returnPtr(tp->Strings[i]);
+ int i;
+
+ T((T_CALLED("tgetstr(%s,%p)"), id, area));
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_string(i, tp) {
+ const char *capname = ExtStrname(tp, i, strcodes);
+ T(("trying %s", capname));
+ if (!strncmp(id, capname, 2)) {
+ T(("found match : %s", _nc_visbuf(tp->Strings[i])));
+ /* setupterm forces cancelled strings to null */
+ if (area != 0
+ && *area != 0
+ && VALID_STRING(tp->Strings[i])) {
+ (void) strcpy(*area, tp->Strings[i]);
+ *area += strlen(*area) + 1;
}
+ returnPtr(tp->Strings[i]);
}
}
- returnPtr(NULL);
+ }
+ returnPtr(NULL);
}
/*
@@ -199,8 +203,9 @@ int i;
*
*/
-char *tgoto(const char *string, int x, int y)
+char *
+tgoto(const char *string, int x, int y)
{
- T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y));
- returnPtr(tparm((NCURSES_CONST char *)string, y, x));
+ T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y));
+ returnPtr(tparm((NCURSES_CONST char *) string, y, x));
}
diff --git a/lib/libcurses/tinfo/lib_ti.c b/lib/libcurses/tinfo/lib_ti.c
index bfa484cfd95..91164f528fb 100644
--- a/lib/libcurses/tinfo/lib_ti.c
+++ b/lib/libcurses/tinfo/lib_ti.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_ti.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */
+/* $OpenBSD: lib_ti.c,v 1.3 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,71 +33,73 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
#include <curses.priv.h>
#include <term_entry.h>
#include <tic.h>
-MODULE_ID("$From: lib_ti.c,v 1.16 1999/02/28 23:11:28 tom Exp $")
+MODULE_ID("$From: lib_ti.c,v 1.18 2000/01/01 16:58:30 tom Exp $")
-int tigetflag(NCURSES_CONST char *str)
+int
+tigetflag(NCURSES_CONST char *str)
{
-int i;
-
- T((T_CALLED("tigetflag(%s)"), str));
-
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_boolean(i,tp) {
- const char *capname = ExtBoolname(tp, i, boolnames);
- if (!strcmp(str, capname)) {
- /* setupterm forces invalid booleans to false */
- returnCode(tp->Booleans[i]);
- }
+ int i;
+
+ T((T_CALLED("tigetflag(%s)"), str));
+
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_boolean(i, tp) {
+ const char *capname = ExtBoolname(tp, i, boolnames);
+ if (!strcmp(str, capname)) {
+ /* setupterm forces invalid booleans to false */
+ returnCode(tp->Booleans[i]);
}
}
+ }
- returnCode(ABSENT_BOOLEAN);
+ returnCode(ABSENT_BOOLEAN);
}
-int tigetnum(NCURSES_CONST char *str)
+int
+tigetnum(NCURSES_CONST char *str)
{
-int i;
-
- T((T_CALLED("tigetnum(%s)"), str));
-
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_number(i, tp) {
- const char *capname = ExtNumname(tp, i, numnames);
- if (!strcmp(str, capname)) {
- if (!VALID_NUMERIC(tp->Numbers[i]))
- return -1;
- returnCode(tp->Numbers[i]);
- }
+ int i;
+
+ T((T_CALLED("tigetnum(%s)"), str));
+
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_number(i, tp) {
+ const char *capname = ExtNumname(tp, i, numnames);
+ if (!strcmp(str, capname)) {
+ if (!VALID_NUMERIC(tp->Numbers[i]))
+ return ABSENT_NUMERIC;
+ returnCode(tp->Numbers[i]);
}
}
+ }
- returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */
+ returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */
}
-char *tigetstr(NCURSES_CONST char *str)
+char *
+tigetstr(NCURSES_CONST char *str)
{
-int i;
-
- T((T_CALLED("tigetstr(%s)"), str));
-
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_string(i, tp) {
- const char *capname = ExtStrname(tp, i, strnames);
- if (!strcmp(str, capname)) {
- /* setupterm forces cancelled strings to null */
- returnPtr(tp->Strings[i]);
- }
+ int i;
+
+ T((T_CALLED("tigetstr(%s)"), str));
+
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_string(i, tp) {
+ const char *capname = ExtStrname(tp, i, strnames);
+ if (!strcmp(str, capname)) {
+ /* setupterm forces cancelled strings to null */
+ returnPtr(tp->Strings[i]);
}
}
+ }
- returnPtr(CANCELLED_STRING);
+ returnPtr(CANCELLED_STRING);
}
diff --git a/lib/libcurses/tinfo/read_entry.c b/lib/libcurses/tinfo/read_entry.c
index 7737580f544..59e791ebcca 100644
--- a/lib/libcurses/tinfo/read_entry.c
+++ b/lib/libcurses/tinfo/read_entry.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: read_entry.c,v 1.5 1999/08/15 11:40:56 millert Exp $ */
+/* $OpenBSD: read_entry.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */
/****************************************************************************
- * Copyright (c) 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 *
@@ -33,8 +33,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
-
/*
* read_entry.c -- Routine for reading in a compiled terminfo file
*
@@ -49,7 +47,7 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$From: read_entry.c,v 1.61 1999/07/24 20:07:20 tom Exp $")
+MODULE_ID("$From: read_entry.c,v 1.63 2000/01/01 23:06:40 tom Exp $")
#ifndef O_BINARY
#define O_BINARY 0
@@ -58,7 +56,7 @@ MODULE_ID("$From: read_entry.c,v 1.61 1999/07/24 20:07:20 tom Exp $")
#if 0
#define TRACE_IN(p) DEBUG(2, p)
#else
-#define TRACE_IN(p) /*nothing*/
+#define TRACE_IN(p) /*nothing */
#endif
/*
@@ -84,7 +82,8 @@ static bool keep_tic_directory = FALSE;
* Record the "official" location of the terminfo directory, according to
* the place where we're writing to, or the normal default, if not.
*/
-const char *_nc_tic_dir(const char *path)
+const char *
+_nc_tic_dir(const char *path)
{
static const char *result = TERMINFO;
@@ -106,41 +105,43 @@ const char *_nc_tic_dir(const char *path)
* has chdir'd to it. If we let it be changed, then if $TERMINFO has a
* relative path, we'll lose track of the actual directory.
*/
-void _nc_keep_tic_dir(const char *path)
+void
+_nc_keep_tic_dir(const char *path)
{
_nc_tic_dir(path);
keep_tic_directory = TRUE;
}
-static void convert_shorts(char *buf, short *Numbers, int count)
+static void
+convert_shorts(char *buf, short *Numbers, int count)
{
int i;
- for (i = 0; i < count; i++)
- {
- if (IS_NEG1(buf + 2*i))
+ for (i = 0; i < count; i++) {
+ if (IS_NEG1(buf + 2 * i))
Numbers[i] = ABSENT_NUMERIC;
- else if (IS_NEG2(buf + 2*i))
+ else if (IS_NEG2(buf + 2 * i))
Numbers[i] = CANCELLED_NUMERIC;
else
- Numbers[i] = LOW_MSB(buf + 2*i);
+ Numbers[i] = LOW_MSB(buf + 2 * i);
TRACE_IN(("get Numbers[%d]=%d", i, Numbers[i]));
}
}
-static void convert_strings(char *buf, char **Strings, int count, int size, char *table)
+static void
+convert_strings(char *buf, char **Strings, int count, int size, char *table)
{
int i;
char *p;
for (i = 0; i < count; i++) {
- if (IS_NEG1(buf + 2*i)) {
+ if (IS_NEG1(buf + 2 * i)) {
Strings[i] = ABSENT_STRING;
- } else if (IS_NEG2(buf + 2*i)) {
+ } else if (IS_NEG2(buf + 2 * i)) {
Strings[i] = CANCELLED_STRING;
- } else if (LOW_MSB(buf + 2*i) > size) {
+ } else if (LOW_MSB(buf + 2 * i) > size) {
Strings[i] = ABSENT_STRING;
} else {
- Strings[i] = (LOW_MSB(buf+2*i) + table);
+ Strings[i] = (LOW_MSB(buf + 2 * i) + table);
TRACE_IN(("Strings[%d] = %s", i, _nc_visbuf(Strings[i])));
}
@@ -161,53 +162,57 @@ static void convert_strings(char *buf, char **Strings, int count, int size, char
#define even_boundary(value) \
if ((value) % 2 != 0) read(fd, buf, 1)
-static int read_termtype(int fd, TERMTYPE *ptr)
+static int
+read_termtype(int fd, TERMTYPE * ptr)
/* return 1 if read, 0 if not found or garbled */
{
- int name_size, bool_count, num_count, str_count, str_size;
- int i;
- char buf[MAX_ENTRY_SIZE];
+ int name_size, bool_count, num_count, str_count, str_size;
+ int i;
+ char buf[MAX_ENTRY_SIZE];
TRACE_IN(("READ termtype header @%d", tell(fd)));
+ memset(ptr, 0, sizeof(*ptr));
+
/* grab the header */
if (!read_shorts(fd, buf, 6)
- || LOW_MSB(buf) != MAGIC) {
- return(0);
+ || LOW_MSB(buf) != MAGIC) {
+ return (0);
}
_nc_free_termtype(ptr);
- name_size = LOW_MSB(buf + 2);
+ name_size = LOW_MSB(buf + 2);
bool_count = LOW_MSB(buf + 4);
- num_count = LOW_MSB(buf + 6);
- str_count = LOW_MSB(buf + 8);
- str_size = LOW_MSB(buf + 10);
-
- TRACE_IN(("header is %d/%d/%d/%d(%d)", name_size, bool_count, num_count, str_count, str_size));
- if (name_size < 0
- || bool_count < 0
- || num_count < 0
- || str_count < 0
- || str_size < 0) {
- return(0);
+ num_count = LOW_MSB(buf + 6);
+ str_count = LOW_MSB(buf + 8);
+ str_size = LOW_MSB(buf + 10);
+
+ TRACE_IN(("header is %d/%d/%d/%d(%d)", name_size, bool_count, num_count,
+ str_count, str_size));
+ if (name_size < 0
+ || bool_count < 0
+ || num_count < 0
+ || str_count < 0
+ || str_size < 0) {
+ return (0);
}
if (str_size) {
/* try to allocate space for the string table */
- if (str_count*2 >= (int) sizeof(buf)
- || (ptr->str_table = typeMalloc(char, (unsigned)str_size)) == 0) {
- return(0);
+ if (str_count * 2 >= (int) sizeof(buf)
+ || (ptr->str_table = typeMalloc(char, (unsigned) str_size)) == 0) {
+ return (0);
}
} else {
str_count = 0;
}
/* grab the name (a null-terminate string) */
- read(fd, buf, min(MAX_NAME_SIZE, (unsigned)name_size));
+ read(fd, buf, min(MAX_NAME_SIZE, (unsigned) name_size));
buf[MAX_NAME_SIZE] = '\0';
ptr->term_names = typeCalloc(char, strlen(buf) + 1);
if (ptr->term_names == NULL) {
- return(0);
+ return (0);
}
(void) strcpy(ptr->term_names, buf);
if (name_size > MAX_NAME_SIZE)
@@ -215,8 +220,8 @@ static int read_termtype(int fd, TERMTYPE *ptr)
/* grab the booleans */
if ((ptr->Booleans = typeCalloc(char, max(BOOLCOUNT, bool_count))) == 0
- || read(fd, ptr->Booleans, (unsigned)bool_count) < bool_count) {
- return(0);
+ || read(fd, ptr->Booleans, (unsigned) bool_count) < bool_count) {
+ return (0);
}
/*
@@ -229,31 +234,29 @@ static int read_termtype(int fd, TERMTYPE *ptr)
/* grab the numbers */
if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0
- || !read_shorts(fd, buf, num_count)) {
- return(0);
+ || !read_shorts(fd, buf, num_count)) {
+ return (0);
}
convert_shorts(buf, ptr->Numbers, num_count);
if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0)
- return(0);
+ return (0);
- if (str_count)
- {
+ if (str_count) {
/* grab the string offsets */
if (!read_shorts(fd, buf, str_count)) {
- return(0);
+ return (0);
}
/* finally, grab the string table itself */
- if (read(fd, ptr->str_table, (unsigned)str_size) != str_size)
- return(0);
+ if (read(fd, ptr->str_table, (unsigned) str_size) != str_size)
+ return (0);
convert_strings(buf, ptr->Strings, str_count, str_size, ptr->str_table);
}
-
#if NCURSES_XNAMES
ptr->num_Booleans = BOOLCOUNT;
- ptr->num_Numbers = NUMCOUNT;
- ptr->num_Strings = STRCOUNT;
+ ptr->num_Numbers = NUMCOUNT;
+ ptr->num_Strings = STRCOUNT;
/*
* Read extended entries, if any, after the normal end of terminfo data.
@@ -262,94 +265,103 @@ static int read_termtype(int fd, TERMTYPE *ptr)
TRACE_IN(("READ extended_header @%d", tell(fd)));
if (_nc_user_definable && read_shorts(fd, buf, 5)) {
int ext_bool_count = LOW_MSB(buf + 0);
- int ext_num_count = LOW_MSB(buf + 2);
- int ext_str_count = LOW_MSB(buf + 4);
- int ext_str_size = LOW_MSB(buf + 6);
- int ext_str_limit = LOW_MSB(buf + 8);
+ int ext_num_count = LOW_MSB(buf + 2);
+ int ext_str_count = LOW_MSB(buf + 4);
+ int ext_str_size = LOW_MSB(buf + 6);
+ int ext_str_limit = LOW_MSB(buf + 8);
int need = (ext_bool_count + ext_num_count + ext_str_count);
int base = 0;
if (need >= (int) sizeof(buf)
- || ext_str_size >= (int) sizeof(buf)
- || ext_str_limit >= (int) sizeof(buf)
- || ext_bool_count < 0
- || ext_num_count < 0
- || ext_str_count < 0
- || ext_str_size < 0
- || ext_str_limit < 0)
- return(0);
+ || ext_str_size >= (int) sizeof(buf)
+ || ext_str_limit >= (int) sizeof(buf)
+ || ext_bool_count < 0
+ || ext_num_count < 0
+ || ext_str_count < 0
+ || ext_str_size < 0
+ || ext_str_limit < 0)
+ return (0);
ptr->num_Booleans = BOOLCOUNT + ext_bool_count;
- ptr->num_Numbers = NUMCOUNT + ext_num_count;
- ptr->num_Strings = STRCOUNT + ext_str_count;
+ ptr->num_Numbers = NUMCOUNT + ext_num_count;
+ ptr->num_Strings = STRCOUNT + ext_str_count;
- ptr->Booleans = typeRealloc(char, ptr->num_Booleans,ptr->Booleans);
+ ptr->Booleans = typeRealloc(char, ptr->num_Booleans, ptr->Booleans);
ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers);
- ptr->Strings = typeRealloc(char*, ptr->num_Strings, ptr->Strings);
+ ptr->Strings = typeRealloc(char *, ptr->num_Strings, ptr->Strings);
- TRACE_IN(("extended header is %d/%d/%d(%d:%d)", ext_bool_count, ext_num_count, ext_str_count, ext_str_size, ext_str_limit));
+ TRACE_IN(("extended header is %d/%d/%d(%d:%d)", ext_bool_count,
+ ext_num_count, ext_str_count, ext_str_size, ext_str_limit));
TRACE_IN(("READ %d extended-booleans @%d", ext_bool_count, tell(fd)));
if ((ptr->ext_Booleans = ext_bool_count) != 0) {
- if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned)ext_bool_count) != ext_bool_count)
- return(0);
+ if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned)
+ ext_bool_count) != ext_bool_count)
+ return (0);
}
even_boundary(ext_bool_count);
TRACE_IN(("READ %d extended-numbers @%d", ext_num_count, tell(fd)));
if ((ptr->ext_Numbers = ext_num_count) != 0) {
if (!read_shorts(fd, buf, ext_num_count))
- return(0);
+ return (0);
TRACE_IN(("Before converting extended-numbers"));
convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count);
}
TRACE_IN(("READ extended-offsets @%d", tell(fd)));
if ((ext_str_count || need)
- && !read_shorts(fd, buf, ext_str_count+need))
- return(0);
+ && !read_shorts(fd, buf, ext_str_count + need))
+ return (0);
- TRACE_IN(("READ %d bytes of extended-strings @%d", ext_str_limit, tell(fd)));
+ TRACE_IN(("READ %d bytes of extended-strings @%d", ext_str_limit,
+ tell(fd)));
if (ext_str_limit) {
if ((ptr->ext_str_table = typeMalloc(char, ext_str_limit)) == 0)
- return(0);
+ return (0);
if (read(fd, ptr->ext_str_table, ext_str_limit) != ext_str_limit)
- return(0);
+ return (0);
TRACE_IN(("first extended-string is %s", _nc_visbuf(ptr->ext_str_table)));
}
if ((ptr->ext_Strings = ext_str_count) != 0) {
- TRACE_IN(("Before computing extended-string capabilities str_count=%d, ext_str_count=%d", str_count, ext_str_count));
- convert_strings(buf, ptr->Strings + str_count, ext_str_count, ext_str_limit, ptr->ext_str_table);
- for (i = ext_str_count-1; i >= 0; i--) {
- TRACE_IN(("MOVE from [%d:%d] %s", i, i+str_count, _nc_visbuf(ptr->Strings[i+str_count])));
- ptr->Strings[i+STRCOUNT] = ptr->Strings[i+str_count];
- if (VALID_STRING(ptr->Strings[i+STRCOUNT]))
- base += (strlen(ptr->Strings[i+STRCOUNT]) + 1);
- TRACE_IN(("... to [%d] %s", i+STRCOUNT, _nc_visbuf(ptr->Strings[i+STRCOUNT])));
+ TRACE_IN(("Before computing extended-string capabilities str_count=%d, ext_str_count=%d",
+ str_count, ext_str_count));
+ convert_strings(buf, ptr->Strings + str_count, ext_str_count,
+ ext_str_limit, ptr->ext_str_table);
+ for (i = ext_str_count - 1; i >= 0; i--) {
+ TRACE_IN(("MOVE from [%d:%d] %s", i, i + str_count,
+ _nc_visbuf(ptr->Strings[i + str_count])));
+ ptr->Strings[i + STRCOUNT] = ptr->Strings[i + str_count];
+ if (VALID_STRING(ptr->Strings[i + STRCOUNT]))
+ base += (strlen(ptr->Strings[i + STRCOUNT]) + 1);
+ TRACE_IN(("... to [%d] %s", i + STRCOUNT,
+ _nc_visbuf(ptr->Strings[i + STRCOUNT])));
}
}
if (need) {
if ((ptr->ext_Names = typeCalloc(char *, need)) == 0)
- return(0);
- TRACE_IN(("ext_NAMES starting @%d in extended_strings, first = %s", base, _nc_visbuf(ptr->ext_str_table+base)));
- convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need, ext_str_limit, ptr->ext_str_table + base);
+ return (0);
+ TRACE_IN(("ext_NAMES starting @%d in extended_strings, first = %s",
+ base, _nc_visbuf(ptr->ext_str_table + base)));
+ convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need,
+ ext_str_limit, ptr->ext_str_table + base);
}
T(("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)",
- ptr->num_Booleans, ptr->ext_Booleans,
- ptr->num_Numbers, ptr->ext_Numbers,
- ptr->num_Strings, ptr->ext_Strings));
+ ptr->num_Booleans, ptr->ext_Booleans,
+ ptr->num_Numbers, ptr->ext_Numbers,
+ ptr->num_Strings, ptr->ext_Strings));
TRACE_IN(("extend: num_Booleans:%d", ptr->num_Booleans));
} else
#endif /* NCURSES_XNAMES */
{
T(("...done reading terminfo bool %d num %d str %d",
- bool_count,
- num_count,
- str_count));
+ bool_count,
+ num_count,
+ str_count));
TRACE_IN(("normal: num_Booleans:%d", ptr->num_Booleans));
}
@@ -360,23 +372,24 @@ static int read_termtype(int fd, TERMTYPE *ptr)
for (i = str_count; i < STRCOUNT; i++)
ptr->Strings[i] = ABSENT_STRING;
- return(1);
+ return (1);
}
-int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
+int
+_nc_read_file_entry(const char *const filename, TERMTYPE * ptr)
/* return 1 if read, 0 if not found or garbled */
{
int code, fd = -1;
#ifdef __OpenBSD__
if (_nc_read_bsd_terminfo_file(filename, ptr) == 1)
- return(1);
+ return (1);
#endif /* __OpenBSD__ */
if (_nc_access(filename, R_OK) < 0
- || (fd = open(filename, O_RDONLY|O_BINARY)) < 0) {
+ || (fd = open(filename, O_RDONLY | O_BINARY)) < 0) {
T(("cannot open terminfo %s (errno=%d)", filename, errno));
- return(0);
+ return (0);
}
T(("read terminfo %s", filename));
@@ -391,51 +404,54 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
* Build a terminfo pathname and try to read the data. Returns 1 on success,
* 0 on failure.
*/
-static int _nc_read_tic_entry(char *const filename,
- const char *const dir, const char *ttn, TERMTYPE *const tp)
+static int
+_nc_read_tic_entry(char *const filename,
+ const char *const dir, const char *ttn, TERMTYPE * const tp)
{
/* maximum safe length of terminfo root directory name */
#define MAX_TPATH (PATH_MAX - MAX_ALIAS - 6)
- if (strlen(dir) > MAX_TPATH)
- return 0;
- (void) sprintf(filename, "%s/%s", dir, ttn);
- return _nc_read_file_entry(filename, tp);
+ if (strlen(dir) > MAX_TPATH)
+ return 0;
+ (void) sprintf(filename, "%s/%s", dir, ttn);
+ return _nc_read_file_entry(filename, tp);
}
/*
* Process the list of :-separated directories, looking for the terminal type.
* We don't use strtok because it does not show us empty tokens.
*/
-static int _nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const ttn, TERMTYPE *const tp)
+static int
+_nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const
+ ttn, TERMTYPE * const tp)
{
- char *list, *a;
- const char *b;
- int code = 0;
-
- /* we'll modify the argument, so we must copy */
- if ((b = a = list = strdup(dirs)) == NULL)
- return(0);
-
- for (;;) {
- int c = *a;
- if (c == 0 || c == ':') {
- *a = 0;
- if ((b + 1) >= a)
- b = TERMINFO;
- if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) {
- code = 1;
- break;
- }
- b = a + 1;
- if (c == 0)
- break;
- }
- a++;
+ char *list, *a;
+ const char *b;
+ int code = 0;
+
+ /* we'll modify the argument, so we must copy */
+ if ((b = a = list = strdup(dirs)) == NULL)
+ return (0);
+
+ for (;;) {
+ int c = *a;
+ if (c == 0 || c == ':') {
+ *a = 0;
+ if ((b + 1) >= a)
+ b = TERMINFO;
+ if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) {
+ code = 1;
+ break;
+ }
+ b = a + 1;
+ if (c == 0)
+ break;
}
+ a++;
+ }
- free(list);
- return(code);
+ free(list);
+ return (code);
}
/*
@@ -447,49 +463,49 @@ static int _nc_read_terminfo_dirs(const char *dirs, char *const filename, const
* overrun the file buffer.
*/
-int _nc_read_entry(const char *const tn, char *const filename, TERMTYPE *const tp)
+int
+_nc_read_entry(const char *const tn, char *const filename, TERMTYPE * const tp)
{
-char *envp;
-char ttn[MAX_ALIAS + 3];
+ char *envp;
+ char ttn[MAX_ALIAS + 3];
#ifdef __OpenBSD__
- /* First check the BSD terminfo.db file */
- if (_nc_read_bsd_terminfo_entry(tn, filename, tp) == 1)
- return 1;
+ /* First check the BSD terminfo.db file */
+ if (_nc_read_bsd_terminfo_entry(tn, filename, tp) == 1)
+ return (1);
#endif /* __OpenBSD__ */
- /* truncate the terminal name to prevent dangerous buffer airline */
- (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn);
+ /* truncate the terminal name to prevent dangerous buffer airline */
+ (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn);
- /* This is System V behavior, in conjunction with our requirements for
- * writing terminfo entries.
- */
- if (have_tic_directory
- && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1)
- return 1;
+ /* This is System V behavior, in conjunction with our requirements for
+ * writing terminfo entries.
+ */
+ if (have_tic_directory
+ && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1)
+ return 1;
- if (!issetugid() && (envp = getenv("TERMINFO")) != 0
- && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1)
- return 1;
+ if (!issetugid() && (envp = getenv("TERMINFO")) != 0
+ && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1)
+ return 1;
- if ((envp = _nc_home_terminfo()) != 0) {
- if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) {
- return(1);
- }
+ if ((envp = _nc_home_terminfo()) != 0) {
+ if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) {
+ return (1);
}
+ }
- /* this is an ncurses extension */
- if (!issetugid() && (envp = getenv("TERMINFO_DIRS")) != 0)
- return _nc_read_terminfo_dirs(envp, filename, ttn, tp);
+ /* this is an ncurses extension */
+ if (!issetugid() && (envp = getenv("TERMINFO_DIRS")) != 0)
+ return _nc_read_terminfo_dirs(envp, filename, ttn, tp);
- /* Try the system directory. Note that the TERMINFO_DIRS value, if
- * defined by the configure script, begins with a ":", which will be
- * interpreted as TERMINFO.
- */
+ /* Try the system directory. Note that the TERMINFO_DIRS value, if
+ * defined by the configure script, begins with a ":", which will be
+ * interpreted as TERMINFO.
+ */
#ifdef TERMINFO_DIRS
- return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp);
+ return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp);
#else
- return _nc_read_tic_entry(filename, TERMINFO, ttn, tp);
+ return _nc_read_tic_entry(filename, TERMINFO, ttn, tp);
#endif
}
-
diff --git a/lib/libcurses/tinfo/write_entry.c b/lib/libcurses/tinfo/write_entry.c
index 60f95451505..fa91c603775 100644
--- a/lib/libcurses/tinfo/write_entry.c
+++ b/lib/libcurses/tinfo/write_entry.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: write_entry.c,v 1.5 1999/12/06 02:12:46 millert Exp $ */
+/* $OpenBSD: write_entry.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> *
****************************************************************************/
-
-
/*
* write_entry.c -- write a terminfo structure onto the file system
*/
@@ -53,28 +51,29 @@
#if 0
#define TRACE_OUT(p) DEBUG(2, p)
#else
-#define TRACE_OUT(p) /*nothing*/
+#define TRACE_OUT(p) /*nothing */
#endif
-MODULE_ID("$From: write_entry.c,v 1.48 1999/12/04 23:02:59 tom Exp $")
+MODULE_ID("$From: write_entry.c,v 1.50 2000/01/01 16:35:44 tom Exp $")
static int total_written;
static int write_object(FILE *, TERMTYPE *);
-static void write_file(char *filename, TERMTYPE *tp)
+static void
+write_file(char *filename, TERMTYPE * tp)
{
- FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0;
- if (fp == 0) {
- perror(filename);
- _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename);
- }
- DEBUG(1, ("Created %s", filename));
+ FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0;
+ if (fp == 0) {
+ perror(filename);
+ _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename);
+ }
+ DEBUG(1, ("Created %s", filename));
- if (write_object(fp, tp) == ERR) {
- _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename);
- }
- fclose(fp);
+ if (write_object(fp, tp) == ERR) {
+ _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename);
+ }
+ fclose(fp);
}
/*
@@ -82,36 +81,38 @@ static void write_file(char *filename, TERMTYPE *tp)
*
* Make a directory if it doesn't exist.
*/
-static int make_directory(const char *path)
+static int
+make_directory(const char *path)
{
-int rc;
-struct stat statbuf;
-char fullpath[PATH_MAX];
-const char *destination = _nc_tic_dir(0);
-
- if (path == destination || *path == '/') {
- if (strlen(path) + 1 > sizeof(fullpath))
- return(-1);
- (void)strcpy(fullpath, path);
- } else {
- if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath))
- return(-1);
- (void)sprintf(fullpath, "%s/%s", destination, path);
- }
+ int rc;
+ struct stat statbuf;
+ char fullpath[PATH_MAX];
+ const char *destination = _nc_tic_dir(0);
+
+ if (path == destination || *path == '/') {
+ if (strlen(path) + 1 > sizeof(fullpath))
+ return (-1);
+ (void) strcpy(fullpath, path);
+ } else {
+ if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath))
+ return (-1);
+ (void) sprintf(fullpath, "%s/%s", destination, path);
+ }
- if ((rc = stat(path, &statbuf)) < 0) {
- rc = mkdir(path, 0777);
- } else {
- if (_nc_access(path, R_OK|W_OK|X_OK) < 0) {
- rc = -1; /* permission denied */
- } else if (!(S_ISDIR(statbuf.st_mode))) {
- rc = -1; /* not a directory */
- }
+ if ((rc = stat(path, &statbuf)) < 0) {
+ rc = mkdir(path, 0777);
+ } else {
+ if (_nc_access(path, R_OK | W_OK | X_OK) < 0) {
+ rc = -1; /* permission denied */
+ } else if (!(S_ISDIR(statbuf.st_mode))) {
+ rc = -1; /* not a directory */
}
- return rc;
+ }
+ return rc;
}
-void _nc_set_writedir(char *dir)
+void
+_nc_set_writedir(char *dir)
/* set the write directory for compiled entries */
{
const char *destination;
@@ -123,15 +124,14 @@ void _nc_set_writedir(char *dir)
(void) _nc_tic_dir(getenv("TERMINFO"));
destination = _nc_tic_dir(0);
- if (make_directory(destination) < 0)
- {
- char *home = _nc_home_terminfo();
+ if (make_directory(destination) < 0) {
+ char *home = _nc_home_terminfo();
if (home != 0) {
destination = home;
if (make_directory(destination) < 0)
_nc_err_abort("%s: permission denied (errno %d)",
- destination, errno);
+ destination, errno);
}
}
@@ -140,7 +140,7 @@ void _nc_set_writedir(char *dir)
* *once only* per run.
*/
if (chdir(_nc_tic_dir(destination)) < 0
- || getcwd(actual, sizeof(actual)) == 0)
+ || getcwd(actual, sizeof(actual)) == 0)
_nc_err_abort("%s: not a directory", destination);
_nc_keep_tic_dir(strdup(actual));
}
@@ -157,27 +157,28 @@ void _nc_set_writedir(char *dir)
*
*/
-static void check_writeable(int code)
+static void
+check_writeable(int code)
{
-static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-static bool verified[sizeof(dirnames)];
+ static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ static bool verified[sizeof(dirnames)];
-char dir[2];
-char *s;
+ char dir[2];
+ char *s;
- if (code == 0 || (s = strchr(dirnames, code)) == 0)
- _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code);
+ if (code == 0 || (s = strchr(dirnames, code)) == 0)
+ _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code);
- if (verified[s-dirnames])
- return;
+ if (verified[s - dirnames])
+ return;
- dir[0] = code;
- dir[1] = '\0';
- if (make_directory(dir) < 0) {
- _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
- }
+ dir[0] = code;
+ dir[1] = '\0';
+ if (make_directory(dir) < 0) {
+ _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
+ }
- verified[s-dirnames] = TRUE;
+ verified[s - dirnames] = TRUE;
}
/*
@@ -202,163 +203,159 @@ char *s;
* _nc_curr_line is properly set before the write_entry() call.
*/
-void _nc_write_entry(TERMTYPE *const tp)
+void
+_nc_write_entry(TERMTYPE * const tp)
{
-struct stat statbuf;
-char name_list[MAX_TERMINFO_LENGTH];
-char *first_name, *other_names;
-char *ptr;
-char filename[PATH_MAX];
-char linkname[PATH_MAX];
+ struct stat statbuf;
+ char name_list[MAX_TERMINFO_LENGTH];
+ char *first_name, *other_names;
+ char *ptr;
+ char filename[PATH_MAX];
+ char linkname[PATH_MAX];
#if USE_SYMLINKS
-char symlinkname[PATH_MAX];
+ char symlinkname[PATH_MAX];
#endif /* USE_SYMLINKS */
-static int call_count;
-static time_t start_time; /* time at start of writes */
+ static int call_count;
+ static time_t start_time; /* time at start of writes */
- if (call_count++ == 0) {
- start_time = 0;
- }
+ if (call_count++ == 0) {
+ start_time = 0;
+ }
- (void) strcpy(name_list, tp->term_names);
- DEBUG(7, ("Name list = '%s'", name_list));
+ (void) strcpy(name_list, tp->term_names);
+ DEBUG(7, ("Name list = '%s'", name_list));
- first_name = name_list;
+ first_name = name_list;
- ptr = &name_list[strlen(name_list) - 1];
- other_names = ptr + 1;
+ ptr = &name_list[strlen(name_list) - 1];
+ other_names = ptr + 1;
- while (ptr > name_list && *ptr != '|')
- ptr--;
+ while (ptr > name_list && *ptr != '|')
+ ptr--;
- if (ptr != name_list) {
- *ptr = '\0';
+ if (ptr != name_list) {
+ *ptr = '\0';
- for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++)
- continue;
+ for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++)
+ continue;
- if (*ptr == '\0')
- other_names = ptr;
- else {
- *ptr = '\0';
- other_names = ptr + 1;
- }
+ if (*ptr == '\0')
+ other_names = ptr;
+ else {
+ *ptr = '\0';
+ other_names = ptr + 1;
}
+ }
- DEBUG(7, ("First name = '%s'", first_name));
- DEBUG(7, ("Other names = '%s'", other_names));
+ DEBUG(7, ("First name = '%s'", first_name));
+ DEBUG(7, ("Other names = '%s'", other_names));
- _nc_set_type(first_name);
+ _nc_set_type(first_name);
- if (strlen(first_name) > sizeof(filename)-3)
- _nc_warning("terminal name too long.");
+ if (strlen(first_name) > sizeof(filename) - 3)
+ _nc_warning("terminal name too long.");
- sprintf(filename, "%c/%s", first_name[0], first_name);
+ sprintf(filename, "%c/%s", first_name[0], first_name);
- /*
- * Has this primary name been written since the first call to
- * write_entry()? If so, the newer write will step on the older,
- * so warn the user.
- */
- if (start_time > 0 &&
- stat(filename, &statbuf) >= 0
- && statbuf.st_mtime >= start_time)
- {
- _nc_warning("name multiply defined.");
+ /*
+ * Has this primary name been written since the first call to
+ * write_entry()? If so, the newer write will step on the older,
+ * so warn the user.
+ */
+ if (start_time > 0 &&
+ stat(filename, &statbuf) >= 0
+ && statbuf.st_mtime >= start_time) {
+ _nc_warning("name multiply defined.");
+ }
+
+ check_writeable(first_name[0]);
+ write_file(filename, tp);
+
+ if (start_time == 0) {
+ if (stat(filename, &statbuf) < 0
+ || (start_time = statbuf.st_mtime) == 0) {
+ _nc_syserr_abort("error obtaining time from %s/%s",
+ _nc_tic_dir(0), filename);
}
+ }
+ while (*other_names != '\0') {
+ ptr = other_names++;
+ while (*other_names != '|' && *other_names != '\0')
+ other_names++;
- check_writeable(first_name[0]);
- write_file(filename, tp);
+ if (*other_names != '\0')
+ *(other_names++) = '\0';
- if (start_time == 0) {
- if (stat(filename, &statbuf) < 0
- || (start_time = statbuf.st_mtime) == 0) {
- _nc_syserr_abort("error obtaining time from %s/%s",
- _nc_tic_dir(0), filename);
- }
+ if (strlen(ptr) > sizeof(linkname) - 3) {
+ _nc_warning("terminal alias %s too long.", ptr);
+ continue;
}
- while (*other_names != '\0') {
- ptr = other_names++;
- while (*other_names != '|' && *other_names != '\0')
- other_names++;
-
- if (*other_names != '\0')
- *(other_names++) = '\0';
-
- if (strlen(ptr) > sizeof(linkname)-3) {
- _nc_warning("terminal alias %s too long.", ptr);
- continue;
- }
- if (strchr(ptr, '/') != 0) {
- _nc_warning("cannot link alias %s.", ptr);
- continue;
- }
-
- check_writeable(ptr[0]);
- sprintf(linkname, "%c/%s", ptr[0], ptr);
-
- if (strcmp(filename, linkname) == 0) {
- _nc_warning("self-synonym ignored");
- }
- else if (stat(linkname, &statbuf) >= 0 &&
- statbuf.st_mtime < start_time)
- {
- _nc_warning("alias %s multiply defined.", ptr);
- }
- else if (_nc_access(linkname, W_OK) == 0)
+ if (strchr(ptr, '/') != 0) {
+ _nc_warning("cannot link alias %s.", ptr);
+ continue;
+ }
+
+ check_writeable(ptr[0]);
+ sprintf(linkname, "%c/%s", ptr[0], ptr);
+
+ if (strcmp(filename, linkname) == 0) {
+ _nc_warning("self-synonym ignored");
+ } else if (stat(linkname, &statbuf) >= 0 &&
+ statbuf.st_mtime < start_time) {
+ _nc_warning("alias %s multiply defined.", ptr);
+ } else if (_nc_access(linkname, W_OK) == 0)
#if HAVE_LINK
- {
- int code;
+ {
+ int code;
#if USE_SYMLINKS
- strcpy(symlinkname, "../");
- strncat(symlinkname, filename, sizeof(symlinkname) - 4);
- symlinkname[sizeof(symlinkname) - 1] = '\0';
+ strcpy(symlinkname, "../");
+ strncat(symlinkname, filename, sizeof(symlinkname) - 4);
+ symlinkname[sizeof(symlinkname) - 1] = '\0';
#endif /* USE_SYMLINKS */
#if HAVE_REMOVE
- code = remove(linkname);
+ code = remove(linkname);
#else
- code = unlink(linkname);
+ code = unlink(linkname);
#endif
- if (code != 0 && errno == ENOENT)
- code = 0;
+ if (code != 0 && errno == ENOENT)
+ code = 0;
#if USE_SYMLINKS
- if (symlink(symlinkname, linkname) < 0)
+ if (symlink(symlinkname, linkname) < 0)
#else
- if (link(filename, linkname) < 0)
+ if (link(filename, linkname) < 0)
#endif /* USE_SYMLINKS */
- {
- /*
- * If there wasn't anything there, and we cannot
- * link to the target because it is the same as the
- * target, then the source must be on a filesystem
- * that uses caseless filenames, such as Win32, etc.
- */
- if (code == 0 && errno == EEXIST)
- _nc_warning("can't link %s to %s", filename, linkname);
- else if (code == 0 && errno == EPERM)
- write_file(linkname, tp);
- else
- _nc_syserr_abort("can't link %s to %s", filename, linkname);
- }
- else
- {
- DEBUG(1, ("Linked %s", linkname));
- }
- }
+ {
+ /*
+ * If there wasn't anything there, and we cannot
+ * link to the target because it is the same as the
+ * target, then the source must be on a filesystem
+ * that uses caseless filenames, such as Win32, etc.
+ */
+ if (code == 0 && errno == EEXIST)
+ _nc_warning("can't link %s to %s", filename, linkname);
+ else if (code == 0 && errno == EPERM)
+ write_file(linkname, tp);
+ else
+ _nc_syserr_abort("can't link %s to %s", filename, linkname);
+ } else {
+ DEBUG(1, ("Linked %s", linkname));
+ }
+ }
#else /* just make copies */
- write_file(linkname, tp);
+ write_file(linkname, tp);
#endif /* HAVE_LINK */
- }
+ }
}
-#undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */
+#undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */
#define HI(x) ((x) / 256)
#define LO(x) ((x) % 256)
#define LITTLE_ENDIAN(p, x) (p)[0] = LO(x), (p)[1] = HI(x)
#define WRITE_STRING(str) (fwrite(str, sizeof(char), strlen(str) + 1, fp) == strlen(str) + 1)
-static int compute_offsets(char **Strings, int strmax, short *offsets)
+static int
+compute_offsets(char **Strings, int strmax, short *offsets)
{
size_t nextfree = 0;
int i;
@@ -377,17 +374,18 @@ static int compute_offsets(char **Strings, int strmax, short *offsets)
return nextfree;
}
-static void convert_shorts(unsigned char *buf, short *Numbers, int count)
+static void
+convert_shorts(unsigned char *buf, short *Numbers, int count)
{
int i;
for (i = 0; i < count; i++) {
- if (Numbers[i] == -1) { /* HI/LO won't work */
- buf[2*i] = buf[2*i + 1] = 0377;
- } else if (Numbers[i] == -2) { /* HI/LO won't work */
- buf[2*i] = 0376;
- buf[2*i + 1] = 0377;
+ if (Numbers[i] == ABSENT_NUMERIC) { /* HI/LO won't work */
+ buf[2 * i] = buf[2 * i + 1] = 0377;
+ } else if (Numbers[i] == CANCELLED_NUMERIC) { /* HI/LO won't work */
+ buf[2 * i] = 0376;
+ buf[2 * i + 1] = 0377;
} else {
- LITTLE_ENDIAN(buf + 2*i, Numbers[i]);
+ LITTLE_ENDIAN(buf + 2 * i, Numbers[i]);
TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i]));
}
}
@@ -396,177 +394,181 @@ static void convert_shorts(unsigned char *buf, short *Numbers, int count)
#define even_boundary(value) \
((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1)
-static int write_object(FILE *fp, TERMTYPE *tp)
+static int
+write_object(FILE * fp, TERMTYPE * tp)
{
-char *namelist;
-size_t namelen, boolmax, nummax, strmax;
-char zero = '\0';
-size_t i;
-short nextfree;
-short offsets[MAX_ENTRY_SIZE/2];
-unsigned char buf[MAX_ENTRY_SIZE];
-unsigned last_bool = BOOLWRITE;
-unsigned last_num = NUMWRITE;
-unsigned last_str = STRWRITE;
+ char *namelist;
+ size_t namelen, boolmax, nummax, strmax;
+ char zero = '\0';
+ size_t i;
+ short nextfree;
+ short offsets[MAX_ENTRY_SIZE / 2];
+ unsigned char buf[MAX_ENTRY_SIZE];
+ unsigned last_bool = BOOLWRITE;
+ unsigned last_num = NUMWRITE;
+ unsigned last_str = STRWRITE;
#if NCURSES_XNAMES
- /*
- * Normally we limit the list of values to exclude the "obsolete"
- * capabilities. However, if we are accepting extended names, add
- * these as well, since they are used for supporting translation
- * to/from termcap.
- */
- if (_nc_user_definable) {
- last_bool = BOOLCOUNT;
- last_num = NUMCOUNT;
- last_str = STRCOUNT;
- }
+ /*
+ * Normally we limit the list of values to exclude the "obsolete"
+ * capabilities. However, if we are accepting extended names, add
+ * these as well, since they are used for supporting translation
+ * to/from termcap.
+ */
+ if (_nc_user_definable) {
+ last_bool = BOOLCOUNT;
+ last_num = NUMCOUNT;
+ last_str = STRCOUNT;
+ }
#endif
- namelist = tp->term_names;
- namelen = strlen(namelist) + 1;
+ namelist = tp->term_names;
+ namelen = strlen(namelist) + 1;
- boolmax = 0;
- for (i = 0; i < last_bool; i++) {
- if (tp->Booleans[i])
- boolmax = i+1;
- }
+ boolmax = 0;
+ for (i = 0; i < last_bool; i++) {
+ if (tp->Booleans[i])
+ boolmax = i + 1;
+ }
- nummax = 0;
- for (i = 0; i < last_num; i++) {
- if (tp->Numbers[i] != ABSENT_NUMERIC)
- nummax = i+1;
- }
+ nummax = 0;
+ for (i = 0; i < last_num; i++) {
+ if (tp->Numbers[i] != ABSENT_NUMERIC)
+ nummax = i + 1;
+ }
- strmax = 0;
- for (i = 0; i < last_str; i++) {
- if (tp->Strings[i] != ABSENT_STRING)
- strmax = i+1;
- }
+ strmax = 0;
+ for (i = 0; i < last_str; i++) {
+ if (tp->Strings[i] != ABSENT_STRING)
+ strmax = i + 1;
+ }
- nextfree = compute_offsets(tp->Strings, strmax, offsets);
+ nextfree = compute_offsets(tp->Strings, strmax, offsets);
- /* fill in the header */
- LITTLE_ENDIAN(buf, MAGIC);
- LITTLE_ENDIAN(buf+2, min(namelen, MAX_NAME_SIZE + 1));
- LITTLE_ENDIAN(buf+4, boolmax);
- LITTLE_ENDIAN(buf+6, nummax);
- LITTLE_ENDIAN(buf+8, strmax);
- LITTLE_ENDIAN(buf+10, nextfree);
+ /* fill in the header */
+ LITTLE_ENDIAN(buf, MAGIC);
+ LITTLE_ENDIAN(buf + 2, min(namelen, MAX_NAME_SIZE + 1));
+ LITTLE_ENDIAN(buf + 4, boolmax);
+ LITTLE_ENDIAN(buf + 6, nummax);
+ LITTLE_ENDIAN(buf + 8, strmax);
+ LITTLE_ENDIAN(buf + 10, nextfree);
- /* write out the header */
- TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp)));
- if (fwrite(buf, 12, 1, fp) != 1
- || fwrite(namelist, sizeof(char), namelen, fp) != namelen
- || fwrite(tp->Booleans, sizeof(char), boolmax, fp) != boolmax)
- return(ERR);
+ /* write out the header */
+ TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp)));
+ if (fwrite(buf, 12, 1, fp) != 1
+ || fwrite(namelist, sizeof(char), namelen, fp) != namelen
+ || fwrite(tp->Booleans, sizeof(char), boolmax, fp) != boolmax)
+ return (ERR);
- if (even_boundary(namelen+boolmax))
- return(ERR);
+ if (even_boundary(namelen + boolmax))
+ return (ERR);
- TRACE_OUT(("Numerics begin at %04lx", ftell(fp)));
+ TRACE_OUT(("Numerics begin at %04lx", ftell(fp)));
- /* the numerics */
- convert_shorts(buf, tp->Numbers, nummax);
- if (fwrite(buf, 2, nummax, fp) != nummax)
- return(ERR);
+ /* the numerics */
+ convert_shorts(buf, tp->Numbers, nummax);
+ if (fwrite(buf, 2, nummax, fp) != nummax)
+ return (ERR);
- TRACE_OUT(("String offsets begin at %04lx", ftell(fp)));
+ TRACE_OUT(("String offsets begin at %04lx", ftell(fp)));
- /* the string offsets */
- convert_shorts(buf, offsets, strmax);
- if (fwrite(buf, 2, strmax, fp) != strmax)
- return(ERR);
+ /* the string offsets */
+ convert_shorts(buf, offsets, strmax);
+ if (fwrite(buf, 2, strmax, fp) != strmax)
+ return (ERR);
- TRACE_OUT(("String table begins at %04lx", ftell(fp)));
+ TRACE_OUT(("String table begins at %04lx", ftell(fp)));
- /* the strings */
- for (i = 0; i < strmax; i++)
- if (VALID_STRING(tp->Strings[i]))
- if (!WRITE_STRING(tp->Strings[i]))
- return(ERR);
+ /* the strings */
+ for (i = 0; i < strmax; i++)
+ if (VALID_STRING(tp->Strings[i]))
+ if (!WRITE_STRING(tp->Strings[i]))
+ return (ERR);
#if NCURSES_XNAMES
- if (NUM_EXT_NAMES(tp)) {
- unsigned extcnt = NUM_EXT_NAMES(tp);
-
- if (even_boundary(nextfree))
- return(ERR);
-
- nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets);
- TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree));
- nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings);
- TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
- strmax = tp->ext_Strings + extcnt;
-
- /*
- * Write the extended header
- */
- LITTLE_ENDIAN(buf+0, tp->ext_Booleans);
- LITTLE_ENDIAN(buf+2, tp->ext_Numbers);
- LITTLE_ENDIAN(buf+4, tp->ext_Strings);
- LITTLE_ENDIAN(buf+6, strmax);
- LITTLE_ENDIAN(buf+8, nextfree);
- TRACE_OUT(("WRITE extended-header @%ld", ftell(fp)));
- if (fwrite(buf, 10, 1, fp) != 1)
- return(ERR);
-
- TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp)));
- if (tp->ext_Booleans
- && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char), tp->ext_Booleans, fp) != tp->ext_Booleans)
- return(ERR);
-
- if (even_boundary(tp->ext_Booleans))
- return(ERR);
-
- TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp)));
- if (tp->ext_Numbers) {
- convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers);
- if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers)
- return(ERR);
- }
+ if (NUM_EXT_NAMES(tp)) {
+ unsigned extcnt = NUM_EXT_NAMES(tp);
- /*
- * Convert the offsets for the ext_Strings and ext_Names tables,
- * in that order.
- */
- convert_shorts(buf, offsets, strmax);
- TRACE_OUT(("WRITE offsets @%ld", ftell(fp)));
- if (fwrite(buf, 2, strmax, fp) != strmax)
- return(ERR);
-
- /*
- * Write the string table after the offset tables so we do not
- * have to do anything about alignment.
- */
- for (i = 0; i < tp->ext_Strings; i++) {
- if (VALID_STRING(tp->Strings[i+STRCOUNT])) {
- TRACE_OUT(("WRITE ext_Strings[%d]=%s", i, _nc_visbuf(tp->Strings[i+STRCOUNT])));
- if (!WRITE_STRING(tp->Strings[i+STRCOUNT]))
- return(ERR);
- }
- }
+ if (even_boundary(nextfree))
+ return (ERR);
+
+ nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets);
+ TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree));
+ nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings);
+ TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
+ strmax = tp->ext_Strings + extcnt;
- /*
- * Write the extended names
- */
- for (i = 0; i < extcnt; i++) {
- TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i]));
- if (!WRITE_STRING(tp->ext_Names[i]))
- return(ERR);
+ /*
+ * Write the extended header
+ */
+ LITTLE_ENDIAN(buf + 0, tp->ext_Booleans);
+ LITTLE_ENDIAN(buf + 2, tp->ext_Numbers);
+ LITTLE_ENDIAN(buf + 4, tp->ext_Strings);
+ LITTLE_ENDIAN(buf + 6, strmax);
+ LITTLE_ENDIAN(buf + 8, nextfree);
+ TRACE_OUT(("WRITE extended-header @%ld", ftell(fp)));
+ if (fwrite(buf, 10, 1, fp) != 1)
+ return (ERR);
+
+ TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp)));
+ if (tp->ext_Booleans
+ && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char),
+ tp->ext_Booleans, fp) != tp->ext_Booleans)
+ return (ERR);
+
+ if (even_boundary(tp->ext_Booleans))
+ return (ERR);
+
+ TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp)));
+ if (tp->ext_Numbers) {
+ convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers);
+ if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers)
+ return (ERR);
+ }
+
+ /*
+ * Convert the offsets for the ext_Strings and ext_Names tables,
+ * in that order.
+ */
+ convert_shorts(buf, offsets, strmax);
+ TRACE_OUT(("WRITE offsets @%ld", ftell(fp)));
+ if (fwrite(buf, 2, strmax, fp) != strmax)
+ return (ERR);
+
+ /*
+ * Write the string table after the offset tables so we do not
+ * have to do anything about alignment.
+ */
+ for (i = 0; i < tp->ext_Strings; i++) {
+ if (VALID_STRING(tp->Strings[i + STRCOUNT])) {
+ TRACE_OUT(("WRITE ext_Strings[%d]=%s", i,
+ _nc_visbuf(tp->Strings[i + STRCOUNT])));
+ if (!WRITE_STRING(tp->Strings[i + STRCOUNT]))
+ return (ERR);
}
+ }
+ /*
+ * Write the extended names
+ */
+ for (i = 0; i < extcnt; i++) {
+ TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i]));
+ if (!WRITE_STRING(tp->ext_Names[i]))
+ return (ERR);
}
+
+ }
#endif /* NCURSES_XNAMES */
- total_written++;
- return(OK);
+ total_written++;
+ return (OK);
}
/*
* Returns the total number of entries written by this process
*/
-int _nc_tic_written(void)
+int
+_nc_tic_written(void)
{
- return total_written;
+ return total_written;
}
diff --git a/lib/libcurses/tty/lib_mvcur.c b/lib/libcurses/tty/lib_mvcur.c
index b3179275d1f..6c47e5fa408 100644
--- a/lib/libcurses/tty/lib_mvcur.c
+++ b/lib/libcurses/tty/lib_mvcur.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_mvcur.c,v 1.4 1999/11/28 17:49:54 millert Exp $ */
+/* $OpenBSD: lib_mvcur.c,v 1.5 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,7 +33,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
** lib_mvcur.c
**
@@ -155,13 +154,13 @@
#include <term.h>
#include <ctype.h>
-MODULE_ID("$From: lib_mvcur.c,v 1.60 1999/10/03 01:08:27 Alexander.V.Lukyanov Exp $")
+MODULE_ID("$From: lib_mvcur.c,v 1.62 2000/01/01 16:54:37 tom Exp $")
#define STRLEN(s) (s != 0) ? strlen(s) : 0
+#define CURRENT_ROW SP->_cursrow /* phys cursor row */
+#define CURRENT_COLUMN SP->_curscol /* phys cursor column */
#define CURRENT_ATTR SP->_current_attr /* current phys attribute */
-#define CURRENT_ROW SP->_cursrow /* phys cursor row */
-#define CURRENT_COLUMN SP->_curscol /* phys cursor column */
#define REAL_ATTR SP->_current_attr /* phys current attribute */
#define WANT_CHAR(y, x) SP->_newscr->_line[y].text[x] /* desired state */
#define BAUDRATE cur_term->_baudrate /* bits per second */
@@ -178,20 +177,21 @@ static float diff;
static int normalized_cost(const char *const cap, int affcnt);
#if !HAVE_STRSTR
-char * _nc_strstr(const char *haystack, const char *needle)
+char *
+_nc_strstr(const char *haystack, const char *needle)
{
- size_t len1 = strlen(haystack);
- size_t len2 = strlen(needle);
- char *result = 0;
-
- while ((len1 != 0) && (len1-- >= len2)) {
- if (!strncmp(haystack, needle, len2)) {
- result = haystack;
- break;
- }
- haystack++;
+ size_t len1 = strlen(haystack);
+ size_t len2 = strlen(needle);
+ char *result = 0;
+
+ while ((len1 != 0) && (len1-- >= len2)) {
+ if (!strncmp(haystack, needle, len2)) {
+ result = haystack;
+ break;
}
- return result;
+ haystack++;
+ }
+ return result;
}
#endif
@@ -205,18 +205,18 @@ char * _nc_strstr(const char *haystack, const char *needle)
static int
trace_cost_of(const char *capname, const char *cap, int affcnt)
{
- int result = _nc_msec_cost(cap,affcnt);
- TR(TRACE_CHARPUT|TRACE_MOVE, ("CostOf %s %d", capname, result));
- return result;
+ int result = _nc_msec_cost(cap, affcnt);
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("CostOf %s %d", capname, result));
+ return result;
}
#define CostOf(cap,affcnt) trace_cost_of(#cap,cap,affcnt);
static int
trace_normalized_cost(const char *capname, const char *cap, int affcnt)
{
- int result = normalized_cost(cap,affcnt);
- TR(TRACE_CHARPUT|TRACE_MOVE, ("NormalizedCost %s %d", capname, result));
- return result;
+ int result = normalized_cost(cap, affcnt);
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("NormalizedCost %s %d", capname, result));
+ return result;
}
#define NormalizedCost(cap,affcnt) trace_normalized_cost(#cap,cap,affcnt);
@@ -227,25 +227,22 @@ trace_normalized_cost(const char *capname, const char *cap, int affcnt)
#endif
-int _nc_msec_cost(const char *const cap, int affcnt)
+int
+_nc_msec_cost(const char *const cap, int affcnt)
/* compute the cost of a given operation */
{
if (cap == 0)
- return(INFINITY);
- else
- {
- const char *cp;
- float cum_cost = 0;
+ return (INFINITY);
+ else {
+ const char *cp;
+ float cum_cost = 0;
- for (cp = cap; *cp; cp++)
- {
+ for (cp = cap; *cp; cp++) {
/* extract padding, either mandatory or required */
- if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>'))
- {
- float number = 0;
+ if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>')) {
+ float number = 0;
- for (cp += 2; *cp != '>'; cp++)
- {
+ for (cp += 2; *cp != '>'; cp++) {
if (isdigit(*cp))
number = number * 10 + (*cp - '0');
else if (*cp == '*')
@@ -255,40 +252,40 @@ int _nc_msec_cost(const char *const cap, int affcnt)
}
cum_cost += number * 10;
- }
- else
+ } else
cum_cost += SP->_char_padding;
}
- return((int)cum_cost);
+ return ((int) cum_cost);
}
}
-static int normalized_cost(const char *const cap, int affcnt)
+static int
+normalized_cost(const char *const cap, int affcnt)
/* compute the effective character-count for an operation (round up) */
{
- int cost = _nc_msec_cost(cap, affcnt);
- if (cost != INFINITY)
- cost = (cost + SP->_char_padding - 1) / SP->_char_padding;
- return cost;
+ int cost = _nc_msec_cost(cap, affcnt);
+ if (cost != INFINITY)
+ cost = (cost + SP->_char_padding - 1) / SP->_char_padding;
+ return cost;
}
-static void reset_scroll_region(void)
+static void
+reset_scroll_region(void)
/* Set the scroll-region to a known state (the default) */
{
- if (change_scroll_region)
- {
+ if (change_scroll_region) {
TPUTS_TRACE("change_scroll_region");
putp(tparm(change_scroll_region, 0, screen_lines - 1));
}
}
-void _nc_mvcur_resume(void)
+void
+_nc_mvcur_resume(void)
/* what to do at initialization time and after each shellout */
{
/* initialize screen for cursor access */
- if (enter_ca_mode)
- {
+ if (enter_ca_mode) {
TPUTS_TRACE("enter_ca_mode");
putp(enter_ca_mode);
}
@@ -306,15 +303,15 @@ void _nc_mvcur_resume(void)
SP->_cursrow = SP->_curscol = -1;
/* restore cursor shape */
- if (SP->_cursor != -1)
- {
+ if (SP->_cursor != -1) {
int cursor = SP->_cursor;
SP->_cursor = -1;
- curs_set (cursor);
+ curs_set(cursor);
}
}
-void _nc_mvcur_init(void)
+void
+_nc_mvcur_init(void)
/* initialize the cost structure */
{
/*
@@ -323,15 +320,15 @@ void _nc_mvcur_init(void)
SP->_char_padding = (9 * 1000 * 10) / (BAUDRATE > 0 ? BAUDRATE : 9600);
if (SP->_char_padding <= 0)
SP->_char_padding = 1; /* must be nonzero */
- TR(TRACE_CHARPUT|TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding));
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding));
/* non-parameterized local-motion strings */
- SP->_cr_cost = CostOf(carriage_return, 0);
+ SP->_cr_cost = CostOf(carriage_return, 0);
SP->_home_cost = CostOf(cursor_home, 0);
- SP->_ll_cost = CostOf(cursor_to_ll, 0);
+ SP->_ll_cost = CostOf(cursor_to_ll, 0);
#if USE_HARD_TABS
- SP->_ht_cost = CostOf(tab, 0);
- SP->_cbt_cost = CostOf(back_tab, 0);
+ SP->_ht_cost = CostOf(tab, 0);
+ SP->_cbt_cost = CostOf(back_tab, 0);
#endif /* USE_HARD_TABS */
SP->_cub1_cost = CostOf(cursor_left, 0);
SP->_cuf1_cost = CostOf(cursor_right, 0);
@@ -359,7 +356,7 @@ void _nc_mvcur_init(void)
*
* (1) They never have * padding. In the entire master terminfo database
* as of March 1995, only the obsolete Zenith Z-100 pc violates this.
- * (Proportional padding is found mainly in insert, delete and scroll
+ * (Proportional padding is found mainly in insert, delete and scroll
* capabilities).
*
* (2) The average case of cup has two two-digit parameters. Strictly,
@@ -377,34 +374,34 @@ void _nc_mvcur_init(void)
* All these averages depend on the assumption that all parameter values
* are equally probable.
*/
- SP->_cup_cost = CostOf(tparm(SP->_address_cursor, 23, 23), 1);
- SP->_cub_cost = CostOf(tparm(parm_left_cursor, 23), 1);
- SP->_cuf_cost = CostOf(tparm(parm_right_cursor, 23), 1);
- SP->_cud_cost = CostOf(tparm(parm_down_cursor, 23), 1);
- SP->_cuu_cost = CostOf(tparm(parm_up_cursor, 23), 1);
- SP->_hpa_cost = CostOf(tparm(column_address, 23), 1);
- SP->_vpa_cost = CostOf(tparm(row_address, 23), 1);
+ SP->_cup_cost = CostOf(tparm(SP->_address_cursor, 23, 23), 1);
+ SP->_cub_cost = CostOf(tparm(parm_left_cursor, 23), 1);
+ SP->_cuf_cost = CostOf(tparm(parm_right_cursor, 23), 1);
+ SP->_cud_cost = CostOf(tparm(parm_down_cursor, 23), 1);
+ SP->_cuu_cost = CostOf(tparm(parm_up_cursor, 23), 1);
+ SP->_hpa_cost = CostOf(tparm(column_address, 23), 1);
+ SP->_vpa_cost = CostOf(tparm(row_address, 23), 1);
/* non-parameterized screen-update strings */
- SP->_ed_cost = NormalizedCost(clr_eos, 1);
- SP->_el_cost = NormalizedCost(clr_eol, 1);
- SP->_el1_cost = NormalizedCost(clr_bol, 1);
+ SP->_ed_cost = NormalizedCost(clr_eos, 1);
+ SP->_el_cost = NormalizedCost(clr_eol, 1);
+ SP->_el1_cost = NormalizedCost(clr_bol, 1);
SP->_dch1_cost = NormalizedCost(delete_character, 1);
SP->_ich1_cost = NormalizedCost(insert_character, 1);
/* parameterized screen-update strings */
- SP->_dch_cost = NormalizedCost(tparm(parm_dch, 23), 1);
- SP->_ich_cost = NormalizedCost(tparm(parm_ich, 23), 1);
- SP->_ech_cost = NormalizedCost(tparm(erase_chars, 23), 1);
- SP->_rep_cost = NormalizedCost(tparm(repeat_char, ' ', 23), 1);
+ SP->_dch_cost = NormalizedCost(tparm(parm_dch, 23), 1);
+ SP->_ich_cost = NormalizedCost(tparm(parm_ich, 23), 1);
+ SP->_ech_cost = NormalizedCost(tparm(erase_chars, 23), 1);
+ SP->_rep_cost = NormalizedCost(tparm(repeat_char, ' ', 23), 1);
SP->_cup_ch_cost = NormalizedCost(tparm(SP->_address_cursor, 23, 23), 1);
SP->_hpa_ch_cost = NormalizedCost(tparm(column_address, 23), 1);
/* pre-compute some capability lengths */
SP->_carriage_return_length = STRLEN(carriage_return);
- SP->_cursor_home_length = STRLEN(cursor_home);
- SP->_cursor_to_ll_length = STRLEN(cursor_to_ll);
+ SP->_cursor_home_length = STRLEN(cursor_home);
+ SP->_cursor_to_ll_length = STRLEN(cursor_to_ll);
/*
* If save_cursor is used within enter_ca_mode, we should not use it for
@@ -413,8 +410,8 @@ void _nc_mvcur_init(void)
* feature.
*/
if (save_cursor != 0
- && enter_ca_mode != 0
- && strstr(enter_ca_mode, save_cursor) != 0) {
+ && enter_ca_mode != 0
+ && strstr(enter_ca_mode, save_cursor) != 0) {
T(("...suppressed sc/rc capability due to conflict with smcup/rmcup"));
save_cursor = 0;
restore_cursor = 0;
@@ -428,7 +425,8 @@ void _nc_mvcur_init(void)
_nc_mvcur_resume();
}
-void _nc_mvcur_wrap(void)
+void
+_nc_mvcur_wrap(void)
/* wrap up cursor-addressing mode */
{
/* leave cursor at screen bottom */
@@ -438,8 +436,7 @@ void _nc_mvcur_wrap(void)
if (SP->_cursor != -1)
curs_set(1);
- if (exit_ca_mode)
- {
+ if (exit_ca_mode) {
TPUTS_TRACE("exit_ca_mode");
putp(exit_ca_mode);
}
@@ -464,24 +461,24 @@ void _nc_mvcur_wrap(void)
* Perform repeated-append, returning cost
*/
static inline int
-repeated_append (int total, int num, int repeat, char *dst, const char *src)
+repeated_append(int total, int num, int repeat, char *dst, const char *src)
{
- register size_t src_len = strlen(src);
- register size_t dst_len = STRLEN(dst);
-
- if ((dst_len + repeat * src_len) < OPT_SIZE-1) {
- total += (num * repeat);
- if (dst) {
- dst += dst_len;
- while (repeat-- > 0) {
- (void) strcpy(dst, src);
- dst += src_len;
- }
- }
- } else {
- total = INFINITY;
+ register size_t src_len = strlen(src);
+ register size_t dst_len = STRLEN(dst);
+
+ if ((dst_len + repeat * src_len) < OPT_SIZE - 1) {
+ total += (num * repeat);
+ if (dst) {
+ dst += dst_len;
+ while (repeat-- > 0) {
+ (void) strcpy(dst, src);
+ dst += src_len;
+ }
}
- return total;
+ } else {
+ total = INFINITY;
+ }
+ return total;
}
#ifndef NO_OPTIMIZE
@@ -496,56 +493,47 @@ repeated_append (int total, int num, int repeat, char *dst, const char *src)
/* Note: we'd like to inline this for speed, but GNU C barfs on the attempt. */
static int
-relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
+relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw)
/* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */
{
- int n, vcost = 0, hcost = 0;
+ int n, vcost = 0, hcost = 0;
if (result)
result[0] = '\0';
- if (to_y != from_y)
- {
+ if (to_y != from_y) {
vcost = INFINITY;
- if (row_address)
- {
+ if (row_address) {
if (result)
(void) strcpy(result, tparm(row_address, to_y));
vcost = SP->_vpa_cost;
}
- if (to_y > from_y)
- {
+ if (to_y > from_y) {
n = (to_y - from_y);
- if (parm_down_cursor && SP->_cud_cost < vcost)
- {
+ if (parm_down_cursor && SP->_cud_cost < vcost) {
if (result)
(void) strcpy(result, tparm(parm_down_cursor, n));
vcost = SP->_cud_cost;
}
- if (cursor_down && (n * SP->_cud1_cost < vcost))
- {
+ if (cursor_down && (n * SP->_cud1_cost < vcost)) {
if (result)
result[0] = '\0';
vcost = repeated_append(0, SP->_cud1_cost, n, result, cursor_down);
}
- }
- else /* (to_y < from_y) */
- {
+ } else { /* (to_y < from_y) */
n = (from_y - to_y);
- if (parm_up_cursor && SP->_cup_cost < vcost)
- {
+ if (parm_up_cursor && SP->_cup_cost < vcost) {
if (result)
(void) strcpy(result, tparm(parm_up_cursor, n));
vcost = SP->_cup_cost;
}
- if (cursor_up && (n * SP->_cuu1_cost < vcost))
- {
+ if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
if (result)
result[0] = '\0';
vcost = repeated_append(0, SP->_cuu1_cost, n, result, cursor_up);
@@ -553,53 +541,47 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
}
if (vcost == INFINITY)
- return(INFINITY);
+ return (INFINITY);
}
if (result)
result += strlen(result);
- if (to_x != from_x)
- {
- char str[OPT_SIZE];
+ if (to_x != from_x) {
+ char str[OPT_SIZE];
hcost = INFINITY;
- if (column_address)
- {
+ if (column_address) {
if (result)
(void) strcpy(result, tparm(column_address, to_x));
hcost = SP->_hpa_cost;
}
- if (to_x > from_x)
- {
+ if (to_x > from_x) {
n = to_x - from_x;
- if (parm_right_cursor && SP->_cuf_cost < hcost)
- {
+ if (parm_right_cursor && SP->_cuf_cost < hcost) {
if (result)
(void) strcpy(result, tparm(parm_right_cursor, n));
hcost = SP->_cuf_cost;
}
- if (cursor_right)
- {
- int lhcost = 0;
+ if (cursor_right) {
+ int lhcost = 0;
str[0] = '\0';
#if USE_HARD_TABS
/* use hard tabs, if we have them, to do as much as possible */
- if (init_tabs > 0 && tab)
- {
- int nxt, fr;
+ if (init_tabs > 0 && tab) {
+ int nxt, fr;
- for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt)
- {
- lhcost = repeated_append(lhcost, SP->_ht_cost, 1, str, tab);
+ for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) {
+ lhcost = repeated_append(lhcost, SP->_ht_cost, 1,
+ str, tab);
if (lhcost == INFINITY)
- break;
+ break;
}
n = to_x - fr;
@@ -616,11 +598,11 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
* screen.
*/
if (ovw
- && n > 0
- && vcost == 0
- && str[0] == '\0'
- && isdigit(TextOf(WANT_CHAR(to_y, from_x))))
- ovw = FALSE;
+ && n > 0
+ && vcost == 0
+ && str[0] == '\0'
+ && isdigit(TextOf(WANT_CHAR(to_y, from_x))))
+ ovw = FALSE;
#endif
/*
* If we have no attribute changes, overwrite is cheaper.
@@ -630,21 +612,18 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
* and the time the structure WANT_CHAR would access has been
* updated.
*/
- if (ovw)
- {
- int i;
+ if (ovw) {
+ int i;
for (i = 0; i < n; i++)
- if ((WANT_CHAR(to_y, from_x + i) & A_ATTRIBUTES) != CURRENT_ATTR)
- {
+ if ((WANT_CHAR(to_y, from_x + i) & A_ATTRIBUTES) != CURRENT_ATTR) {
ovw = FALSE;
break;
}
}
- if (ovw)
- {
- char *sp;
- int i;
+ if (ovw) {
+ char *sp;
+ int i;
sp = str + strlen(str);
@@ -652,48 +631,41 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
*sp++ = WANT_CHAR(to_y, from_x + i);
*sp = '\0';
lhcost += n * SP->_char_padding;
- }
- else
+ } else
#endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */
{
lhcost = repeated_append(lhcost, SP->_cuf1_cost, n, str, cursor_right);
}
- if (lhcost < hcost)
- {
+ if (lhcost < hcost) {
if (result)
(void) strcpy(result, str);
hcost = lhcost;
}
}
- }
- else /* (to_x < from_x) */
- {
+ } else { /* (to_x < from_x) */
n = from_x - to_x;
- if (parm_left_cursor && SP->_cub_cost < hcost)
- {
+ if (parm_left_cursor && SP->_cub_cost < hcost) {
if (result)
(void) strcpy(result, tparm(parm_left_cursor, n));
hcost = SP->_cub_cost;
}
- if (cursor_left)
- {
- int lhcost = 0;
+ if (cursor_left) {
+ int lhcost = 0;
str[0] = '\0';
#if USE_HARD_TABS
- if (init_tabs > 0 && back_tab)
- {
- int nxt, fr;
+ if (init_tabs > 0 && back_tab) {
+ int nxt, fr;
- for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt)
- {
- lhcost = repeated_append(lhcost, SP->_cbt_cost, 1, str, back_tab);
+ for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) {
+ lhcost = repeated_append(lhcost, SP->_cbt_cost, 1,
+ str, back_tab);
if (lhcost == INFINITY)
- break;
+ break;
}
n = fr - to_x;
@@ -702,8 +674,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
lhcost = repeated_append(lhcost, SP->_cub1_cost, n, str, cursor_left);
- if (lhcost < hcost)
- {
+ if (lhcost < hcost) {
if (result)
(void) strcpy(result, str);
hcost = lhcost;
@@ -712,10 +683,10 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
}
if (hcost == INFINITY)
- return(INFINITY);
+ return (INFINITY);
}
- return(vcost + hcost);
+ return (vcost + hcost);
}
#endif /* !NO_OPTIMIZE */
@@ -731,12 +702,12 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
*/
static inline int
-onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
+onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/* onscreen move from (yold, xold) to (ynew, xnew) */
{
- char use[OPT_SIZE], *sp;
- int tactic = 0, newcost, usecost = INFINITY;
- int t5_cr_cost;
+ char use[OPT_SIZE], *sp;
+ int tactic = 0, newcost, usecost = INFINITY;
+ int t5_cr_cost;
#if defined(MAIN) || defined(NCURSES_TEST)
struct timeval before, after;
@@ -746,8 +717,7 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
/* tactic #0: use direct cursor addressing */
sp = tparm(SP->_address_cursor, ynew, xnew);
- if (sp)
- {
+ if (sp) {
tactic = 0;
(void) strcpy(use, sp);
usecost = SP->_cup_cost;
@@ -765,11 +735,9 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
* (like, say, local-movement \n getting mapped to some obscure
* character because A_ALTCHARSET is on).
*/
- if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew))
- {
+ if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew)) {
#if defined(MAIN) || defined(NCURSES_TEST)
- if (!profiling)
- {
+ if (!profiling) {
(void) fputs("nonlocal\n", stderr);
goto nonlocal; /* always run the optimizer if profiling */
}
@@ -778,40 +746,36 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
#endif /* MAIN */
}
}
-
#ifndef NO_OPTIMIZE
/* tactic #1: use local movement */
if (yold != -1 && xold != -1
- && ((newcost=relative_move(NULL, yold, xold, ynew, xnew, ovw))!=INFINITY)
- && newcost < usecost)
- {
+ && ((newcost = relative_move(NULL, yold, xold, ynew, xnew, ovw)) != INFINITY)
+ && newcost < usecost) {
tactic = 1;
usecost = newcost;
}
/* tactic #2: use carriage-return + local movement */
if (yold != -1 && carriage_return
- && ((newcost=relative_move(NULL, yold,0,ynew,xnew, ovw)) != INFINITY)
- && SP->_cr_cost + newcost < usecost)
- {
+ && ((newcost = relative_move(NULL, yold, 0, ynew, xnew, ovw)) != INFINITY)
+ && SP->_cr_cost + newcost < usecost) {
tactic = 2;
usecost = SP->_cr_cost + newcost;
}
/* tactic #3: use home-cursor + local movement */
if (cursor_home
- && ((newcost=relative_move(NULL, 0, 0, ynew, xnew, ovw)) != INFINITY)
- && SP->_home_cost + newcost < usecost)
- {
+ && ((newcost = relative_move(NULL, 0, 0, ynew, xnew, ovw)) != INFINITY)
+ && SP->_home_cost + newcost < usecost) {
tactic = 3;
usecost = SP->_home_cost + newcost;
}
/* tactic #4: use home-down + local movement */
if (cursor_to_ll
- && ((newcost=relative_move(NULL, screen_lines-1, 0, ynew, xnew, ovw)) != INFINITY)
- && SP->_ll_cost + newcost < usecost)
- {
+ && ((newcost = relative_move(NULL, screen_lines - 1, 0, ynew, xnew,
+ ovw)) != INFINITY)
+ && SP->_ll_cost + newcost < usecost) {
tactic = 4;
usecost = SP->_ll_cost + newcost;
}
@@ -820,12 +784,12 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
* tactic #5: use left margin for wrap to right-hand side,
* unless strange wrap behavior indicated by xenl might hose us.
*/
- t5_cr_cost = (xold>0 ? SP->_cr_cost : 0);
+ t5_cr_cost = (xold > 0 ? SP->_cr_cost : 0);
if (auto_left_margin && !eat_newline_glitch
&& yold > 0 && cursor_left
- && ((newcost=relative_move(NULL, yold-1, screen_columns-1, ynew, xnew, ovw)) != INFINITY)
- && t5_cr_cost + SP->_cub1_cost + newcost < usecost)
- {
+ && ((newcost = relative_move(NULL, yold - 1, screen_columns - 1,
+ ynew, xnew, ovw)) != INFINITY)
+ && t5_cr_cost + SP->_cub1_cost + newcost < usecost) {
tactic = 5;
usecost = t5_cr_cost + SP->_cub1_cost + newcost;
}
@@ -833,36 +797,28 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
/*
* These cases are ordered by estimated relative frequency.
*/
- if (tactic)
- {
+ if (tactic) {
if (tactic == 1)
(void) relative_move(use, yold, xold, ynew, xnew, ovw);
- else if (tactic == 2)
- {
+ else if (tactic == 2) {
(void) strcpy(use, carriage_return);
(void) relative_move(use + SP->_carriage_return_length,
- yold,0,ynew,xnew, ovw);
- }
- else if (tactic == 3)
- {
+ yold, 0, ynew, xnew, ovw);
+ } else if (tactic == 3) {
(void) strcpy(use, cursor_home);
(void) relative_move(use + SP->_cursor_home_length,
- 0, 0, ynew, xnew, ovw);
- }
- else if (tactic == 4)
- {
+ 0, 0, ynew, xnew, ovw);
+ } else if (tactic == 4) {
(void) strcpy(use, cursor_to_ll);
(void) relative_move(use + SP->_cursor_to_ll_length,
- screen_lines-1, 0, ynew, xnew, ovw);
- }
- else /* if (tactic == 5) */
- {
+ screen_lines - 1, 0, ynew, xnew, ovw);
+ } else { /* if (tactic == 5) */
use[0] = '\0';
if (xold > 0)
(void) strcat(use, carriage_return);
(void) strcat(use, cursor_left);
(void) relative_move(use + strlen(use),
- yold-1, screen_columns-1, ynew, xnew, ovw);
+ yold - 1, screen_columns - 1, ynew, xnew, ovw);
}
}
#endif /* !NO_OPTIMIZE */
@@ -872,28 +828,28 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
diff = after.tv_usec - before.tv_usec
+ (after.tv_sec - before.tv_sec) * 1000000;
if (!profiling)
- (void) fprintf(stderr, "onscreen: %d msec, %f 28.8Kbps char-equivalents\n",
- (int)diff, diff/288);
+ (void) fprintf(stderr,
+ "onscreen: %d msec, %f 28.8Kbps char-equivalents\n",
+ (int) diff, diff / 288);
#endif /* MAIN */
- nonlocal:
- if (usecost != INFINITY)
- {
+ nonlocal:
+ if (usecost != INFINITY) {
TPUTS_TRACE("mvcur");
tputs(use, 1, _nc_outch);
- return(OK);
- }
- else
- return(ERR);
+ return (OK);
+ } else
+ return (ERR);
}
-int mvcur(int yold, int xold, int ynew, int xnew)
+int
+mvcur(int yold, int xold, int ynew, int xnew)
/* optimized cursor move from (yold, xold) to (ynew, xnew) */
{
TR(TRACE_MOVE, ("mvcur(%d,%d,%d,%d) called", yold, xold, ynew, xnew));
if (yold == ynew && xold == xnew)
- return(OK);
+ return (OK);
/*
* Most work here is rounding for terminal boundaries getting the
@@ -901,40 +857,33 @@ int mvcur(int yold, int xold, int ynew, int xnew)
* rolling up the screen to get ynew on the screen.
*/
- if (xnew >= screen_columns)
- {
+ if (xnew >= screen_columns) {
ynew += xnew / screen_columns;
xnew %= screen_columns;
}
- if (xold >= screen_columns)
- {
- int l;
+ if (xold >= screen_columns) {
+ int l;
l = (xold + 1) / screen_columns;
yold += l;
if (yold >= screen_lines)
- l -= (yold - screen_lines - 1);
+ l -= (yold - screen_lines - 1);
while (l > 0) {
- if (newline)
- {
- TPUTS_TRACE("newline");
- tputs(newline, 0, _nc_outch);
- }
- else
- putchar('\n');
- l--;
- if (xold > 0)
- {
- if (carriage_return)
- {
- TPUTS_TRACE("carriage_return");
- tputs(carriage_return, 0, _nc_outch);
- }
- else
- putchar('\r');
- xold = 0;
- }
+ if (newline) {
+ TPUTS_TRACE("newline");
+ tputs(newline, 0, _nc_outch);
+ } else
+ putchar('\n');
+ l--;
+ if (xold > 0) {
+ if (carriage_return) {
+ TPUTS_TRACE("carriage_return");
+ tputs(carriage_return, 0, _nc_outch);
+ } else
+ putchar('\r');
+ xold = 0;
+ }
}
}
@@ -944,7 +893,7 @@ int mvcur(int yold, int xold, int ynew, int xnew)
ynew = screen_lines - 1;
/* destination location is on screen now */
- return(onscreen_mvcur(yold, xold, ynew, xnew, TRUE));
+ return (onscreen_mvcur(yold, xold, ynew, xnew, TRUE));
}
#if defined(TRACE) || defined(NCURSES_TEST)
@@ -965,35 +914,51 @@ const char *_nc_progname = "mvcur";
static unsigned long xmits;
-int tputs(const char *string, int affcnt GCC_UNUSED, int (*outc)(int) GCC_UNUSED)
+/* these override lib_tputs.c */
+int
+tputs(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED)
/* stub tputs() that dumps sequences in a visible form */
{
if (profiling)
xmits += strlen(string);
else
(void) fputs(_nc_visbuf(string), stdout);
- return(OK);
+ return (OK);
}
-int putp(const char *string)
+int
+putp(const char *string)
{
- return(tputs(string, 1, _nc_outch));
+ return (tputs(string, 1, _nc_outch));
}
-int _nc_outch(int ch)
+int
+_nc_outch(int ch)
{
putc(ch, stdout);
return OK;
}
-static char tname[MAX_ALIAS];
+char PC = 0; /* used by termcap library */
+speed_t ospeed = 0; /* used by termcap library */
+int _nc_nulls_sent = 0; /* used by 'tack' program */
-static void load_term(void)
+int
+delay_output(int ms GCC_UNUSED)
+{
+ return OK;
+}
+
+static char tname[MAX_ALIAS];
+
+static void
+load_term(void)
{
(void) setupterm(tname, STDOUT_FILENO, NULL);
}
-static int roll(int n)
+static int
+roll(int n)
{
int i, j;
@@ -1003,7 +968,8 @@ static int roll(int n)
return (j % n);
}
-int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
+int
+main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
(void) strcpy(tname, termname());
load_term();
@@ -1018,30 +984,32 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
fputs("smcup:", stdout);
putchar('\n');
- for (;;)
- {
- int fy, fx, ty, tx, n, i;
- char buf[BUFSIZ], capname[BUFSIZ];
+ for (;;) {
+ int fy, fx, ty, tx, n, i;
+ char buf[BUFSIZ], capname[BUFSIZ];
(void) fputs("> ", stdout);
(void) fgets(buf, sizeof(buf), stdin);
- if (buf[0] == '?')
- {
-(void) puts("? -- display this help message");
-(void) puts("fy fx ty tx -- (4 numbers) display (fy,fx)->(ty,tx) move");
-(void) puts("s[croll] n t b m -- display scrolling sequence");
-(void) printf("r[eload] -- reload terminal info for %s\n", termname());
-(void) puts("l[oad] <term> -- load terminal info for type <term>");
-(void) puts("d[elete] <cap> -- delete named capability");
-(void) puts("i[nspect] -- display terminal capabilities");
-(void) puts("c[ost] -- dump cursor-optimization cost table");
-(void) puts("o[optimize] -- toggle movement optimization");
-(void) puts("t[orture] <num> -- torture-test with <num> random moves");
-(void) puts("q[uit] -- quit the program");
- }
- else if (sscanf(buf, "%d %d %d %d", &fy, &fx, &ty, &tx) == 4)
- {
+ if (buf[0] == '?') {
+ (void) puts("? -- display this help message");
+ (void)
+ puts("fy fx ty tx -- (4 numbers) display (fy,fx)->(ty,tx) move");
+ (void) puts("s[croll] n t b m -- display scrolling sequence");
+ (void)
+ printf("r[eload] -- reload terminal info for %s\n",
+ termname());
+ (void)
+ puts("l[oad] <term> -- load terminal info for type <term>");
+ (void) puts("d[elete] <cap> -- delete named capability");
+ (void) puts("i[nspect] -- display terminal capabilities");
+ (void)
+ puts("c[ost] -- dump cursor-optimization cost table");
+ (void) puts("o[optimize] -- toggle movement optimization");
+ (void)
+ puts("t[orture] <num> -- torture-test with <num> random moves");
+ (void) puts("q[uit] -- quit the program");
+ } else if (sscanf(buf, "%d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
struct timeval before, after;
putchar('"');
@@ -1051,10 +1019,9 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
gettimeofday(&after, NULL);
printf("\" (%ld msec)\n",
- (long)(after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000));
- }
- else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4)
- {
+ (long) (after.tv_usec - before.tv_usec + (after.tv_sec -
+ before.tv_sec) * 1000000));
+ } else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
struct timeval before, after;
putchar('"');
@@ -1064,66 +1031,53 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
gettimeofday(&after, NULL);
printf("\" (%ld msec)\n",
- (long)(after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000));
- }
- else if (buf[0] == 'r')
- {
+ (long) (after.tv_usec - before.tv_usec + (after.tv_sec -
+ before.tv_sec) * 1000000));
+ } else if (buf[0] == 'r') {
(void) strcpy(tname, termname());
load_term();
- }
- else if (sscanf(buf, "l %s", tname) == 1)
- {
+ } else if (sscanf(buf, "l %s", tname) == 1) {
load_term();
- }
- else if (sscanf(buf, "d %s", capname) == 1)
- {
- struct name_table_entry const *np = _nc_find_entry(capname,
- _nc_info_hash_table);
+ } else if (sscanf(buf, "d %s", capname) == 1) {
+ struct name_table_entry const *np = _nc_find_entry(capname,
+ _nc_info_hash_table);
if (np == NULL)
(void) printf("No such capability as \"%s\"\n", capname);
- else
- {
- switch(np->nte_type)
- {
+ else {
+ switch (np->nte_type) {
case BOOLEAN:
cur_term->type.Booleans[np->nte_index] = FALSE;
- (void) printf("Boolean capability `%s' (%d) turned off.\n",
- np->nte_name, np->nte_index);
+ (void)
+ printf("Boolean capability `%s' (%d) turned off.\n",
+ np->nte_name, np->nte_index);
break;
case NUMBER:
- cur_term->type.Numbers[np->nte_index] = -1;
+ cur_term->type.Numbers[np->nte_index] = ABSENT_NUMERIC;
(void) printf("Number capability `%s' (%d) set to -1.\n",
- np->nte_name, np->nte_index);
+ np->nte_name, np->nte_index);
break;
case STRING:
- cur_term->type.Strings[np->nte_index] = (char *)NULL;
+ cur_term->type.Strings[np->nte_index] = ABSENT_STRING;
(void) printf("String capability `%s' (%d) deleted.\n",
- np->nte_name, np->nte_index);
+ np->nte_name, np->nte_index);
break;
}
}
- }
- else if (buf[0] == 'i')
- {
- dump_init((char *)NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
- dump_entry(&cur_term->type, FALSE, TRUE, 0);
- putchar('\n');
- }
- else if (buf[0] == 'o')
- {
- if (_nc_optimize_enable & OPTIMIZE_MVCUR)
- {
- _nc_optimize_enable &=~ OPTIMIZE_MVCUR;
- (void) puts("Optimization is now off.");
- }
- else
- {
- _nc_optimize_enable |= OPTIMIZE_MVCUR;
- (void) puts("Optimization is now on.");
- }
+ } else if (buf[0] == 'i') {
+ dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
+ dump_entry(&cur_term->type, FALSE, TRUE, 0);
+ putchar('\n');
+ } else if (buf[0] == 'o') {
+ if (_nc_optimize_enable & OPTIMIZE_MVCUR) {
+ _nc_optimize_enable &= ~OPTIMIZE_MVCUR;
+ (void) puts("Optimization is now off.");
+ } else {
+ _nc_optimize_enable |= OPTIMIZE_MVCUR;
+ (void) puts("Optimization is now on.");
+ }
}
/*
* You can use the `t' test to profile and tune the movement
@@ -1144,16 +1098,15 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
* modes. As long as the optimized times are less, the optimizer
* is winning.
*/
- else if (sscanf(buf, "t %d", &n) == 1)
- {
+ else if (sscanf(buf, "t %d", &n) == 1) {
float cumtime = 0, perchar;
- int speeds[] = {2400, 9600, 14400, 19200, 28800, 38400, 0};
+ int speeds[] =
+ {2400, 9600, 14400, 19200, 28800, 38400, 0};
- srand((unsigned)(getpid() + time((time_t *)0)));
+ srand((unsigned) (getpid() + time((time_t *) 0)));
profiling = TRUE;
xmits = 0;
- for (i = 0; i < n; i++)
- {
+ for (i = 0; i < n; i++) {
/*
* This does a move test between two random locations,
* Random moves probably short-change the optimizer,
@@ -1184,10 +1137,9 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
perchar = cumtime / n;
(void) printf("%d moves (%ld chars) in %d msec, %f msec each:\n",
- n, xmits, (int)cumtime, perchar);
+ n, xmits, (int) cumtime, perchar);
- for (i = 0; speeds[i]; i++)
- {
+ for (i = 0; speeds[i]; i++) {
/*
* Total estimated time for the moves, computation and
* transmission both. Transmission time is an estimate
@@ -1202,12 +1154,11 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
*/
float overhead = speeds[i] * perchar / 1e6;
- (void) printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n",
- speeds[i], overhead, totalest);
+ (void)
+ printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n",
+ speeds[i], overhead, totalest);
}
- }
- else if (buf[0] == 'c')
- {
+ } else if (buf[0] == 'c') {
(void) printf("char padding: %d\n", SP->_char_padding);
(void) printf("cr cost: %d\n", SP->_cr_cost);
(void) printf("cup cost: %d\n", SP->_cup_cost);
@@ -1227,8 +1178,7 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
(void) printf("cuu cost: %d\n", SP->_cuu_cost);
(void) printf("hpa cost: %d\n", SP->_hpa_cost);
(void) printf("vpa cost: %d\n", SP->_vpa_cost);
- }
- else if (buf[0] == 'x' || buf[0] == 'q')
+ } else if (buf[0] == 'x' || buf[0] == 'q')
break;
else
(void) puts("Invalid command.");
@@ -1238,7 +1188,7 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
_nc_mvcur_wrap();
putchar('\n');
- return(0);
+ return (0);
}
#endif /* MAIN */