aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/ncurses/tty
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ncurses/ncurses/tty')
-rwxr-xr-xcontrib/ncurses/ncurses/tty/MKexpanded.sh6
-rw-r--r--contrib/ncurses/ncurses/tty/hashmap.c18
-rw-r--r--contrib/ncurses/ncurses/tty/lib_mvcur.c253
-rw-r--r--contrib/ncurses/ncurses/tty/lib_tstp.c12
-rw-r--r--contrib/ncurses/ncurses/tty/lib_twait.c213
-rw-r--r--contrib/ncurses/ncurses/tty/lib_vidattr.c72
-rw-r--r--contrib/ncurses/ncurses/tty/tty_display.h11
-rw-r--r--contrib/ncurses/ncurses/tty/tty_update.c639
8 files changed, 803 insertions, 421 deletions
diff --git a/contrib/ncurses/ncurses/tty/MKexpanded.sh b/contrib/ncurses/ncurses/tty/MKexpanded.sh
index 8e4a6c6c5f03..bf9acf21aa43 100755
--- a/contrib/ncurses/ncurses/tty/MKexpanded.sh
+++ b/contrib/ncurses/ncurses/tty/MKexpanded.sh
@@ -1,6 +1,6 @@
#! /bin/sh
##############################################################################
-# Copyright (c) 1998,2000 Free Software Foundation, Inc. #
+# Copyright (c) 1998-2000,2005 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 "Software"), #
@@ -29,7 +29,7 @@
#
# Author: Thomas E. Dickey <dickey@clark.net> 1997
#
-# $Id: MKexpanded.sh,v 1.10 2000/12/10 00:24:33 tom Exp $
+# $Id: MKexpanded.sh,v 1.11 2005/01/02 01:06:40 tom Exp $
#
# Script to generate 'expanded.c', a dummy source that contains functions
# corresponding to complex macros used in this library. By making functions,
@@ -84,7 +84,7 @@ NCURSES_EXPORT(int) _nc_InsCharCost (int count)
{
return InsCharCost(count);
}
-NCURSES_EXPORT(void) _nc_UpdateAttrs (chtype c)
+NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T c)
{
UpdateAttrs(c);
}
diff --git a/contrib/ncurses/ncurses/tty/hashmap.c b/contrib/ncurses/ncurses/tty/hashmap.c
index 1c30526069ba..1f482d4b6d0b 100644
--- a/contrib/ncurses/ncurses/tty/hashmap.c
+++ b/contrib/ncurses/ncurses/tty/hashmap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 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 *
@@ -70,7 +70,7 @@ AUTHOR
#include <curses.priv.h>
#include <term.h> /* for back_color_erase */
-MODULE_ID("$Id: hashmap.c,v 1.45 2001/12/19 01:06:49 tom Exp $")
+MODULE_ID("$Id: hashmap.c,v 1.49 2006/03/11 19:33:49 tom Exp $")
#ifdef HASHDEBUG
@@ -108,7 +108,9 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH];
#define HASH_VAL(ch) (ch)
#endif
-static inline unsigned long
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+
+static NCURSES_INLINE unsigned long
hash(NCURSES_CH_T * text)
{
int i;
@@ -140,10 +142,10 @@ update_cost_from_blank(NCURSES_CH_T * to)
{
int cost = 0;
int i;
- NCURSES_CH_T blank = NewChar2(BLANK_TEXT, BLANK_ATTR);
+ NCURSES_CH_T blank = blankchar;
if (back_color_erase)
- AddAttr(blank, (AttrOf(stdscr->_nc_bkgd) & A_COLOR));
+ SetPair(blank, GetPair(stdscr->_nc_bkgd));
for (i = TEXTWIDTH; i > 0; i--)
if (!(CharEq(blank, *to++)))
@@ -156,7 +158,7 @@ update_cost_from_blank(NCURSES_CH_T * to)
* Returns true when moving line 'from' to line 'to' seems to be cost
* effective. 'blank' indicates whether the line 'to' would become blank.
*/
-static inline bool
+static NCURSES_INLINE bool
cost_effective(const int from, const int to, const bool blank)
{
int new_from;
@@ -294,9 +296,9 @@ _nc_hash_map(void)
} else {
/* re-hash all */
if (oldhash == 0)
- oldhash = typeCalloc(unsigned long, screen_lines);
+ oldhash = typeCalloc(unsigned long, (unsigned) screen_lines);
if (newhash == 0)
- newhash = typeCalloc(unsigned long, screen_lines);
+ newhash = typeCalloc(unsigned long, (unsigned) screen_lines);
if (!oldhash || !newhash)
return; /* malloc failure */
for (i = 0; i < screen_lines; i++) {
diff --git a/contrib/ncurses/ncurses/tty/lib_mvcur.c b/contrib/ncurses/ncurses/tty/lib_mvcur.c
index 89b503f4aee6..4c0ef4a27e3e 100644
--- a/contrib/ncurses/ncurses/tty/lib_mvcur.c
+++ b/contrib/ncurses/ncurses/tty/lib_mvcur.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 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 *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -108,7 +109,9 @@
* LONG_DIST and (b) further inward from the right or left edge than LONG_DIST,
* we'll consider nonlocal.
*/
-#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) && (tx < screen_lines - 1 - LONG_DIST) && (abs(ty-fy) + abs(tx-fx) > LONG_DIST))
+#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) \
+ && (tx < screen_columns - 1 - LONG_DIST) \
+ && (abs(ty-fy) + abs(tx-fx) > LONG_DIST))
/****************************************************************************
*
@@ -152,12 +155,8 @@
#include <term.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_mvcur.c,v 1.85 2001/06/03 01:48:29 skimo Exp $")
+MODULE_ID("$Id: lib_mvcur.c,v 1.107 2006/11/25 22:31:59 tom Exp $")
-#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 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 */
@@ -258,7 +257,7 @@ reset_scroll_region(void)
{
if (change_scroll_region) {
TPUTS_TRACE("change_scroll_region");
- putp(tparm(change_scroll_region, 0, screen_lines - 1));
+ putp(TPARM_2(change_scroll_region, 0, screen_lines - 1));
}
}
@@ -296,10 +295,11 @@ NCURSES_EXPORT(void)
_nc_mvcur_init(void)
/* initialize the cost structure */
{
- /*
- * 9 = 7 bits + 1 parity + 1 stop.
- */
- SP->_char_padding = (9 * 1000 * 10) / (BAUDRATE > 0 ? BAUDRATE : 9600);
+ if (isatty(fileno(SP->_ofp)))
+ SP->_char_padding = ((BAUDBYTE * 1000 * 10)
+ / (BAUDRATE > 0 ? BAUDRATE : 9600));
+ else
+ SP->_char_padding = 1; /* must be nonzero */
if (SP->_char_padding <= 0)
SP->_char_padding = 1; /* must be nonzero */
TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding));
@@ -309,8 +309,13 @@ _nc_mvcur_init(void)
SP->_home_cost = CostOf(cursor_home, 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);
+ if (getenv("NCURSES_NO_HARD_TABS") == 0) {
+ SP->_ht_cost = CostOf(tab, 0);
+ SP->_cbt_cost = CostOf(back_tab, 0);
+ } else {
+ SP->_ht_cost = INFINITY;
+ SP->_cbt_cost = INFINITY;
+ }
#endif /* USE_HARD_TABS */
SP->_cub1_cost = CostOf(cursor_left, 0);
SP->_cuf1_cost = CostOf(cursor_right, 0);
@@ -356,13 +361,13 @@ _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_2(SP->_address_cursor, 23, 23), 1);
+ SP->_cub_cost = CostOf(TPARM_1(parm_left_cursor, 23), 1);
+ SP->_cuf_cost = CostOf(TPARM_1(parm_right_cursor, 23), 1);
+ SP->_cud_cost = CostOf(TPARM_1(parm_down_cursor, 23), 1);
+ SP->_cuu_cost = CostOf(TPARM_1(parm_up_cursor, 23), 1);
+ SP->_hpa_cost = CostOf(TPARM_1(column_address, 23), 1);
+ SP->_vpa_cost = CostOf(TPARM_1(row_address, 23), 1);
/* non-parameterized screen-update strings */
SP->_ed_cost = NormalizedCost(clr_eos, 1);
@@ -371,15 +376,22 @@ _nc_mvcur_init(void)
SP->_dch1_cost = NormalizedCost(delete_character, 1);
SP->_ich1_cost = NormalizedCost(insert_character, 1);
+ /*
+ * If this is a bce-terminal, we want to bias the choice so we use clr_eol
+ * rather than spaces at the end of a line.
+ */
+ if (back_color_erase)
+ SP->_el_cost = 0;
+
/* 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->_cup_ch_cost = NormalizedCost(tparm(SP->_address_cursor, 23, 23), 1);
- SP->_hpa_ch_cost = NormalizedCost(tparm(column_address, 23), 1);
- SP->_cuf_ch_cost = NormalizedCost(tparm(parm_right_cursor, 23), 1);
+ SP->_dch_cost = NormalizedCost(TPARM_1(parm_dch, 23), 1);
+ SP->_ich_cost = NormalizedCost(TPARM_1(parm_ich, 23), 1);
+ SP->_ech_cost = NormalizedCost(TPARM_1(erase_chars, 23), 1);
+ SP->_rep_cost = NormalizedCost(TPARM_2(repeat_char, ' ', 23), 1);
+
+ SP->_cup_ch_cost = NormalizedCost(TPARM_2(SP->_address_cursor, 23, 23), 1);
+ SP->_hpa_ch_cost = NormalizedCost(TPARM_1(column_address, 23), 1);
+ SP->_cuf_ch_cost = NormalizedCost(TPARM_1(parm_right_cursor, 23), 1);
SP->_inline_cost = min(SP->_cup_ch_cost,
min(SP->_hpa_ch_cost,
SP->_cuf_ch_cost));
@@ -441,7 +453,7 @@ _nc_mvcur_wrap(void)
/*
* Perform repeated-append, returning cost
*/
-static inline int
+static NCURSES_INLINE int
repeated_append(string_desc * target, int total, int num, int repeat, const char *src)
{
size_t need = repeat * strlen(src);
@@ -484,7 +496,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
vcost = INFINITY;
if (row_address != 0
- && _nc_safe_strcat(target, tparm(row_address, to_y))) {
+ && _nc_safe_strcat(target, TPARM_1(row_address, to_y))) {
vcost = SP->_vpa_cost;
}
@@ -494,7 +506,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
if (parm_down_cursor
&& SP->_cud_cost < vcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
- tparm(parm_down_cursor, n))) {
+ TPARM_1(parm_down_cursor, n))) {
vcost = SP->_cud_cost;
}
@@ -508,10 +520,10 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
n = (from_y - to_y);
if (parm_up_cursor
- && SP->_cup_cost < vcost
+ && SP->_cuu_cost < vcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
- tparm(parm_up_cursor, n))) {
- vcost = SP->_cup_cost;
+ TPARM_1(parm_up_cursor, n))) {
+ vcost = SP->_cuu_cost;
}
if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
@@ -534,7 +546,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
if (column_address
&& _nc_safe_strcat(_nc_str_copy(target, &save),
- tparm(column_address, to_x))) {
+ TPARM_1(column_address, to_x))) {
hcost = SP->_hpa_cost;
}
@@ -544,7 +556,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
if (parm_right_cursor
&& SP->_cuf_cost < hcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
- tparm(parm_right_cursor, n))) {
+ TPARM_1(parm_right_cursor, n))) {
hcost = SP->_cuf_cost;
}
@@ -570,7 +582,6 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
}
#endif /* USE_HARD_TABS */
-#if defined(REAL_ATTR) && defined(WANT_CHAR)
if (n <= 0 || n >= (int) check.s_size)
ovw = FALSE;
#if BSD_TPUTS
@@ -584,9 +595,11 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
&& n > 0
&& n < (int) check.s_size
&& vcost == 0
- && str[0] == '\0'
- && isdigit(CharOf(WANT_CHAR(to_y, from_x))))
- ovw = FALSE;
+ && str[0] == '\0') {
+ int wanted = CharOf(WANT_CHAR(to_y, from_x));
+ if (is8bits(wanted) && isdigit(wanted))
+ ovw = FALSE;
+ }
#endif
/*
* If we have no attribute changes, overwrite is cheaper.
@@ -601,7 +614,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
for (i = 0; i < n; i++) {
NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i);
- if (AttrOf(ch) != CURRENT_ATTR
+ if (!SameAttrOf(ch, SCREEN_ATTRS(SP))
#if USE_WIDEC_SUPPORT
|| !Charable(ch)
#endif
@@ -619,9 +632,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
*check.s_tail = '\0';
check.s_size -= n;
lhcost += n * SP->_char_padding;
- } else
-#endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */
- {
+ } else {
lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost,
n, cursor_right);
}
@@ -637,7 +648,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
if (parm_left_cursor
&& SP->_cub_cost < hcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
- tparm(parm_left_cursor, n))) {
+ TPARM_1(parm_left_cursor, n))) {
hcost = SP->_cub_cost;
}
@@ -689,7 +700,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
* the simpler method below.
*/
-static inline int
+static NCURSES_INLINE int
onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/* onscreen move from (yold, xold) to (ynew, xnew) */
{
@@ -708,7 +719,7 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
#define InitResult _nc_str_init(&result, buffer, sizeof(buffer))
/* tactic #0: use direct cursor addressing */
- if (_nc_safe_strcpy(InitResult, tparm(SP->_address_cursor, ynew, xnew))) {
+ if (_nc_safe_strcpy(InitResult, TPARM_2(SP->_address_cursor, ynew, xnew))) {
tactic = 0;
usecost = SP->_cup_cost;
@@ -817,20 +828,22 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
}
#endif /* !NO_OPTIMIZE */
+ nonlocal:
#if defined(MAIN) || defined(NCURSES_TEST)
gettimeofday(&after, NULL);
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",
+ "onscreen: %d microsec, %f 28.8Kbps char-equivalents\n",
(int) diff, diff / 288);
#endif /* MAIN */
- nonlocal:
if (usecost != INFINITY) {
TPUTS_TRACE("mvcur");
tputs(buffer, 1, _nc_outch);
+ SP->_cursrow = ynew;
+ SP->_curscol = xnew;
return (OK);
} else
return (ERR);
@@ -840,72 +853,101 @@ NCURSES_EXPORT(int)
mvcur(int yold, int xold, int ynew, int xnew)
/* optimized cursor move from (yold, xold) to (ynew, xnew) */
{
+ NCURSES_CH_T oldattr;
+ int code;
+
TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
yold, xold, ynew, xnew));
- if (SP == 0)
- returnCode(ERR);
+ if (SP == 0) {
+ code = ERR;
+ } else if (yold == ynew && xold == xnew) {
+ code = OK;
+ } else {
- if (yold == ynew && xold == xnew)
- returnCode(OK);
+ /*
+ * Most work here is rounding for terminal boundaries getting the
+ * column position implied by wraparound or the lack thereof and
+ * rolling up the screen to get ynew on the screen.
+ */
+ if (xnew >= screen_columns) {
+ ynew += xnew / screen_columns;
+ xnew %= screen_columns;
+ }
- /*
- * Most work here is rounding for terminal boundaries getting the
- * column position implied by wraparound or the lack thereof and
- * rolling up the screen to get ynew on the screen.
- */
+ /*
+ * Force restore even if msgr is on when we're in an alternate
+ * character set -- these have a strong tendency to screw up the CR &
+ * LF used for local character motions!
+ */
+ oldattr = SCREEN_ATTRS(SP);
+ if ((AttrOf(oldattr) & A_ALTCHARSET)
+ || (AttrOf(oldattr) && !move_standout_mode)) {
+ TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
+ (unsigned long) AttrOf(oldattr),
+ _traceattr(AttrOf(oldattr))));
+ (void) VIDATTR(A_NORMAL, 0);
+ }
- if (xnew >= screen_columns) {
- ynew += xnew / screen_columns;
- xnew %= screen_columns;
- }
- if (xold >= screen_columns) {
- int l;
-
- if (SP->_nl) {
- l = (xold + 1) / screen_columns;
- yold += l;
- if (yold >= screen_lines)
- 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 (xold >= screen_columns) {
+ int l;
+
+ if (SP->_nl) {
+ l = (xold + 1) / screen_columns;
+ yold += l;
+ if (yold >= screen_lines)
+ l -= (yold - screen_lines - 1);
+
+ if (l > 0) {
if (carriage_return) {
TPUTS_TRACE("carriage_return");
- tputs(carriage_return, 0, _nc_outch);
+ putp(carriage_return);
} else
- putchar('\r');
+ _nc_outch('\r');
xold = 0;
+
+ while (l > 0) {
+ if (newline) {
+ TPUTS_TRACE("newline");
+ putp(newline);
+ } else
+ _nc_outch('\n');
+ l--;
+ }
}
+ } else {
+ /*
+ * If caller set nonl(), we cannot really use newlines to
+ * position to the next row.
+ */
+ xold = -1;
+ yold = -1;
}
- } else {
- /*
- * If caller set nonl(), we cannot really use newlines to position
- * to the next row.
- */
- xold = -1;
- yold = -1;
}
- }
- if (yold > screen_lines - 1)
- yold = screen_lines - 1;
- if (ynew > screen_lines - 1)
- ynew = screen_lines - 1;
+ if (yold > screen_lines - 1)
+ yold = screen_lines - 1;
+ if (ynew > screen_lines - 1)
+ ynew = screen_lines - 1;
+
+ /* destination location is on screen now */
+ code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE);
- /* destination location is on screen now */
- returnCode(onscreen_mvcur(yold, xold, ynew, xnew, TRUE));
+ /*
+ * Restore attributes if we disabled them before moving.
+ */
+ if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) {
+ TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move",
+ (unsigned long) AttrOf(oldattr),
+ _traceattr(AttrOf(oldattr))));
+ (void) VIDATTR(AttrOf(oldattr), GetPair(oldattr));
+ }
+ }
+ returnCode(code);
}
#if defined(TRACE) || defined(NCURSES_TEST)
-NCURSES_EXPORT_VAR(int)
-_nc_optimize_enable = OPTIMIZE_ALL;
+NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL;
#endif
#if defined(MAIN) || defined(NCURSES_TEST)
@@ -918,10 +960,9 @@ _nc_optimize_enable = OPTIMIZE_ALL;
#include <tic.h>
#include <dump_entry.h>
-NCURSES_EXPORT_VAR(const char *)
-_nc_progname = "mvcur";
+NCURSES_EXPORT_VAR(const char *) _nc_progname = "mvcur";
- static unsigned long xmits;
+static unsigned long xmits;
/* these override lib_tputs.c */
NCURSES_EXPORT(int)
@@ -948,17 +989,13 @@ _nc_outch(int ch)
return OK;
}
-NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */
-NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */
-NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */
-
NCURSES_EXPORT(int)
delay_output(int ms GCC_UNUSED)
{
return OK;
}
-static char tname[MAX_ALIAS];
+static char tname[PATH_MAX];
static void
load_term(void)
@@ -982,7 +1019,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
(void) strcpy(tname, termname());
load_term();
- _nc_setupscreen(lines, columns, stdout);
+ _nc_setupscreen(lines, columns, stdout, FALSE, 0);
baudrate();
_nc_mvcur_init();
@@ -1079,7 +1116,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
}
} else if (buf[0] == 'i') {
dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
- dump_entry(&cur_term->type, FALSE, TRUE, 0);
+ dump_entry(&cur_term->type, FALSE, TRUE, 0, 0, 0);
putchar('\n');
} else if (buf[0] == 'o') {
if (_nc_optimize_enable & OPTIMIZE_MVCUR) {
diff --git a/contrib/ncurses/ncurses/tty/lib_tstp.c b/contrib/ncurses/ncurses/tty/lib_tstp.c
index c850e41da2c2..4c9f9fbaf1b7 100644
--- a/contrib/ncurses/ncurses/tty/lib_tstp.c
+++ b/contrib/ncurses/ncurses/tty/lib_tstp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2006 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 *
@@ -29,7 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
- * and: Thomas Dickey 1995-2001 *
+ * and: Thomas E. Dickey 1995-on *
****************************************************************************/
/*
@@ -46,7 +46,7 @@
#define _POSIX_SOURCE
#endif
-MODULE_ID("$Id: lib_tstp.c,v 1.30 2002/05/18 19:55:38 tom Exp $")
+MODULE_ID("$Id: lib_tstp.c,v 1.32 2006/04/01 19:31:34 tom Exp $")
#if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC)
#define USE_SIGTSTP 1
@@ -277,11 +277,7 @@ cleanup(int sig)
static void
sigwinch(int sig GCC_UNUSED)
{
- SCREEN *scan = _nc_screen_chain;
- while (scan) {
- scan->_sig_winch = TRUE;
- scan = scan->_next_screen;
- }
+ _nc_handle_sigwinch(-1);
}
#endif /* USE_SIGWINCH */
diff --git a/contrib/ncurses/ncurses/tty/lib_twait.c b/contrib/ncurses/ncurses/tty/lib_twait.c
index 9829a7eec8ef..28e503f331f6 100644
--- a/contrib/ncurses/ncurses/tty/lib_twait.c
+++ b/contrib/ncurses/ncurses/tty/lib_twait.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2004,2006 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 *
@@ -61,7 +61,7 @@
# endif
#endif
-MODULE_ID("$Id: lib_twait.c,v 1.44 2002/04/21 21:06:29 tom Exp $")
+MODULE_ID("$Id: lib_twait.c,v 1.51 2006/05/27 21:57:43 tom Exp $")
static long
_nc_gettime(bool first)
@@ -75,9 +75,16 @@ _nc_gettime(bool first)
gettimeofday(&t1, (struct timezone *) 0);
if (first) {
t0 = t1;
+ res = 0;
+ } else {
+ /* .tv_sec and .tv_usec are unsigned, be careful when subtracting */
+ if (t0.tv_usec > t1.tv_usec) { /* Convert 1s in 1e6 microsecs */
+ t1.tv_usec += 1000000;
+ t1.tv_sec--;
+ }
+ res = (t1.tv_sec - t0.tv_sec) * 1000
+ + (t1.tv_usec - t0.tv_usec) / 1000;
}
- res = (t1.tv_sec - t0.tv_sec) * 1000
- + (t1.tv_usec - t0.tv_usec) / 1000;
#else
# define PRECISE_GETTIME 0
static time_t t0;
@@ -91,6 +98,29 @@ _nc_gettime(bool first)
return res;
}
+#ifdef NCURSES_WGETCH_EVENTS
+NCURSES_EXPORT(int)
+_nc_eventlist_timeout(_nc_eventlist * evl)
+{
+ int event_delay = -1;
+ int n;
+
+ if (evl != 0) {
+
+ for (n = 0; n < evl->count; ++n) {
+ _nc_event *ev = evl->events[n];
+
+ if (ev->type == _NC_EVENT_TIMEOUT_MSEC) {
+ event_delay = ev->data.timeout_msec;
+ if (event_delay < 0)
+ event_delay = INT_MAX; /* FIXME Is this defined? */
+ }
+ }
+ }
+ return event_delay;
+}
+#endif /* NCURSES_WGETCH_EVENTS */
+
/*
* Wait a specified number of milliseconds, returning nonzero if the timer
* didn't expire before there is activity on the specified file descriptors.
@@ -99,21 +129,35 @@ _nc_gettime(bool first)
* 1 - ncurses' normal input-descriptor
* 2 - mouse descriptor, if any
* 3 - either input or mouse.
+ *
+ * Experimental: if NCURSES_WGETCH_EVENTS is defined, (mode & 4) determines
+ * whether to pay attention to evl argument. If set, the smallest of
+ * millisecond and of timeout of evl is taken.
+ *
* We return a mask that corresponds to the mode (e.g., 2 for mouse activity).
*
* If the milliseconds given are -1, the wait blocks until activity on the
* descriptors.
*/
NCURSES_EXPORT(int)
-_nc_timed_wait(int mode, int milliseconds, int *timeleft)
+_nc_timed_wait(int mode,
+ int milliseconds,
+ int *timeleft
+ EVENTLIST_2nd(_nc_eventlist * evl))
{
int fd;
int count;
-
int result;
+#ifdef NCURSES_WGETCH_EVENTS
+ int timeout_is_event = 0;
+ int n;
+#endif
+
#if USE_FUNC_POLL
- struct pollfd fds[2];
+#define MIN_FDS 2
+ struct pollfd fd_list[MIN_FDS];
+ struct pollfd *fds = fd_list;
#elif defined(__BEOS__)
#elif HAVE_SELECT
static fd_set set;
@@ -121,11 +165,21 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
long starttime, returntime;
- if (milliseconds < 0)
- milliseconds = 0;
TR(TRACE_IEVENT, ("start twait: %d milliseconds, mode: %d",
milliseconds, mode));
+#ifdef NCURSES_WGETCH_EVENTS
+ if (mode & 4) {
+ int event_delay = _nc_eventlist_timeout(evl);
+
+ if (event_delay >= 0
+ && (milliseconds >= event_delay || milliseconds < 0)) {
+ milliseconds = event_delay;
+ timeout_is_event = 1;
+ }
+ }
+#endif
+
#if PRECISE_GETTIME
retry:
#endif
@@ -133,8 +187,19 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
count = 0;
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl)
+ evl->result_flags = 0;
+#endif
+
#if USE_FUNC_POLL
- memset(fds, 0, sizeof(fds));
+ memset(fd_list, 0, sizeof(fd_list));
+
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl)
+ fds = typeMalloc(struct pollfd, MIN_FDS + evl->count);
+#endif
+
if (mode & 1) {
fds[count].fd = SP->_ifd;
fds[count].events = POLLIN;
@@ -146,7 +211,53 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
fds[count].events = POLLIN;
count++;
}
- result = poll(fds, count, milliseconds);
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl) {
+ for (n = 0; n < evl->count; ++n) {
+ _nc_event *ev = evl->events[n];
+
+ if (ev->type == _NC_EVENT_FILE
+ && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+ fds[count].fd = ev->data.fev.fd;
+ fds[count].events = POLLIN;
+ count++;
+ }
+ }
+ }
+#endif
+
+ result = poll(fds, (unsigned) count, milliseconds);
+
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl) {
+ int c;
+
+ if (!result)
+ count = 0;
+
+ for (n = 0; n < evl->count; ++n) {
+ _nc_event *ev = evl->events[n];
+
+ if (ev->type == _NC_EVENT_FILE
+ && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+ ev->data.fev.result = 0;
+ for (c = 0; c < count; c++)
+ if (fds[c].fd == ev->data.fev.fd
+ && fds[c].revents & POLLIN) {
+ ev->data.fev.result |= _NC_EVENT_FILE_READABLE;
+ evl->result_flags |= _NC_EVENT_FILE_READABLE;
+ }
+ } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC
+ && !result && timeout_is_event) {
+ evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC;
+ }
+ }
+ }
+
+ if (fds != fd_list)
+ free((char *) fds);
+
+#endif
#elif defined(__BEOS__)
/*
@@ -157,26 +268,34 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
*
* FIXME: the return values from the ioctl aren't very clear if we get
* interrupted.
+ *
+ * FIXME: this assumes mode&1 if milliseconds < 0 (see lib_getch.c).
*/
result = 0;
if (mode & 1) {
+ int step = (milliseconds < 0) ? 0 : 5000;
bigtime_t d;
bigtime_t useconds = milliseconds * 1000;
int n, howmany;
- if (useconds == 0) /* we're here to go _through_ the loop */
+ if (useconds <= 0) /* we're here to go _through_ the loop */
useconds = 1;
- for (d = 0; d < useconds; d += 5000) {
+ for (d = 0; d < useconds; d += step) {
n = 0;
howmany = ioctl(0, 'ichr', &n);
if (howmany >= 0 && n > 0) {
result = 1;
break;
}
- if (useconds > 1)
- snooze(5000);
- milliseconds -= 5;
+ if (useconds > 1 && step > 0) {
+ snooze(step);
+ milliseconds -= (step / 1000);
+ if (milliseconds <= 0) {
+ milliseconds = 0;
+ break;
+ }
+ }
}
} else if (milliseconds > 0) {
snooze(milliseconds * 1000);
@@ -198,6 +317,19 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
FD_SET(fd, &set);
count = max(fd, count) + 1;
}
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl) {
+ for (n = 0; n < evl->count; ++n) {
+ _nc_event *ev = evl->events[n];
+
+ if (ev->type == _NC_EVENT_FILE
+ && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+ FD_SET(ev->data.fev.fd, &set);
+ count = max(ev->data.fev.fd + 1, count);
+ }
+ }
+ }
+#endif
if (milliseconds >= 0) {
struct timeval ntimeout;
@@ -207,14 +339,53 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
} else {
result = select(count, &set, NULL, NULL, NULL);
}
+
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl) {
+ evl->result_flags = 0;
+ for (n = 0; n < evl->count; ++n) {
+ _nc_event *ev = evl->events[n];
+
+ if (ev->type == _NC_EVENT_FILE
+ && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+ ev->data.fev.result = 0;
+ if (FD_ISSET(ev->data.fev.fd, &set)) {
+ ev->data.fev.result |= _NC_EVENT_FILE_READABLE;
+ evl->result_flags |= _NC_EVENT_FILE_READABLE;
+ }
+ } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC
+ && !result && timeout_is_event)
+ evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC;
+ }
+ }
#endif
+#endif /* USE_FUNC_POLL, etc */
+
returntime = _nc_gettime(FALSE);
if (milliseconds >= 0)
milliseconds -= (returntime - starttime);
-#if PRECISE_GETTIME
+#ifdef NCURSES_WGETCH_EVENTS
+ if (evl) {
+ evl->result_flags = 0;
+ for (n = 0; n < evl->count; ++n) {
+ _nc_event *ev = evl->events[n];
+
+ if (ev->type == _NC_EVENT_TIMEOUT_MSEC) {
+ long diff = (returntime - starttime);
+ if (ev->data.timeout_msec <= diff)
+ ev->data.timeout_msec = 0;
+ else
+ ev->data.timeout_msec -= diff;
+ }
+
+ }
+ }
+#endif
+
+#if PRECISE_GETTIME && HAVE_NANOSLEEP
/*
* If the timeout hasn't expired, and we've gotten no data,
* this is probably a system where 'select()' needs to be left
@@ -222,7 +393,7 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
* then come back for more.
*/
if (result == 0 && milliseconds > 100) {
- napms(100);
+ napms(100); /* FIXME: this won't be right if I recur! */
milliseconds -= 100;
goto retry;
}
@@ -245,7 +416,7 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
if (result > 0) {
result = 0;
#if USE_FUNC_POLL
- for (count = 0; count < 2; count++) {
+ for (count = 0; count < MIN_FDS; count++) {
if ((mode & (1 << count))
&& (fds[count].revents & POLLIN)) {
result |= (1 << count);
@@ -265,6 +436,10 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft)
} else
result = 0;
}
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl && evl->result_flags)
+ result |= 4;
+#endif
return (result);
}
diff --git a/contrib/ncurses/ncurses/tty/lib_vidattr.c b/contrib/ncurses/ncurses/tty/lib_vidattr.c
index 00611f4e1501..dbbbc978a054 100644
--- a/contrib/ncurses/ncurses/tty/lib_vidattr.c
+++ b/contrib/ncurses/ncurses/tty/lib_vidattr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 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 *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996 on *
****************************************************************************/
/*
@@ -64,7 +65,7 @@
#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$Id: lib_vidattr.c,v 1.39 2001/08/26 00:40:46 Philippe.Blain Exp $")
+MODULE_ID("$Id: lib_vidattr.c,v 1.46 2006/01/21 23:39:40 tom Exp $")
#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
@@ -87,8 +88,7 @@ MODULE_ID("$Id: lib_vidattr.c,v 1.39 2001/08/26 00:40:46 Philippe.Blain Exp $")
}
NCURSES_EXPORT(int)
-vidputs
-(chtype newmode, int (*outc) (int))
+vidputs(chtype newmode, int (*outc) (int))
{
static attr_t previous_attr = A_NORMAL;
attr_t turn_on, turn_off;
@@ -105,15 +105,51 @@ vidputs
/* this allows us to go on whether or not newterm() has been called */
if (SP)
- previous_attr = SP->_current_attr;
+ previous_attr = AttrOf(SCREEN_ATTRS(SP));
TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(previous_attr)));
-#if !USE_XMC_SUPPORT
if ((SP != 0)
- && (magic_cookie_glitch > 0))
+ && (magic_cookie_glitch > 0)) {
+#if USE_XMC_SUPPORT
+ static chtype table[] =
+ {
+ A_STANDOUT,
+ A_UNDERLINE,
+ A_REVERSE,
+ A_BLINK,
+ A_DIM,
+ A_BOLD,
+ A_INVIS,
+ A_PROTECT,
+ };
+ unsigned n;
+ int used = 0;
+ int limit = (max_attributes <= 0) ? 1 : max_attributes;
+ chtype retain = 0;
+
+ /*
+ * Limit the number of attribute bits set in the newmode according to
+ * the terminfo max_attributes value.
+ */
+ for (n = 0; n < SIZEOF(table); ++n) {
+ if ((table[n] & SP->_ok_attributes) == 0) {
+ newmode &= ~table[n];
+ } else if ((table[n] & newmode) != 0) {
+ if (used++ >= limit) {
+ newmode &= ~table[n];
+ if (newmode == retain)
+ break;
+ } else {
+ retain = newmode;
+ }
+ }
+ }
+#else
newmode &= ~(SP->_xmc_suppress);
#endif
+ TR(TRACE_ATTRS, ("suppressed attribute is %s", _traceattr(newmode)));
+ }
/*
* If we have a terminal that cannot combine color with video
@@ -177,7 +213,7 @@ vidputs
TurnOff(A_STANDOUT, exit_standout_mode);
}
}
- previous_attr &= ~A_COLOR;
+ previous_attr &= ALL_BUT_COLOR;
}
SetColorsIf((pair != 0) || fix_pair0, previous_attr);
@@ -194,7 +230,7 @@ vidputs
(newmode & A_INVIS) != 0,
(newmode & A_PROTECT) != 0,
(newmode & A_ALTCHARSET) != 0), 1, outc);
- previous_attr &= ~A_COLOR;
+ previous_attr &= ALL_BUT_COLOR;
}
SetColorsIf((pair != 0) || fix_pair0, previous_attr);
} else {
@@ -213,8 +249,8 @@ vidputs
if (turn_off && exit_attribute_mode) {
doPut(exit_attribute_mode);
- turn_on |= (newmode & (chtype) (~A_COLOR));
- previous_attr &= ~A_COLOR;
+ turn_on |= (newmode & ALL_BUT_COLOR);
+ previous_attr &= ALL_BUT_COLOR;
}
SetColorsIf((pair != 0) || fix_pair0, previous_attr);
@@ -229,22 +265,12 @@ vidputs
TurnOn(A_PROTECT, enter_protected_mode);
TurnOn(A_INVIS, enter_secure_mode);
TurnOn(A_UNDERLINE, enter_underline_mode);
-#ifdef enter_horizontal_hl_mode
+#if USE_WIDEC_SUPPORT
TurnOn(A_HORIZONTAL, enter_horizontal_hl_mode);
-#endif
-#ifdef enter_left_hl_mode
TurnOn(A_LEFT, enter_left_hl_mode);
-#endif
-#ifdef enter_low_hl_mode
TurnOn(A_LOW, enter_low_hl_mode);
-#endif
-#ifdef enter_right_hl_mode
TurnOn(A_RIGHT, enter_right_hl_mode);
-#endif
-#ifdef enter_top_hl_mode
TurnOn(A_TOP, enter_top_hl_mode);
-#endif
-#ifdef enter_vertical_hl_mode
TurnOn(A_VERTICAL, enter_vertical_hl_mode);
#endif
/* *INDENT-ON* */
@@ -255,7 +281,7 @@ vidputs
newmode |= A_REVERSE;
if (SP)
- SP->_current_attr = newmode;
+ SetAttr(SCREEN_ATTRS(SP), newmode);
else
previous_attr = newmode;
diff --git a/contrib/ncurses/ncurses/tty/tty_display.h b/contrib/ncurses/ncurses/tty/tty_display.h
index 8382c823f06a..4c45a08450ed 100644
--- a/contrib/ncurses/ncurses/tty/tty_display.h
+++ b/contrib/ncurses/ncurses/tty/tty_display.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2003,2004 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 *
@@ -29,6 +29,9 @@
#ifndef TTY_DISPLAY_H
#define TTY_DISPLAY_H 1
+/*
+ * $Id: tty_display.h,v 1.6 2005/01/01 23:41:12 tom Exp $
+ */
extern NCURSES_EXPORT(bool) _nc_tty_beep (void);
extern NCURSES_EXPORT(bool) _nc_tty_check_resize (void);
extern NCURSES_EXPORT(bool) _nc_tty_cursor (int);
@@ -111,11 +114,11 @@ struct tty_display_data {
: ((enter_insert_mode && exit_insert_mode) \
? D->_smir_cost + D->_rmir_cost + (D->_ip_cost * count) \
: ((insert_character != 0) \
- ? (D->_ich1_cost * count) \
+ ? ((D->_ich1_cost + D->_ip_cost) * count) \
: INFINITY)))
#if USE_XMC_SUPPORT
-#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) { \
+#define UpdateAttrs(c) if (!SameAttrOf(D->_current_attr, AttrOf(c))) { \
attr_t chg = D->_current_attr; \
vidattr(AttrOf(c)); \
if (magic_cookie_glitch > 0 \
@@ -128,7 +131,7 @@ struct tty_display_data {
} \
}
#else
-#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) \
+#define UpdateAttrs(c) if (!SameAttrOf(D->_current_attr, AttrOf(c))) \
vidattr(AttrOf(c));
#endif
diff --git a/contrib/ncurses/ncurses/tty/tty_update.c b/contrib/ncurses/ncurses/tty/tty_update.c
index e06de1b7da06..6926b56198d9 100644
--- a/contrib/ncurses/ncurses/tty/tty_update.c
+++ b/contrib/ncurses/ncurses/tty/tty_update.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 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 *
@@ -29,15 +29,16 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*-----------------------------------------------------------------
*
* lib_doupdate.c
*
- * The routine doupdate() and its dependents. Also _nc_outstr(),
- * so all physical output is concentrated here (except _nc_outch()
- * in lib_tputs.c).
+ * The routine doupdate() and its dependents.
+ * All physical output is concentrated here (except _nc_outch()
+ * in lib_tputs.c).
*
*-----------------------------------------------------------------*/
@@ -70,9 +71,10 @@
#endif
#endif
+#include <ctype.h>
#include <term.h>
-MODULE_ID("$Id: tty_update.c,v 1.174 2002/04/21 21:04:16 tom Exp $")
+MODULE_ID("$Id: tty_update.c,v 1.238 2006/11/25 22:33:21 tom Exp $")
/*
* This define controls the line-breakout optimization. Every once in a
@@ -87,6 +89,9 @@ MODULE_ID("$Id: tty_update.c,v 1.174 2002/04/21 21:04:16 tom Exp $")
#define FILL_BCE() (SP->_coloron && !SP->_default_color && !back_color_erase)
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+static NCURSES_CH_T normal = NewChar(BLANK_TEXT);
+
/*
* Enable checking to see if doupdate and friends are tracking the true
* cursor position correctly. NOTE: this is a debugging hack which will
@@ -94,7 +99,7 @@ MODULE_ID("$Id: tty_update.c,v 1.174 2002/04/21 21:04:16 tom Exp $")
*/
/* #define POSITION_DEBUG */
-static inline NCURSES_CH_T ClrBlank(WINDOW *win);
+static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win);
static int ClrBottom(int total);
static void ClearScreen(NCURSES_CH_T blank);
static void ClrUpdate(void);
@@ -162,64 +167,131 @@ position_check(int expected_y, int expected_x, char *legend)
*
****************************************************************************/
-static inline void
+static NCURSES_INLINE void
GoTo(int const row, int const col)
{
- attr_t oldattr = SP->_current_attr;
-
TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)",
row, col, SP->_cursrow, SP->_curscol));
position_check(SP->_cursrow, SP->_curscol, "GoTo");
- /*
- * Force restore even if msgr is on when we're in an alternate
- * character set -- these have a strong tendency to screw up the
- * CR & LF used for local character motions!
- */
- if ((oldattr & A_ALTCHARSET)
- || (oldattr && !move_standout_mode)) {
- TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
- oldattr, _traceattr(oldattr)));
- vidattr(A_NORMAL);
- }
-
mvcur(SP->_cursrow, SP->_curscol, row, col);
- SP->_cursrow = row;
- SP->_curscol = col;
position_check(SP->_cursrow, SP->_curscol, "GoTo2");
}
-static inline void
+static NCURSES_INLINE void
PutAttrChar(CARG_CH_T ch)
{
+ int chlen = 1;
+ NCURSES_CH_T my_ch;
PUTC_DATA;
NCURSES_CH_T tilde;
+ NCURSES_CH_T attr = CHDEREF(ch);
+ TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)",
+ _tracech_t(ch),
+ SP->_cursrow, SP->_curscol));
+#if USE_WIDEC_SUPPORT
+ /*
+ * If this is not a valid character, there is nothing more to do.
+ */
+ if (isWidecExt(CHDEREF(ch))) {
+ TR(TRACE_CHARPUT, ("...skip"));
+ return;
+ }
+ /*
+ * Determine the number of character cells which the 'ch' value will use
+ * on the screen. It should be at least one.
+ */
+ if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) {
+ static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+
+ /*
+ * If the character falls into any of these special cases, do
+ * not force the result to a blank:
+ *
+ * a) it is printable (this works around a bug in wcwidth()).
+ * b) use_legacy_coding() has been called to modify the treatment
+ * of codes 128-255.
+ * c) the acs_map[] has been initialized to allow codes 0-31
+ * to be rendered. This supports Linux console's "PC"
+ * characters. Codes 128-255 are allowed though this is
+ * not checked.
+ */
+ if (is8bits(CharOf(CHDEREF(ch)))
+ && (isprint(CharOf(CHDEREF(ch)))
+ || (SP->_legacy_coding > 0 && CharOf(CHDEREF(ch)) >= 160)
+ || (SP->_legacy_coding > 1 && CharOf(CHDEREF(ch)) >= 128)
+ || (AttrOf(attr) & A_ALTCHARSET
+ && ((CharOfD(ch) < ACS_LEN
+ && SP->_acs_map != 0
+ && SP->_acs_map[CharOfD(ch)] != 0)
+ || (CharOfD(ch) >= 128))))) {
+ ;
+ } else {
+ ch = CHREF(blank);
+ TR(TRACE_CHARPUT, ("forced to blank"));
+ }
+ chlen = 1;
+ }
+#endif
+
+ if ((AttrOf(attr) & A_ALTCHARSET)
+ && SP->_acs_map != 0
+ && CharOfD(ch) < ACS_LEN) {
+ my_ch = CHDEREF(ch); /* work around const param */
+#if USE_WIDEC_SUPPORT
+ /*
+ * This is crude & ugly, but works most of the time. It checks if the
+ * acs_chars string specified that we have a mapping for this
+ * character, and uses the wide-character mapping when we expect the
+ * normal one to be broken (by mis-design ;-).
+ */
+ if (SP->_screen_acs_fix
+ && SP->_screen_acs_map[CharOf(my_ch)]) {
+ RemAttr(attr, A_ALTCHARSET);
+ my_ch = _nc_wacs[CharOf(my_ch)];
+ }
+#endif
+ /*
+ * If we (still) have alternate character set, it is the normal 8bit
+ * flavor. The _screen_acs_map[] array tells if the character was
+ * really in acs_chars, needed because of the way wide/normal line
+ * drawing flavors are integrated.
+ */
+ if (AttrOf(attr) & A_ALTCHARSET) {
+ int j = CharOfD(ch);
+ chtype temp = UChar(SP->_acs_map[j]);
+
+ if (!(SP->_screen_acs_map[j])) {
+ RemAttr(attr, A_ALTCHARSET);
+ if (temp == 0)
+ temp = ' ';
+ }
+ if (temp != 0)
+ SetChar(my_ch, temp, AttrOf(attr));
+ }
+ ch = CHREF(my_ch);
+ }
if (tilde_glitch && (CharOfD(ch) == L('~'))) {
- SetChar(tilde, L('`'), AttrOfD(ch));
+ SetChar(tilde, L('`'), AttrOf(attr));
ch = CHREF(tilde);
}
- TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)",
- _tracech_t(ch),
- SP->_cursrow, SP->_curscol));
- UpdateAttrs(AttrOfD(ch));
+ UpdateAttrs(attr);
#if !USE_WIDEC_SUPPORT
/* FIXME - we do this special case for signal handling, should see how to
* make it work for wide characters.
*/
if (SP->_outch != 0) {
- SP->_outch(ch);
+ SP->_outch(UChar(ch));
} else
#endif
{
PUTC(CHDEREF(ch), SP->_ofp); /* macro's fastest... */
-#ifdef TRACE
- _nc_outchars++;
-#endif /* TRACE */
+ TRACE_OUTCHARS(1);
}
- SP->_curscol++;
+ SP->_curscol += chlen;
if (char_padding) {
TPUTS_TRACE("char_padding");
putp(char_padding);
@@ -311,38 +383,48 @@ PutCharLR(const ARG_CH_T ch)
}
}
+/*
+ * Wrap the cursor position, i.e., advance to the beginning of the next line.
+ */
static void
wrap_cursor(void)
{
if (eat_newline_glitch) {
/*
- * xenl can manifest two different ways. The vt100
- * way is that, when you'd expect the cursor to wrap,
- * it stays hung at the right margin (on top of the
- * character just emitted) and doesn't wrap until the
- * *next* graphic char is emitted. The c100 way is
- * to ignore LF received just after an am wrap.
+ * xenl can manifest two different ways. The vt100 way is that, when
+ * you'd expect the cursor to wrap, it stays hung at the right margin
+ * (on top of the character just emitted) and doesn't wrap until the
+ * *next* graphic char is emitted. The c100 way is to ignore LF
+ * received just after an am wrap.
*
- * An aggressive way to handle this would be to
- * emit CR/LF after the char and then assume the wrap
- * is done, you're on the first position of the next
- * line, and the terminal out of its weird state.
- * Here it's safe to just tell the code that the
- * cursor is in hyperspace and let the next mvcur()
- * call straighten things out.
+ * An aggressive way to handle this would be to emit CR/LF after the
+ * char and then assume the wrap is done, you're on the first position
+ * of the next line, and the terminal out of its weird state. Here
+ * it's safe to just tell the code that the cursor is in hyperspace and
+ * let the next mvcur() call straighten things out.
*/
SP->_curscol = -1;
SP->_cursrow = -1;
} else if (auto_right_margin) {
SP->_curscol = 0;
SP->_cursrow++;
+ /*
+ * We've actually moved - but may have to work around problems with
+ * video attributes not working.
+ */
+ if (!move_standout_mode && AttrOf(SCREEN_ATTRS(SP))) {
+ TR(TRACE_CHARPUT, ("turning off (%#lx) %s before wrapping",
+ (unsigned long) AttrOf(SCREEN_ATTRS(SP)),
+ _traceattr(AttrOf(SCREEN_ATTRS(SP)))));
+ (void) VIDATTR(A_NORMAL, 0);
+ }
} else {
SP->_curscol--;
}
position_check(SP->_cursrow, SP->_curscol, "wrap_cursor");
}
-static inline void
+static NCURSES_INLINE void
PutChar(const ARG_CH_T ch)
/* insert character, handling automargin stuff */
{
@@ -363,18 +445,20 @@ PutChar(const ARG_CH_T ch)
* as A_REVERSE. All attribute flags which don't affect appearance of a space
* or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
*/
-static inline bool
+static NCURSES_INLINE bool
can_clear_with(ARG_CH_T ch)
{
if (!back_color_erase && SP->_coloron) {
#if NCURSES_EXT_FUNCS
+ int pair;
+
if (!SP->_default_color)
return FALSE;
if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK)
return FALSE;
- if (AttrOfD(ch) & A_COLOR) {
+ if ((pair = GetPair(CHDEREF(ch))) != 0) {
short fg, bg;
- pair_content(PAIR_NUMBER(AttrOfD(ch)), &fg, &bg);
+ pair_content(pair, &fg, &bg);
if (fg != C_MASK || bg != C_MASK)
return FALSE;
}
@@ -404,6 +488,8 @@ EmitRange(const NCURSES_CH_T * ntext, int num)
{
int i;
+ TR(TRACE_CHARPUT, ("EmitRange %d:%s", num, _nc_viscbuf(ntext, num)));
+
if (erase_chars || repeat_char) {
while (num > 0) {
int runcount;
@@ -435,8 +521,8 @@ EmitRange(const NCURSES_CH_T * ntext, int num)
if (erase_chars
&& runcount > SP->_ech_cost + SP->_cup_ch_cost
&& can_clear_with(CHREF(ntext0))) {
- UpdateAttrs(AttrOf(ntext0));
- putp(tparm(erase_chars, runcount));
+ UpdateAttrs(ntext0);
+ putp(TPARM_1(erase_chars, runcount));
/*
* If this is the last part of the given interval,
@@ -455,8 +541,9 @@ EmitRange(const NCURSES_CH_T * ntext, int num)
if (wrap_possible)
rep_count--;
- UpdateAttrs(AttrOf(ntext0));
- putp(tparm(repeat_char, CharOf(ntext0), rep_count));
+ UpdateAttrs(ntext0);
+ tputs(TPARM_2(repeat_char, CharOf(ntext0), rep_count),
+ rep_count, _nc_outch);
SP->_curscol += rep_count;
if (wrap_possible)
@@ -485,33 +572,37 @@ EmitRange(const NCURSES_CH_T * ntext, int num)
* Returns: same as EmitRange
*/
static int
-PutRange(
- const NCURSES_CH_T * otext,
- const NCURSES_CH_T * ntext,
- int row,
- int first, int last)
+PutRange(const NCURSES_CH_T * otext,
+ const NCURSES_CH_T * ntext,
+ int row,
+ int first, int last)
{
- int j, run;
+ int i, j, same;
TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)",
otext, ntext, row, first, last));
if (otext != ntext
&& (last - first + 1) > SP->_inline_cost) {
- for (j = first, run = 0; j <= last; j++) {
- if (!run && isnac(otext[j]))
+ for (j = first, same = 0; j <= last; j++) {
+ if (!same && isWidecExt(otext[j]))
continue;
if (CharEq(otext[j], ntext[j])) {
- run++;
+ same++;
} else {
- if (run > SP->_inline_cost) {
- int before_run = (j - run);
- EmitRange(ntext + first, before_run - first);
+ if (same > SP->_inline_cost) {
+ EmitRange(ntext + first, j - same - first);
GoTo(row, first = j);
}
- run = 0;
+ same = 0;
}
}
+ i = EmitRange(ntext + first, j - same - first);
+ /*
+ * Always return 1 for the next GoTo() after a PutRange() if we found
+ * identical characters at end of interval
+ */
+ return (same == 0 ? i : 1);
}
return EmitRange(ntext + first, last - first + 1);
}
@@ -580,17 +671,15 @@ doupdate(void)
#endif /* USE_TRACE_TIMES */
/*
- * This is the support for magic-cookie terminals. The
- * theory: we scan the virtual screen looking for attribute
- * turnons. Where we find one, check to make sure it's
- * realizable by seeing if the required number of
- * un-attributed blanks are present before and after the
- * attributed range; try to shift the range boundaries over
- * blanks (not changing the screen display) so this becomes
- * true. If it is, shift the beginning attribute change
- * appropriately (the end one, if we've gotten this far, is
- * guaranteed room for its cookie). If not, nuke the added
- * attributes out of the span.
+ * This is the support for magic-cookie terminals. The theory: we scan
+ * the virtual screen looking for attribute turnons. Where we find one,
+ * check to make sure it's realizable by seeing if the required number of
+ * un-attributed blanks are present before and after the attributed range;
+ * try to shift the range boundaries over blanks (not changing the screen
+ * display) so this becomes true. If it is, shift the beginning attribute
+ * change appropriately (the end one, if we've gotten this far, is
+ * guaranteed room for its cookie). If not, nuke the added attributes out
+ * of the span.
*/
#if USE_XMC_SUPPORT
if (magic_cookie_glitch > 0) {
@@ -600,11 +689,13 @@ doupdate(void)
for (i = 0; i < screen_lines; i++) {
for (j = 0; j < screen_columns; j++) {
bool failed = FALSE;
- attr_t turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr;
+ NCURSES_CH_T *thisline = newscr->_line[i].text;
+ attr_t thisattr = AttrOf(thisline[j]) & SP->_xmc_triggers;
+ attr_t turnon = thisattr & ~rattr;
/* is an attribute turned on here? */
if (turnon == 0) {
- rattr = AttrOf(newscr->_line[i].text[j]);
+ rattr = thisattr;
continue;
}
@@ -612,23 +703,33 @@ doupdate(void)
TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon)));
/*
- * If the attribute change location is a blank with a
- * "safe" attribute, undo the attribute turnon. This may
- * ensure there's enough room to set the attribute before
- * the first non-blank in the run.
+ * If the attribute change location is a blank with a "safe"
+ * attribute, undo the attribute turnon. This may ensure
+ * there's enough room to set the attribute before the first
+ * non-blank in the run.
*/
-#define SAFE(a) (!((a) & (attr_t)~NONBLANK_ATTR))
- if (ISBLANK(newscr->_line[i].text[j]) && SAFE(turnon)) {
- RemAttr(newscr->_line[i].text[j], turnon);
+#define SAFE(a) (!((a) & SP->_xmc_triggers))
+ if (ISBLANK(thisline[j]) && SAFE(turnon)) {
+ RemAttr(thisline[j], turnon);
continue;
}
/* check that there's enough room at start of span */
for (k = 1; k <= magic_cookie_glitch; k++) {
if (j - k < 0
- || !ISBLANK(newscr->_line[i].text[j - k])
- || !SAFE(AttrOf(newscr->_line[i].text[j - k])))
+ || !ISBLANK(thisline[j - k])
+ || !SAFE(AttrOf(thisline[j - k]))) {
failed = TRUE;
+ TR(TRACE_ATTRS, ("No room at start in %d,%d%s%s",
+ i, j - k,
+ (ISBLANK(thisline[j - k])
+ ? ""
+ : ":nonblank"),
+ (SAFE(AttrOf(thisline[j - k]))
+ ? ""
+ : ":unsafe")));
+ break;
+ }
}
if (!failed) {
bool end_onscreen = FALSE;
@@ -637,7 +738,8 @@ doupdate(void)
/* find end of span, if it's onscreen */
for (m = i; m < screen_lines; m++) {
for (; n < screen_columns; n++) {
- if (AttrOf(newscr->_line[m].text[n]) == rattr) {
+ attr_t testattr = AttrOf(newscr->_line[m].text[n]);
+ if ((testattr & SP->_xmc_triggers) == rattr) {
end_onscreen = TRUE;
TR(TRACE_ATTRS,
("Range attributed with %s ends at (%d, %d)",
@@ -656,22 +758,34 @@ doupdate(void)
NCURSES_CH_T *lastline = newscr->_line[m].text;
/*
- * If there are safely-attributed blanks at the
- * end of the range, shorten the range. This will
- * help ensure that there is enough room at end
- * of span.
+ * If there are safely-attributed blanks at the end of
+ * the range, shorten the range. This will help ensure
+ * that there is enough room at end of span.
*/
while (n >= 0
&& ISBLANK(lastline[n])
- && SAFE(AttrOf(lastline[n])))
+ && SAFE(AttrOf(lastline[n]))) {
RemAttr(lastline[n--], turnon);
+ }
/* check that there's enough room at end of span */
- for (k = 1; k <= magic_cookie_glitch; k++)
+ for (k = 1; k <= magic_cookie_glitch; k++) {
if (n + k >= screen_columns
|| !ISBLANK(lastline[n + k])
- || !SAFE(AttrOf(lastline[n + k])))
+ || !SAFE(AttrOf(lastline[n + k]))) {
failed = TRUE;
+ TR(TRACE_ATTRS,
+ ("No room at end in %d,%d%s%s",
+ i, j - k,
+ (ISBLANK(lastline[n + k])
+ ? ""
+ : ":nonblank"),
+ (SAFE(AttrOf(lastline[n + k]))
+ ? ""
+ : ":unsafe")));
+ break;
+ }
+ }
}
}
@@ -685,7 +799,8 @@ doupdate(void)
/* turn off new attributes over span */
for (p = i; p < screen_lines; p++) {
for (; q < screen_columns; q++) {
- if (AttrOf(newscr->_line[p].text[q]) == rattr)
+ attr_t testattr = AttrOf(newscr->_line[p].text[q]);
+ if ((testattr & SP->_xmc_triggers) == rattr)
goto foundend;
RemAttr(newscr->_line[p].text[q], turnon);
}
@@ -698,14 +813,14 @@ doupdate(void)
_traceattr(turnon), i, j));
/*
- * back up the start of range so there's room
- * for cookies before the first nonblank character
+ * Back up the start of range so there's room for cookies
+ * before the first nonblank character.
*/
for (k = 1; k <= magic_cookie_glitch; k++)
- AddAttr(newscr->_line[i].text[j - k], turnon);
+ AddAttr(thisline[j - k], turnon);
}
- rattr = AttrOf(newscr->_line[i].text[j]);
+ rattr = thisattr;
}
}
@@ -789,13 +904,18 @@ doupdate(void)
cleanup:
/*
- * Keep the physical screen in normal mode in case we get other
- * processes writing to the screen.
+ * We would like to keep the physical screen in normal mode in case we get
+ * other processes writing to the screen. This goal cannot be met for
+ * magic cookies since it interferes with attributes that may propagate
+ * past the current position.
*/
- UpdateAttrs(A_NORMAL);
+#if USE_XMC_SUPPORT
+ if (magic_cookie_glitch != 0)
+#endif
+ UpdateAttrs(normal);
_nc_flush();
- curscr->_attrs = newscr->_attrs;
+ WINDOW_ATTRS(curscr) = WINDOW_ATTRS(newscr);
#if USE_TRACE_TIMES
(void) times(&after);
@@ -824,10 +944,10 @@ doupdate(void)
#define BCE_ATTRS (A_NORMAL|A_COLOR)
#define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_nc_bkgd)
-static inline NCURSES_CH_T
+static NCURSES_INLINE NCURSES_CH_T
ClrBlank(WINDOW *win)
{
- NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+ NCURSES_CH_T blank = blankchar;
if (back_color_erase)
AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS));
return blank;
@@ -887,14 +1007,14 @@ ClrToEOL(NCURSES_CH_T blank, bool needclear)
}
if (needclear) {
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("clr_eol");
- if (SP->_el_cost > (screen_columns - SP->_curscol)) {
+ if (clr_eol && SP->_el_cost <= (screen_columns - SP->_curscol)) {
+ putp(clr_eol);
+ } else {
int count = (screen_columns - SP->_curscol);
while (count-- > 0)
PutChar(CHREF(blank));
- } else {
- putp(clr_eol);
}
}
}
@@ -913,7 +1033,7 @@ ClrToEOS(NCURSES_CH_T blank)
row = SP->_cursrow;
col = SP->_curscol;
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("clr_eos");
tputs(clr_eos, screen_lines - row, _nc_outch);
@@ -940,7 +1060,7 @@ ClrBottom(int total)
int col;
int top = total;
int last = min(screen_columns, newscr->_maxx + 1);
- NCURSES_CH_T blank = ClrBlank(stdscr);
+ NCURSES_CH_T blank = newscr->_line[total - 1].text[last - 1];
bool ok;
if (clr_eos && can_clear_with(CHREF(blank))) {
@@ -960,29 +1080,22 @@ ClrBottom(int total)
}
/* don't use clr_eos for just one line if clr_eol available */
- if (top < total - 1 || (top < total && !clr_eol && !clr_bol)) {
+ if (top < total) {
GoTo(top, 0);
ClrToEOS(blank);
- total = top;
if (SP->oldhash && SP->newhash) {
for (row = top; row < screen_lines; row++)
SP->oldhash[row] = SP->newhash[row];
}
}
}
- return total;
+ return top;
}
#if USE_XMC_SUPPORT
#if USE_WIDEC_SUPPORT
-static inline bool
-check_xmc_transition(NCURSES_CH_T * a, NCURSES_CH_T * b)
-{
- if (((a->attr ^ b->attr) & ~(a->attr) & SP->_xmc_triggers) != 0) {
- return TRUE;
- }
- return FALSE;
-}
+#define check_xmc_transition(a, b) \
+ ((((a)->attr ^ (b)->attr) & ~((a)->attr) & SP->_xmc_triggers) != 0)
#define xmc_turn_on(a,b) check_xmc_transition(&(a), &(b))
#else
#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0)
@@ -1019,14 +1132,12 @@ TransformLine(int const lineno)
int n;
bool attrchanged = FALSE;
- TR(TRACE_UPDATE, ("TransformLine(%d) called", lineno));
+ TR(TRACE_UPDATE, (T_CALLED("TransformLine(%d)"), lineno));
/* copy new hash value to old one */
if (SP->oldhash && SP->newhash)
SP->oldhash[lineno] = SP->newhash[lineno];
-#define ColorOf(n) (AttrOf(n) & A_COLOR)
-#define unColor(n) (AttrOf(n) & ALL_BUT_COLOR)
/*
* If we have colors, there is the possibility of having two color pairs
* that display as the same colors. For instance, Lynx does this. Check
@@ -1034,24 +1145,19 @@ TransformLine(int const lineno)
* they are equivalent.
*/
if (SP->_coloron) {
- attr_t oldColor;
- attr_t newColor;
int oldPair;
int newPair;
for (n = 0; n < screen_columns; n++) {
if (!CharEq(newLine[n], oldLine[n])) {
- oldColor = ColorOf(oldLine[n]);
- newColor = ColorOf(newLine[n]);
- if (oldColor != newColor
+ oldPair = GetPair(oldLine[n]);
+ newPair = GetPair(newLine[n]);
+ if (oldPair != newPair
&& unColor(oldLine[n]) == unColor(newLine[n])) {
- oldPair = PAIR_NUMBER(oldColor);
- newPair = PAIR_NUMBER(newColor);
if (oldPair < COLOR_PAIRS
&& newPair < COLOR_PAIRS
&& SP->_color_pairs[oldPair] == SP->_color_pairs[newPair]) {
- RemAttr(oldLine[n], A_COLOR);
- AddAttr(oldLine[n], ColorOf(newLine[n]));
+ SetPair(oldLine[n], GetPair(newLine[n]));
}
}
}
@@ -1061,8 +1167,10 @@ TransformLine(int const lineno)
if (ceol_standout_glitch && clr_eol) {
firstChar = 0;
while (firstChar < screen_columns) {
- if (AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar]))
+ if (!SameAttrOf(newLine[firstChar], oldLine[firstChar])) {
attrchanged = TRUE;
+ break;
+ }
firstChar++;
}
}
@@ -1125,17 +1233,9 @@ TransformLine(int const lineno)
} else {
NCURSES_CH_T blank;
- /* find the first differing character */
- while (firstChar < screen_columns &&
- CharEq(newLine[firstChar], oldLine[firstChar]))
- firstChar++;
-
- /* if there wasn't one, we're done */
- if (firstChar >= screen_columns)
- return;
-
/* it may be cheap to clear leading whitespace with clr_bol */
- if (clr_bol && (blank = newLine[0], can_clear_with(CHREF(blank)))) {
+ blank = newLine[0];
+ if (clr_bol && can_clear_with(CHREF(blank))) {
int oFirstChar, nFirstChar;
for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++)
@@ -1145,25 +1245,44 @@ TransformLine(int const lineno)
if (!CharEq(newLine[nFirstChar], blank))
break;
- if (nFirstChar > oFirstChar + SP->_el1_cost) {
- if (nFirstChar >= screen_columns && SP->_el_cost <= SP->_el1_cost) {
- GoTo(lineno, 0);
- UpdateAttrs(AttrOf(blank));
- TPUTS_TRACE("clr_eol");
- putp(clr_eol);
- } else {
- GoTo(lineno, nFirstChar - 1);
- UpdateAttrs(AttrOf(blank));
- TPUTS_TRACE("clr_bol");
- putp(clr_bol);
- }
-
- while (firstChar < nFirstChar)
- oldLine[firstChar++] = blank;
+ if (nFirstChar == oFirstChar) {
+ firstChar = nFirstChar;
+ /* find the first differing character */
+ while (firstChar < screen_columns
+ && CharEq(newLine[firstChar], oldLine[firstChar]))
+ firstChar++;
+ } else if (oFirstChar > nFirstChar) {
+ firstChar = nFirstChar;
+ } else { /* oFirstChar < nFirstChar */
+ firstChar = oFirstChar;
+ if (SP->_el1_cost < nFirstChar - oFirstChar) {
+ if (nFirstChar >= screen_columns
+ && SP->_el_cost <= SP->_el1_cost) {
+ GoTo(lineno, 0);
+ UpdateAttrs(blank);
+ TPUTS_TRACE("clr_eol");
+ putp(clr_eol);
+ } else {
+ GoTo(lineno, nFirstChar - 1);
+ UpdateAttrs(blank);
+ TPUTS_TRACE("clr_bol");
+ putp(clr_bol);
+ }
- if (firstChar >= screen_columns)
- return;
+ while (firstChar < nFirstChar)
+ oldLine[firstChar++] = blank;
+ }
}
+ } else {
+ /* find the first differing character */
+ while (firstChar < screen_columns
+ && CharEq(newLine[firstChar], oldLine[firstChar]))
+ firstChar++;
+ }
+ /* if there wasn't one, we're done */
+ if (firstChar >= screen_columns) {
+ TR(TRACE_UPDATE, (T_RETURN("")));
+ return;
}
blank = newLine[screen_columns - 1];
@@ -1183,6 +1302,7 @@ TransformLine(int const lineno)
newLine + firstChar,
(nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T));
}
+ TR(TRACE_UPDATE, (T_RETURN("")));
return;
}
@@ -1222,7 +1342,7 @@ TransformLine(int const lineno)
/* can be -1 if no characters differ */
while (CharEq(newLine[nLastChar], oldLine[oLastChar])) {
/* don't split a wide char */
- if (isnac(newLine[nLastChar]) &&
+ if (isWidecExt(newLine[nLastChar]) &&
!CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1]))
break;
nLastChar--;
@@ -1239,9 +1359,15 @@ TransformLine(int const lineno)
if (oLastChar < nLastChar) {
int m = max(nLastNonblank, oLastNonblank);
+#if USE_WIDEC_SUPPORT
+ while (isWidecExt(newLine[n + 1]) && n) {
+ --n;
+ --oLastChar;
+ }
+#endif
GoTo(lineno, n + 1);
- if (InsCharCost(nLastChar - oLastChar)
- > (m - n)) {
+ if ((nLastChar < nLastNonblank)
+ || InsCharCost(nLastChar - oLastChar) > (m - n)) {
PutRange(oldLine, newLine, lineno, n + 1, m);
} else {
InsStr(&newLine[n + 1], nLastChar - oLastChar);
@@ -1263,7 +1389,7 @@ TransformLine(int const lineno)
* setting the video attributes from
* the last character on the row.
*/
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
DelChar(oLastChar - nLastChar);
}
}
@@ -1275,6 +1401,8 @@ TransformLine(int const lineno)
memcpy(oldLine + firstChar,
newLine + firstChar,
(screen_columns - firstChar) * sizeof(NCURSES_CH_T));
+ TR(TRACE_UPDATE, (T_RETURN("")));
+ return;
}
/*
@@ -1295,7 +1423,7 @@ ClearScreen(NCURSES_CH_T blank)
#if NCURSES_EXT_FUNCS
if (SP->_coloron
&& !SP->_default_color) {
- _nc_do_color((int) COLOR_PAIR(SP->_current_attr), 0, FALSE, _nc_outch);
+ _nc_do_color(GET_SCREEN_PAIR(SP), 0, FALSE, _nc_outch);
if (!back_color_erase) {
fast_clear = FALSE;
}
@@ -1304,7 +1432,7 @@ ClearScreen(NCURSES_CH_T blank)
if (fast_clear) {
if (clear_screen) {
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("clear_screen");
putp(clear_screen);
SP->_cursrow = SP->_curscol = 0;
@@ -1313,13 +1441,13 @@ ClearScreen(NCURSES_CH_T blank)
SP->_cursrow = SP->_curscol = -1;
GoTo(0, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("clr_eos");
- putp(clr_eos);
+ tputs(clr_eos, screen_lines, _nc_outch);
} else if (clr_eol) {
SP->_cursrow = SP->_curscol = -1;
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
for (i = 0; i < screen_lines; i++) {
GoTo(i, 0);
TPUTS_TRACE("clr_eol");
@@ -1328,7 +1456,7 @@ ClearScreen(NCURSES_CH_T blank)
GoTo(0, 0);
}
} else {
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
for (i = 0; i < screen_lines; i++) {
GoTo(i, 0);
for (j = 0; j < screen_columns; j++)
@@ -1362,7 +1490,7 @@ InsStr(NCURSES_CH_T * line, int count)
/* The order must match that of InsCharCost. */
if (parm_ich) {
TPUTS_TRACE("parm_ich");
- tputs(tparm(parm_ich, count), count, _nc_outch);
+ tputs(TPARM_1(parm_ich, count), count, _nc_outch);
while (count) {
PutAttrChar(CHREF(*line));
line++;
@@ -1410,12 +1538,14 @@ DelChar(int count)
{
int n;
- TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%d,%d)", count,
- newscr->_cury, newscr->_curx));
+ TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%ld,%ld)",
+ count,
+ (long) newscr->_cury,
+ (long) newscr->_curx));
if (parm_dch) {
TPUTS_TRACE("parm_dch");
- tputs(tparm(parm_dch, count), count, _nc_outch);
+ tputs(TPARM_1(parm_dch, count), count, _nc_outch);
} else {
for (n = 0; n < count; n++) {
TPUTS_TRACE("delete_character");
@@ -1425,19 +1555,6 @@ DelChar(int count)
}
/*
-** _nc_outstr(char *str)
-**
-** Emit a string without waiting for update.
-*/
-
-NCURSES_EXPORT(void)
-_nc_outstr(const char *str)
-{
- (void) putp(str);
- _nc_flush();
-}
-
-/*
* Physical-scrolling support
*
* This code was adapted from Keith Bostic's hardware scrolling
@@ -1473,47 +1590,48 @@ _nc_outstr(const char *str)
static int
scroll_csr_forward(int n, int top, int bot, int miny, int maxy, NCURSES_CH_T blank)
{
- int i, j;
+ int i;
if (n == 1 && scroll_forward && top == miny && bot == maxy) {
GoTo(bot, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("scroll_forward");
- tputs(scroll_forward, 0, _nc_outch);
+ putp(scroll_forward);
} else if (n == 1 && delete_line && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("delete_line");
- tputs(delete_line, 0, _nc_outch);
+ putp(delete_line);
} else if (parm_index && top == miny && bot == maxy) {
GoTo(bot, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("parm_index");
- tputs(tparm(parm_index, n, 0), n, _nc_outch);
+ tputs(TPARM_2(parm_index, n, 0), n, _nc_outch);
} else if (parm_delete_line && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("parm_delete_line");
- tputs(tparm(parm_delete_line, n, 0), n, _nc_outch);
+ tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch);
} else if (scroll_forward && top == miny && bot == maxy) {
GoTo(bot, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
for (i = 0; i < n; i++) {
TPUTS_TRACE("scroll_forward");
- tputs(scroll_forward, 0, _nc_outch);
+ putp(scroll_forward);
}
} else if (delete_line && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
for (i = 0; i < n; i++) {
TPUTS_TRACE("delete_line");
- tputs(delete_line, 0, _nc_outch);
+ putp(delete_line);
}
} else
return ERR;
#if NCURSES_EXT_FUNCS
if (FILL_BCE()) {
+ int j;
for (i = 0; i < n; i++) {
GoTo(bot - i, 0);
for (j = 0; j < screen_columns; j++)
@@ -1530,47 +1648,48 @@ static int
scroll_csr_backward(int n, int top, int bot, int miny, int maxy,
NCURSES_CH_T blank)
{
- int i, j;
+ int i;
if (n == 1 && scroll_reverse && top == miny && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("scroll_reverse");
- tputs(scroll_reverse, 0, _nc_outch);
+ putp(scroll_reverse);
} else if (n == 1 && insert_line && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("insert_line");
- tputs(insert_line, 0, _nc_outch);
+ putp(insert_line);
} else if (parm_rindex && top == miny && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("parm_rindex");
- tputs(tparm(parm_rindex, n, 0), n, _nc_outch);
+ tputs(TPARM_2(parm_rindex, n, 0), n, _nc_outch);
} else if (parm_insert_line && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
TPUTS_TRACE("parm_insert_line");
- tputs(tparm(parm_insert_line, n, 0), n, _nc_outch);
+ tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch);
} else if (scroll_reverse && top == miny && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
for (i = 0; i < n; i++) {
TPUTS_TRACE("scroll_reverse");
- tputs(scroll_reverse, 0, _nc_outch);
+ putp(scroll_reverse);
}
} else if (insert_line && bot == maxy) {
GoTo(top, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
for (i = 0; i < n; i++) {
TPUTS_TRACE("insert_line");
- tputs(insert_line, 0, _nc_outch);
+ putp(insert_line);
}
} else
return ERR;
#if NCURSES_EXT_FUNCS
if (FILL_BCE()) {
+ int j;
for (i = 0; i < n; i++) {
GoTo(top + i, 0);
for (j = 0; j < screen_columns; j++)
@@ -1592,41 +1711,48 @@ scroll_idl(int n, int del, int ins, NCURSES_CH_T blank)
return ERR;
GoTo(del, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
if (n == 1 && delete_line) {
TPUTS_TRACE("delete_line");
- tputs(delete_line, 0, _nc_outch);
+ putp(delete_line);
} else if (parm_delete_line) {
TPUTS_TRACE("parm_delete_line");
- tputs(tparm(parm_delete_line, n, 0), n, _nc_outch);
+ tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch);
} else { /* if (delete_line) */
for (i = 0; i < n; i++) {
TPUTS_TRACE("delete_line");
- tputs(delete_line, 0, _nc_outch);
+ putp(delete_line);
}
}
GoTo(ins, 0);
- UpdateAttrs(AttrOf(blank));
+ UpdateAttrs(blank);
if (n == 1 && insert_line) {
TPUTS_TRACE("insert_line");
- tputs(insert_line, 0, _nc_outch);
+ putp(insert_line);
} else if (parm_insert_line) {
TPUTS_TRACE("parm_insert_line");
- tputs(tparm(parm_insert_line, n, 0), n, _nc_outch);
+ tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch);
} else { /* if (insert_line) */
for (i = 0; i < n; i++) {
TPUTS_TRACE("insert_line");
- tputs(insert_line, 0, _nc_outch);
+ putp(insert_line);
}
}
return OK;
}
+/*
+ * Note: some terminals require the cursor to be within the scrolling margins
+ * before setting them. Generally, the cursor must be at the appropriate end
+ * of the scrolling margins when issuing an indexing operation (it is not
+ * apparent whether it must also be at the left margin; we do this just to be
+ * safe). To make the related cursor movement a little faster, we use the
+ * save/restore cursor capabilities if the terminal has them.
+ */
NCURSES_EXPORT(int)
-_nc_scrolln
-(int n, int top, int bot, int maxy)
+_nc_scrolln(int n, int top, int bot, int maxy)
/* scroll region from top to bot by n lines */
{
NCURSES_CH_T blank = ClrBlank(stdscr);
@@ -1658,13 +1784,13 @@ _nc_scrolln
&& save_cursor && restore_cursor) {
cursor_saved = TRUE;
TPUTS_TRACE("save_cursor");
- tputs(save_cursor, 0, _nc_outch);
+ putp(save_cursor);
}
TPUTS_TRACE("change_scroll_region");
- tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch);
+ putp(TPARM_2(change_scroll_region, top, bot));
if (cursor_saved) {
TPUTS_TRACE("restore_cursor");
- tputs(restore_cursor, 0, _nc_outch);
+ putp(restore_cursor);
} else {
SP->_cursrow = SP->_curscol = -1;
}
@@ -1672,7 +1798,7 @@ _nc_scrolln
res = scroll_csr_forward(n, top, bot, top, bot, blank);
TPUTS_TRACE("change_scroll_region");
- tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch);
+ putp(TPARM_2(change_scroll_region, 0, maxy));
SP->_cursrow = SP->_curscol = -1;
}
@@ -1684,9 +1810,9 @@ _nc_scrolln
*/
if (res != ERR
&& (non_dest_scroll_region || (memory_below && bot == maxy))) {
- NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
+ static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
if (bot == maxy && clr_eos) {
- GoTo(bot - n, 0);
+ GoTo(bot - n + 1, 0);
ClrToEOS(blank2);
} else {
for (i = 0; i < n; i++) {
@@ -1704,13 +1830,13 @@ _nc_scrolln
&& save_cursor && restore_cursor) {
cursor_saved = TRUE;
TPUTS_TRACE("save_cursor");
- tputs(save_cursor, 0, _nc_outch);
+ putp(save_cursor);
}
TPUTS_TRACE("change_scroll_region");
- tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch);
+ putp(TPARM_2(change_scroll_region, top, bot));
if (cursor_saved) {
TPUTS_TRACE("restore_cursor");
- tputs(restore_cursor, 0, _nc_outch);
+ putp(restore_cursor);
} else {
SP->_cursrow = SP->_curscol = -1;
}
@@ -1718,7 +1844,7 @@ _nc_scrolln
res = scroll_csr_backward(-n, top, bot, top, bot, blank);
TPUTS_TRACE("change_scroll_region");
- tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch);
+ putp(TPARM_2(change_scroll_region, 0, maxy));
SP->_cursrow = SP->_curscol = -1;
}
@@ -1730,7 +1856,7 @@ _nc_scrolln
*/
if (res != ERR
&& (non_dest_scroll_region || (memory_above && top == 0))) {
- NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
+ static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
for (i = 0; i < -n; i++) {
GoTo(i + top, 0);
ClrToEOL(blank2, FALSE);
@@ -1753,11 +1879,27 @@ NCURSES_EXPORT(void)
_nc_screen_resume(void)
{
/* make sure terminal is in a sane known state */
- SP->_current_attr = A_NORMAL;
+ SetAttr(SCREEN_ATTRS(SP), A_NORMAL);
newscr->_clear = TRUE;
- if (SP->_coloron == TRUE && orig_pair)
- putp(orig_pair);
+ /* reset color pairs and definitions */
+ if (SP->_coloron || SP->_color_defs)
+ _nc_reset_colors();
+
+ /* restore user-defined colors, if any */
+ if (SP->_color_defs < 0) {
+ int n;
+ SP->_color_defs = -(SP->_color_defs);
+ for (n = 0; n < SP->_color_defs; ++n) {
+ if (SP->_color_table[n].init) {
+ init_color(n,
+ SP->_color_table[n].r,
+ SP->_color_table[n].g,
+ SP->_color_table[n].b);
+ }
+ }
+ }
+
if (exit_attribute_mode)
putp(exit_attribute_mode);
else {
@@ -1785,29 +1927,30 @@ _nc_screen_init(void)
NCURSES_EXPORT(void)
_nc_screen_wrap(void)
{
- UpdateAttrs(A_NORMAL);
+ UpdateAttrs(normal);
#if NCURSES_EXT_FUNCS
if (SP->_coloron
&& !SP->_default_color) {
- NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+ static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
SP->_default_color = TRUE;
_nc_do_color(-1, 0, FALSE, _nc_outch);
SP->_default_color = FALSE;
mvcur(SP->_cursrow, SP->_curscol, screen_lines - 1, 0);
- SP->_cursrow = screen_lines - 1;
- SP->_curscol = 0;
ClrToEOL(blank, TRUE);
}
#endif
+ if (SP->_color_defs) {
+ _nc_reset_colors();
+ }
}
#if USE_XMC_SUPPORT
NCURSES_EXPORT(void)
_nc_do_xmc_glitch(attr_t previous)
{
- attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr);
+ attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP)));
while (chg != 0) {
if (chg & 1) {