summaryrefslogtreecommitdiff
path: root/lib/libcurses/tty
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-01-12 23:22:15 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-01-12 23:22:15 +0000
commit6ee254699bf787d78835419be2b3241fb037d444 (patch)
tree07fe67dab517e4990f344fe2c00e65cef4d25b81 /lib/libcurses/tty
parent0b62f5dc36fc7203a74cdc812c4234ae188fdfd2 (diff)
Update to ncurses 5.7, with local changes reapplied.
This is around eight years worth of changes (previously we were around ncurses 5.2), too many to list - many bug fixes and also a few new functions. A major bump for libcurses, libpanel, libform and libmenu. ok deraadt
Diffstat (limited to 'lib/libcurses/tty')
-rw-r--r--lib/libcurses/tty/MKexpanded.sh8
-rw-r--r--lib/libcurses/tty/hardscroll.c52
-rw-r--r--lib/libcurses/tty/hashmap.c102
-rw-r--r--lib/libcurses/tty/lib_mvcur.c304
-rw-r--r--lib/libcurses/tty/lib_tstp.c193
-rw-r--r--lib/libcurses/tty/lib_twait.c308
-rw-r--r--lib/libcurses/tty/lib_vidattr.c97
-rw-r--r--lib/libcurses/tty/tty_display.h13
-rw-r--r--lib/libcurses/tty/tty_input.h4
-rw-r--r--lib/libcurses/tty/tty_update.c827
10 files changed, 1202 insertions, 706 deletions
diff --git a/lib/libcurses/tty/MKexpanded.sh b/lib/libcurses/tty/MKexpanded.sh
index c9de5292ec3..bc6902b5bb7 100644
--- a/lib/libcurses/tty/MKexpanded.sh
+++ b/lib/libcurses/tty/MKexpanded.sh
@@ -1,6 +1,7 @@
#! /bin/sh
+# $OpenBSD: MKexpanded.sh,v 1.4 2010/01/12 23:22:07 nicm Exp $
##############################################################################
-# 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,8 +30,7 @@
#
# Author: Thomas E. Dickey <dickey@clark.net> 1997
#
-# $OpenBSD: MKexpanded.sh,v 1.3 2001/01/22 18:01:59 millert Exp $
-# $From: MKexpanded.sh,v 1.10 2000/12/10 00:24:33 tom Exp $
+# $Id: MKexpanded.sh,v 1.4 2010/01/12 23:22:07 nicm Exp $
#
# Script to generate 'expanded.c', a dummy source that contains functions
# corresponding to complex macros used in this library. By making functions,
@@ -85,7 +85,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/lib/libcurses/tty/hardscroll.c b/lib/libcurses/tty/hardscroll.c
index 2633ce851e9..35cb745db31 100644
--- a/lib/libcurses/tty/hardscroll.c
+++ b/lib/libcurses/tty/hardscroll.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: hardscroll.c,v 1.6 2003/03/18 16:55:54 millert Exp $ */
+/* $OpenBSD: hardscroll.c,v 1.7 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2008 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,6 +31,8 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ * and: Alexander V Lukyanov 1997-1998 *
****************************************************************************/
/******************************************************************************
@@ -147,7 +149,7 @@ AUTHOR
#include <curses.priv.h>
-MODULE_ID("$From: hardscroll.c,v 1.36 2001/01/14 00:17:28 tom Exp $")
+MODULE_ID("$Id: hardscroll.c,v 1.7 2010/01/12 23:22:07 nicm Exp $")
#if defined(SCROLLDEBUG) || defined(HASHDEBUG)
@@ -160,22 +162,25 @@ oldnums[MAXLINES];
# undef TR
# define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); }
+extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
+
#else /* no debug */
/* OLDNUM(n) indicates which line will be shifted to the position n.
if OLDNUM(n) == _NEWINDEX, then the line n in new, not shifted from
somewhere. */
NCURSES_EXPORT_VAR(int *)
-_nc_oldnums = 0;
+_nc_oldnums = 0; /* obsolete: keep for ABI compat */
# if USE_HASHMAP
- static int oldnums_allocated = 0;
-# define oldnums _nc_oldnums
+# define oldnums SP->_oldnum_list
# define OLDNUM(n) oldnums[n]
# else /* !USE_HASHMAP */
# define OLDNUM(n) newscr->_line[n].oldindex
# endif /* !USE_HASHMAP */
+#define OLDNUM_SIZE SP->_oldnum_size
+
#endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */
NCURSES_EXPORT(void)
@@ -185,17 +190,17 @@ _nc_scroll_optimize(void)
int i;
int start, end, shift;
- TR(TRACE_ICALLS, ("_nc_scroll_optimize() begins"));
+ TR(TRACE_ICALLS, (T_CALLED("_nc_scroll_optimize")));
#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
#if USE_HASHMAP
/* get enough storage */
- if (oldnums_allocated < screen_lines) {
+ if (OLDNUM_SIZE < screen_lines) {
int *new_oldnums = typeRealloc(int, screen_lines, oldnums);
if (!new_oldnums)
return;
oldnums = new_oldnums;
- oldnums_allocated = screen_lines;
+ OLDNUM_SIZE = screen_lines;
}
/* calculate the indices */
_nc_hash_map();
@@ -203,8 +208,10 @@ _nc_scroll_optimize(void)
#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
#ifdef TRACE
- if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE))
+ if (USE_TRACEF(TRACE_UPDATE | TRACE_MOVE)) {
_nc_linedump();
+ _nc_unlock_global(tracef);
+ }
#endif /* TRACE */
/* pass 1 - from top to bottom scrolling up */
@@ -255,6 +262,7 @@ _nc_scroll_optimize(void)
}
#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
}
+ TR(TRACE_ICALLS, (T_RETURN("")));
}
#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
@@ -262,24 +270,18 @@ NCURSES_EXPORT(void)
_nc_linedump(void)
/* dump the state of the real and virtual oldnum fields */
{
- static size_t have;
- static char *buf;
-
int n;
+ char *buf = 0;
size_t want = (screen_lines + 1) * 4;
- if (have < want)
- buf = typeMalloc(char, have = want);
-
- (void) strlcpy(buf, "virt", have);
- for (n = 0; n < screen_lines; n++)
- (void) snprintf(buf + strlen(buf), have - strlen(buf), " %02d",
- OLDNUM(n));
- TR(TRACE_UPDATE | TRACE_MOVE, (buf));
-#if NO_LEAKS
- free(buf);
- have = 0;
-#endif
+ if ((buf = typeMalloc(char, want)) != 0) {
+
+ (void) strlcpy(buf, "virt", want);
+ for (n = 0; n < screen_lines; n++)
+ (void) snprintf(buf + strlen(buf), want - strlen(buf), " %02d", OLDNUM(n));
+ TR(TRACE_UPDATE | TRACE_MOVE, (buf));
+ free(buf);
+ }
}
#endif /* defined(TRACE) || defined(SCROLLDEBUG) */
diff --git a/lib/libcurses/tty/hashmap.c b/lib/libcurses/tty/hashmap.c
index bf57cefdbe2..14739fa35a3 100644
--- a/lib/libcurses/tty/hashmap.c
+++ b/lib/libcurses/tty/hashmap.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: hashmap.c,v 1.7 2002/06/22 18:13:05 deraadt Exp $ */
+/* $OpenBSD: hashmap.c,v 1.8 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2006,2007 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 *
@@ -72,7 +72,7 @@ AUTHOR
#include <curses.priv.h>
#include <term.h> /* for back_color_erase */
-MODULE_ID("$From: hashmap.c,v 1.36 2000/12/10 03:04:30 tom Exp $")
+MODULE_ID("$Id: hashmap.c,v 1.8 2010/01/12 23:22:07 nicm Exp $")
#ifdef HASHDEBUG
@@ -83,7 +83,8 @@ MODULE_ID("$From: hashmap.c,v 1.36 2000/12/10 03:04:30 tom Exp $")
# define screen_lines MAXLINES
# define TEXTWIDTH 1
int oldnums[MAXLINES], reallines[MAXLINES];
-static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH];
+static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH];
+static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH];
# define OLDNUM(n) oldnums[n]
# define OLDTEXT(n) oldtext[n]
# define NEWTEXT(m) newtext[m]
@@ -91,7 +92,7 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH];
#else /* !HASHDEBUG */
-# define OLDNUM(n) _nc_oldnums[n]
+# define OLDNUM(n) SP->_oldnum_list[n]
# define OLDTEXT(n) curscr->_line[n].text
# define NEWTEXT(m) newscr->_line[m].text
# define TEXTWIDTH (curscr->_maxx+1)
@@ -99,47 +100,58 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH];
#endif /* !HASHDEBUG */
-#define oldhash (SP->oldhash)
-#define newhash (SP->newhash)
+#define oldhash (SP->oldhash)
+#define newhash (SP->newhash)
+#define hashtab (SP->hashtab)
+#define lines_alloc (SP->hashtab_len)
-static inline unsigned long
-hash(chtype * text)
+#if USE_WIDEC_SUPPORT
+#define HASH_VAL(ch) (ch.chars[0])
+#else
+#define HASH_VAL(ch) (ch)
+#endif
+
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+
+static NCURSES_INLINE unsigned long
+hash(NCURSES_CH_T * text)
{
int i;
- chtype ch;
+ NCURSES_CH_T ch;
unsigned long result = 0;
for (i = TEXTWIDTH; i > 0; i--) {
ch = *text++;
- result += (result << 5) + ch;
+ result += (result << 5) + HASH_VAL(ch);
}
return result;
}
/* approximate update cost */
static int
-update_cost(chtype * from, chtype * to)
+update_cost(NCURSES_CH_T * from, NCURSES_CH_T * to)
{
int cost = 0;
int i;
- for (i = TEXTWIDTH; i > 0; i--)
- if (*from++ != *to++)
+ for (i = TEXTWIDTH; i > 0; i--, from++, to++)
+ if (!(CharEq(*from, *to)))
cost++;
return cost;
}
+
static int
-update_cost_from_blank(chtype * to)
+update_cost_from_blank(NCURSES_CH_T * to)
{
int cost = 0;
int i;
- chtype blank = BLANK;
+ NCURSES_CH_T blank = blankchar;
if (back_color_erase)
- blank |= (stdscr->_bkgd & A_COLOR);
+ SetPair(blank, GetPair(stdscr->_nc_bkgd));
- for (i = TEXTWIDTH; i > 0; i--)
- if (blank != *to++)
+ for (i = TEXTWIDTH; i > 0; i--, to++)
+ if (!(CharEq(blank, *to)))
cost++;
return cost;
@@ -149,7 +161,7 @@ update_cost_from_blank(chtype * 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;
@@ -173,15 +185,6 @@ cost_effective(const int from, const int to, const bool blank)
+ update_cost(OLDTEXT(from), NEWTEXT(to)))) ? TRUE : FALSE;
}
-typedef struct {
- unsigned long hashval;
- int oldcount, newcount;
- int oldindex, newindex;
-} sym;
-
-static sym *hashtab = 0;
-static int lines_alloc = 0;
-
static void
grow_hunks(void)
{
@@ -269,14 +272,14 @@ grow_hunks(void)
NCURSES_EXPORT(void)
_nc_hash_map(void)
{
- sym *sp;
+ HASHMAP *sp;
register int i;
int start, shift, size;
if (screen_lines > lines_alloc) {
if (hashtab)
free(hashtab);
- hashtab = typeMalloc(sym, (screen_lines + 1) * 2);
+ hashtab = typeMalloc(HASHMAP, (screen_lines + 1) * 2);
if (!hashtab) {
if (oldhash) {
FreeAndNull(oldhash);
@@ -296,9 +299,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++) {
@@ -389,11 +392,6 @@ _nc_hash_map(void)
/* After clearing invalid hunks, try grow the rest. */
grow_hunks();
-
-#if NO_LEAKS
- FreeAndNull(hashtab);
- lines_alloc = 0;
-#endif
}
NCURSES_EXPORT(void)
@@ -406,7 +404,7 @@ _nc_make_oldhash(int i)
NCURSES_EXPORT(void)
_nc_scroll_oldhash(int n, int top, int bot)
{
- int size;
+ size_t size;
int i;
if (!oldhash)
@@ -451,11 +449,14 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
char line[BUFSIZ], *st, *last;
int n;
- SP = typeCalloc(SCREEN, 1);
+ if (setupterm(NULL, fileno(stdout), (int *) 0) == ERR)
+ return EXIT_FAILURE;
+ (void) _nc_alloc_screen();
+
for (n = 0; n < screen_lines; n++) {
reallines[n] = n;
oldnums[n] = _NEWINDEX;
- oldtext[n][0] = newtext[n][0] = '.';
+ CharOf(oldtext[n][0]) = CharOf(newtext[n][0]) = '.';
}
if (isatty(fileno(stdin)))
@@ -467,7 +468,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
for (;;) {
/* grab a test command */
if (fgets(line, sizeof(line), stdin) == (char *) NULL)
- exit(EXIT_SUCCESS);
+ break;
switch (line[0]) {
case '#': /* comment */
@@ -489,22 +490,22 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
case 'n': /* use following letters as text of new lines */
for (n = 0; n < screen_lines; n++)
- newtext[n][0] = '.';
+ CharOf(newtext[n][0]) = '.';
for (n = 0; n < screen_lines; n++)
if (line[n + 1] == '\n')
break;
else
- newtext[n][0] = line[n + 1];
+ CharOf(newtext[n][0]) = line[n + 1];
break;
case 'o': /* use following letters as text of old lines */
for (n = 0; n < screen_lines; n++)
- oldtext[n][0] = '.';
+ CharOf(oldtext[n][0]) = '.';
for (n = 0; n < screen_lines; n++)
if (line[n + 1] == '\n')
break;
else
- oldtext[n][0] = line[n + 1];
+ CharOf(oldtext[n][0]) = line[n + 1];
break;
case 'd': /* dump state of test arrays */
@@ -513,12 +514,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
#endif
(void) fputs("Old lines: [", stdout);
for (n = 0; n < screen_lines; n++)
- putchar(oldtext[n][0]);
+ putchar(CharOf(oldtext[n][0]));
putchar(']');
putchar('\n');
(void) fputs("New lines: [", stdout);
for (n = 0; n < screen_lines; n++)
- putchar(newtext[n][0]);
+ putchar(CharOf(newtext[n][0]));
putchar(']');
putchar('\n');
break;
@@ -532,12 +533,17 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
_nc_scroll_optimize();
(void) fputs("Done.\n", stderr);
break;
+ default:
case '?':
usage();
break;
}
}
+#if NO_LEAKS
+ _nc_free_and_exit(EXIT_SUCCESS);
+#else
return EXIT_SUCCESS;
+#endif
}
#endif /* HASHDEBUG */
diff --git a/lib/libcurses/tty/lib_mvcur.c b/lib/libcurses/tty/lib_mvcur.c
index df0a3080ade..bd0b4334345 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.12 2007/05/17 04:34:50 ray Exp $ */
+/* $OpenBSD: lib_mvcur.c,v 1.13 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2008 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,6 +31,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 *
****************************************************************************/
/*
@@ -110,7 +111,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))
/****************************************************************************
*
@@ -154,12 +157,8 @@
#include <term.h>
#include <ctype.h>
-MODULE_ID("$From: lib_mvcur.c,v 1.77 2000/12/10 03:04:30 tom Exp $")
+MODULE_ID("$Id: lib_mvcur.c,v 1.13 2010/01/12 23:22:07 nicm 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 */
@@ -209,8 +208,7 @@ trace_normalized_cost(const char *capname, const char *cap, int affcnt)
#endif
NCURSES_EXPORT(int)
-_nc_msec_cost
-(const char *const cap, int affcnt)
+_nc_msec_cost(const char *const cap, int affcnt)
/* compute the cost of a given operation */
{
if (cap == 0)
@@ -225,16 +223,16 @@ _nc_msec_cost
float number = 0.0;
for (cp += 2; *cp != '>'; cp++) {
- if (isdigit(CharOf(*cp)))
+ if (isdigit(UChar(*cp)))
number = number * 10 + (*cp - '0');
else if (*cp == '*')
number *= affcnt;
- else if (*cp == '.' && (*++cp != '>') && isdigit(CharOf(*cp)))
+ else if (*cp == '.' && (*++cp != '>') && isdigit(UChar(*cp)))
number += (*cp - '0') / 10.0;
}
#if NCURSES_NO_PADDING
- if (!(SP->_no_padding))
+ if (!GetNoPadding(SP))
#endif
cum_cost += number * 10;
} else
@@ -261,7 +259,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));
}
}
@@ -299,10 +297,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));
@@ -312,8 +311,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);
@@ -359,13 +363,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);
@@ -374,15 +378,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));
@@ -417,8 +428,11 @@ _nc_mvcur_wrap(void)
mvcur(-1, -1, screen_lines - 1, 0);
/* set cursor to normal mode */
- if (SP->_cursor != -1)
+ if (SP->_cursor != -1) {
+ int cursor = SP->_cursor;
curs_set(1);
+ SP->_cursor = cursor;
+ }
if (exit_ca_mode) {
TPUTS_TRACE("exit_ca_mode");
@@ -444,7 +458,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);
@@ -487,7 +501,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;
}
@@ -497,11 +511,13 @@ 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;
}
- if (cursor_down && (n * SP->_cud1_cost < vcost)) {
+ if (cursor_down
+ && (*cursor_down != '\n' || SP->_nl)
+ && (n * SP->_cud1_cost < vcost)) {
vcost = repeated_append(_nc_str_copy(target, &save), 0,
SP->_cud1_cost, n, cursor_down);
}
@@ -509,10 +525,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)) {
@@ -535,7 +551,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;
}
@@ -545,7 +561,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;
}
@@ -571,7 +587,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
@@ -585,9 +600,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(TextOf(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.
@@ -600,23 +617,28 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
if (ovw) {
int i;
- for (i = 0; i < n; i++)
- if ((WANT_CHAR(to_y, from_x + i) & A_ATTRIBUTES) != CURRENT_ATTR) {
+ for (i = 0; i < n; i++) {
+ NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i);
+ if (!SameAttrOf(ch, SCREEN_ATTRS(SP))
+#if USE_WIDEC_SUPPORT
+ || !Charable(ch)
+#endif
+ ) {
ovw = FALSE;
break;
}
+ }
}
if (ovw) {
int i;
for (i = 0; i < n; i++)
- *check.s_tail++ = WANT_CHAR(to_y, from_x + i);
+ *check.s_tail++ = (char) CharOf(WANT_CHAR(to_y,
+ from_x + i));
*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);
}
@@ -632,7 +654,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;
}
@@ -684,7 +706,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) */
{
@@ -703,7 +725,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;
@@ -812,78 +834,122 @@ 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);
}
NCURSES_EXPORT(int)
-mvcur
-(int yold, int xold, int ynew, int xnew)
+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));
+ NCURSES_CH_T oldattr;
+ int code;
- if (yold == ynew && xold == xnew)
- return (OK);
+ TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
+ yold, xold, ynew, xnew));
- /*
- * 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 (SP == 0) {
+ code = ERR;
+ } else if (yold == ynew && xold == xnew) {
+ code = OK;
+ } else {
- if (xnew >= screen_columns) {
- ynew += xnew / screen_columns;
- xnew %= screen_columns;
- }
- if (xold >= screen_columns) {
- int l;
-
- 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 (carriage_return) {
- TPUTS_TRACE("carriage_return");
- tputs(carriage_return, 0, _nc_outch);
- } else
- putchar('\r');
- xold = 0;
+ /*
+ * 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;
+ }
+
+ /*
+ * 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 (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");
+ putp(carriage_return);
+ } else
+ _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;
}
}
- }
- 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 */
- return (onscreen_mvcur(yold, xold, ynew, xnew, TRUE));
+ /* destination location is on screen now */
+ code = 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)
@@ -899,16 +965,15 @@ NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL;
#include <tic.h>
#include <dump_entry.h>
+#include <time.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)
-tputs
-(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED)
+tputs(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED)
/* stub tputs() that dumps sequences in a visible form */
{
if (profiling)
@@ -931,18 +996,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)
@@ -964,9 +1024,9 @@ roll(int n)
int
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
- (void) strlcpy(tname, termname(), sizeof(tname));
+ strlcpy(tname, sizeof(tname), getenv("TERM"));
load_term();
- _nc_setupscreen(lines, columns, stdout);
+ _nc_setupscreen(lines, columns, stdout, FALSE, 0);
baudrate();
_nc_mvcur_init();
@@ -983,9 +1043,9 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
(void) fputs("> ", stdout);
if (fgets(buf, sizeof(buf), stdin) == NULL) {
- if (ferror(stdin))
- fputs("ferror on stdin", stderr);
- break;
+ if (ferror(stdin))
+ fputs("ferror on stdin", stderr);
+ break;
}
if (buf[0] == '?') {
@@ -1033,13 +1093,13 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
before.tv_sec)
* 1000000));
} else if (buf[0] == 'r') {
- (void) strlcpy(tname, termname(), sizeof(tname));
+ (void) strlcpy(tname, sizeof(tname), termname());
load_term();
} 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);
+ _nc_get_hash_table(FALSE));
if (np == NULL)
(void) printf("No such capability as \"%s\"\n", capname);
@@ -1067,7 +1127,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);
putchar('\n');
} else if (buf[0] == 'o') {
if (_nc_optimize_enable & OPTIMIZE_MVCUR) {
diff --git a/lib/libcurses/tty/lib_tstp.c b/lib/libcurses/tty/lib_tstp.c
index 0e862bbcde5..a6126846461 100644
--- a/lib/libcurses/tty/lib_tstp.c
+++ b/lib/libcurses/tty/lib_tstp.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_tstp.c,v 1.9 2001/12/06 04:26:00 deraadt Exp $ */
+/* $OpenBSD: lib_tstp.c,v 1.10 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2008 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,6 +31,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1995-on *
****************************************************************************/
/*
@@ -39,17 +40,15 @@
** The routine _nc_signal_handler().
**
*/
-
#include <curses.priv.h>
-#include <signal.h>
#include <SigAction.h>
#if SVR4_ACTION && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
-MODULE_ID("$From: lib_tstp.c,v 1.24 2000/12/10 03:04:30 tom Exp $")
+MODULE_ID("$Id: lib_tstp.c,v 1.10 2010/01/12 23:22:07 nicm Exp $")
#if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC)
#define USE_SIGTSTP 1
@@ -57,6 +56,41 @@ MODULE_ID("$From: lib_tstp.c,v 1.24 2000/12/10 03:04:30 tom Exp $")
#define USE_SIGTSTP 0
#endif
+#ifdef TRACE
+static const char *
+signal_name(int sig)
+{
+ switch (sig) {
+ case SIGALRM:
+ return "SIGALRM";
+#ifdef SIGCONT
+ case SIGCONT:
+ return "SIGCONT";
+#endif
+ case SIGINT:
+ return "SIGINT";
+ case SIGQUIT:
+ return "SIGQUIT";
+ case SIGTERM:
+ return "SIGTERM";
+#ifdef SIGTSTP
+ case SIGTSTP:
+ return "SIGTSTP";
+#endif
+#ifdef SIGTTOU
+ case SIGTTOU:
+ return "SIGTTOU";
+#endif
+#ifdef SIGWINCH
+ case SIGWINCH:
+ return "SIGWINCH";
+#endif
+ default:
+ return "unknown signal";
+ }
+}
+#endif
+
/*
* Note: This code is fragile! Its problem is that different OSs
* handle restart of system calls interrupted by signals differently.
@@ -202,16 +236,14 @@ tstp(int dummy GCC_UNUSED)
static void
cleanup(int sig)
{
- static int nested;
-
/*
- * XXX signal race. The kind of comment is completely ingenius!
+ * XXX signal race. This kind of comment is completely ingenious!
*
* Actually, doing any sort of I/O from within an signal handler is
* "unsafe". But we'll _try_ to clean up the screen and terminal
* settings on the way out.
*/
- if (!nested++
+ if (!_nc_globals.cleanup_nested++
&& (sig == SIGINT
|| sig == SIGQUIT)) {
#if HAVE_SIGACTION || HAVE_SIGVEC
@@ -219,24 +251,22 @@ cleanup(int sig)
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = SIG_IGN;
- if (sigaction(sig, &act, (sigaction_t *) 0) == 0)
+ if (sigaction(sig, &act, NULL) == 0)
#else
if (signal(sig, SIG_IGN) != SIG_ERR)
#endif
{
- SCREEN *scan = _nc_screen_chain;
- while (scan) {
- if (SP != 0
- && SP->_ofp != 0
- && isatty(fileno(SP->_ofp))) {
- SP->_cleanup = TRUE;
- SP->_outch = _nc_outch;
+ SCREEN *scan;
+ for (each_screen(scan)) {
+ if (scan->_ofp != 0
+ && isatty(fileno(scan->_ofp))) {
+ scan->_cleanup = TRUE;
+ scan->_outch = _nc_outch;
}
set_term(scan);
endwin();
if (SP)
SP->_endwin = FALSE; /* in case we have an atexit! */
- scan = scan->_next_screen;
}
}
}
@@ -247,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_globals.have_sigwinch = 1;
}
#endif /* USE_SIGWINCH */
@@ -259,43 +285,57 @@ sigwinch(int sig GCC_UNUSED)
* If the given signal is still in its default state, set it to the given
* handler.
*/
-#if HAVE_SIGACTION || HAVE_SIGVEC
static int
-CatchIfDefault(int sig, sigaction_t * act)
+CatchIfDefault(int sig, RETSIGTYPE (*handler) (int))
{
+ int result;
+#if HAVE_SIGACTION || HAVE_SIGVEC
sigaction_t old_act;
+ sigaction_t new_act;
+
+ memset(&new_act, 0, sizeof(new_act));
+ sigemptyset(&new_act.sa_mask);
+#ifdef SA_RESTART
+#ifdef SIGWINCH
+ if (sig != SIGWINCH)
+#endif
+ new_act.sa_flags |= SA_RESTART;
+#endif /* SA_RESTART */
+ new_act.sa_handler = handler;
- if (sigaction(sig, (sigaction_t *) 0, &old_act) == 0
+ if (sigaction(sig, NULL, &old_act) == 0
&& (old_act.sa_handler == SIG_DFL
+ || old_act.sa_handler == handler
#if USE_SIGWINCH
|| (sig == SIGWINCH && old_act.sa_handler == SIG_IGN)
#endif
)) {
- (void) sigaction(sig, act, (sigaction_t *) 0);
- return TRUE;
+ (void) sigaction(sig, &new_act, NULL);
+ result = TRUE;
+ } else {
+ result = FALSE;
}
- return FALSE;
-}
-#else
-static int
-CatchIfDefault(int sig, RETSIGTYPE(*handler) (int))
-{
- void (*ohandler) (int);
+#else /* !HAVE_SIGACTION */
+ RETSIGTYPE (*ohandler) (int);
ohandler = signal(sig, SIG_IGN);
if (ohandler == SIG_DFL
+ || ohandler == handler
#if USE_SIGWINCH
|| (sig == SIGWINCH && ohandler == SIG_IGN)
#endif
) {
signal(sig, handler);
- return TRUE;
+ result = TRUE;
} else {
signal(sig, ohandler);
- return FALSE;
+ result = FALSE;
}
-}
#endif
+ T(("CatchIfDefault - will %scatch %s",
+ result ? "" : "not ", signal_name(sig)));
+ return result;
+}
/*
* This is invoked once at the beginning (e.g., from 'initscr()'), to
@@ -311,60 +351,43 @@ CatchIfDefault(int sig, RETSIGTYPE(*handler) (int))
NCURSES_EXPORT(void)
_nc_signal_handler(bool enable)
{
+ T((T_CALLED("_nc_signal_handler(%d)"), enable));
#if USE_SIGTSTP /* Xenix 2.x doesn't have SIGTSTP, for example */
- static sigaction_t act, oact;
- static int ignore;
-
- if (!ignore) {
- if (!enable) {
- act.sa_handler = SIG_IGN;
- sigaction(SIGTSTP, &act, &oact);
- } else if (act.sa_handler) {
- sigaction(SIGTSTP, &oact, NULL);
- } else { /*initialize */
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
-#if USE_SIGWINCH
- act.sa_handler = sigwinch;
- CatchIfDefault(SIGWINCH, &act);
-#endif
-
+ {
+ static bool ignore_tstp = FALSE;
+
+ if (!ignore_tstp) {
+ static sigaction_t new_sigaction, old_sigaction;
+
+ if (!enable) {
+ new_sigaction.sa_handler = SIG_IGN;
+ sigaction(SIGTSTP, &new_sigaction, &old_sigaction);
+ } else if (new_sigaction.sa_handler != SIG_DFL) {
+ sigaction(SIGTSTP, &old_sigaction, NULL);
+ } else if (sigaction(SIGTSTP, NULL, &old_sigaction) == 0
+ && (old_sigaction.sa_handler == SIG_DFL)) {
+ sigemptyset(&new_sigaction.sa_mask);
#ifdef SA_RESTART
- act.sa_flags |= SA_RESTART;
+ new_sigaction.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
- act.sa_handler = cleanup;
- CatchIfDefault(SIGINT, &act);
- CatchIfDefault(SIGTERM, &act);
-
- act.sa_handler = tstp;
- if (!CatchIfDefault(SIGTSTP, &act))
- ignore = TRUE;
+ new_sigaction.sa_handler = tstp;
+ (void) sigaction(SIGTSTP, &new_sigaction, NULL);
+ } else {
+ ignore_tstp = TRUE;
+ }
}
}
-#else /* !USE_SIGTSTP */
- if (enable) {
-#if HAVE_SIGACTION || HAVE_SIGVEC
- static sigaction_t act;
- sigemptyset(&act.sa_mask);
-#if USE_SIGWINCH
- act.sa_handler = sigwinch;
- CatchIfDefault(SIGWINCH, &act);
-#endif
-#ifdef SA_RESTART
- act.sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
- act.sa_handler = cleanup;
- CatchIfDefault(SIGINT, &act);
- CatchIfDefault(SIGTERM, &act);
-
-#else /* !(HAVE_SIGACTION || HAVE_SIGVEC) */
+#endif /* !USE_SIGTSTP */
- CatchIfDefault(SIGINT, cleanup);
- CatchIfDefault(SIGTERM, cleanup);
+ if (!_nc_globals.init_signals) {
+ if (enable) {
+ CatchIfDefault(SIGINT, cleanup);
+ CatchIfDefault(SIGTERM, cleanup);
#if USE_SIGWINCH
- CatchIfDefault(SIGWINCH, sigwinch);
+ CatchIfDefault(SIGWINCH, sigwinch);
#endif
-#endif /* !(HAVE_SIGACTION || HAVE_SIGVEC) */
+ _nc_globals.init_signals = TRUE;
+ }
}
-#endif /* !USE_SIGTSTP */
+ returnVoid;
}
diff --git a/lib/libcurses/tty/lib_twait.c b/lib/libcurses/tty/lib_twait.c
index 0b7c4d2949b..fcbc3cfdf47 100644
--- a/lib/libcurses/tty/lib_twait.c
+++ b/lib/libcurses/tty/lib_twait.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_twait.c,v 1.8 2001/01/22 18:02:00 millert Exp $ */
+/* $OpenBSD: lib_twait.c,v 1.9 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2008 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,6 +31,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 *
****************************************************************************/
/*
@@ -42,12 +43,18 @@
** comments, none of the original code remains - T.Dickey).
*/
+#include <curses.priv.h>
+
+#if defined __HAIKU__ && defined __BEOS__
+#undef __BEOS__
+#endif
+
#ifdef __BEOS__
+#undef false
+#undef true
#include <OS.h>
#endif
-#include <curses.priv.h>
-
#if USE_FUNC_POLL
# if HAVE_SYS_TIME_H
# include <sys/time.h>
@@ -61,36 +68,64 @@
# endif
#endif
-MODULE_ID("$From: lib_twait.c,v 1.41 2000/12/10 03:04:30 tom Exp $")
+#undef CUR
+
+MODULE_ID("$Id: lib_twait.c,v 1.9 2010/01/12 23:22:07 nicm Exp $")
static long
-_nc_gettime(bool first)
+_nc_gettime(TimeType * t0, bool first)
{
long res;
-#if HAVE_GETTIMEOFDAY
-# define PRECISE_GETTIME 1
- static struct timeval t0;
- struct timeval t1;
+#if PRECISE_GETTIME
+ TimeType t1;
gettimeofday(&t1, (struct timezone *) 0);
if (first) {
- t0 = t1;
+ *t0 = t1;
+ res = 0;
+ } else {
+ /* .tv_sec and .tv_usec are unsigned, be careful when subtracting */
+ if (t0->tv_usec > t1.tv_usec) {
+ t1.tv_usec += 1000000; /* Convert 1s in 1e6 microsecs */
+ 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;
time_t t1 = time((time_t *) 0);
if (first) {
- t0 = t1;
+ *t0 = t1;
}
- res = (t1 - t0) * 1000;
+ res = (t1 - *t0) * 1000;
#endif
- T(("%s time: %ld msec", first ? "get" : "elapsed", res));
+ TR(TRACE_IEVENT, ("%s time: %ld msec", first ? "get" : "elapsed", res));
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,55 +134,137 @@ _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(SCREEN *sp,
+ int mode,
+ int milliseconds,
+ int *timeleft
+ EVENTLIST_2nd(_nc_eventlist * evl))
{
int fd;
int count;
+ int result = 0;
+ TimeType t0;
- 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;
- static size_t setsize;
- size_t nsetsize;
- int readfd;
+ fd_set set;
#endif
long starttime, returntime;
- T(("start twait: %d milliseconds, mode: %d", milliseconds, mode));
+ TR(TRACE_IEVENT, ("start twait: %d milliseconds, mode: %d",
+ milliseconds, mode));
-#if PRECISE_GETTIME
+#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 && HAVE_NANOSLEEP
retry:
#endif
- starttime = _nc_gettime(TRUE);
+ starttime = _nc_gettime(&t0, TRUE);
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].fd = sp->_ifd;
fds[count].events = POLLIN;
count++;
}
if ((mode & 2)
- && (fd = SP->_mouse_fd) >= 0) {
+ && (fd = sp->_mouse_fd) >= 0) {
fds[count].fd = fd;
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__)
/*
@@ -158,73 +275,124 @@ _nc_timed_wait
*
* 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);
milliseconds = 0;
}
#elif HAVE_SELECT
+ /*
+ * select() modifies the fd_set arguments; do this in the
+ * loop.
+ */
+ FD_ZERO(&set);
+
if (mode & 1) {
- count = SP->_ifd;
- readfd = SP->_ifd;
+ FD_SET(sp->_ifd, &set);
+ count = sp->_ifd + 1;
}
- if ((mode & 2) && (fd = SP->_mouse_fd) >= 0) {
- count = max(fd, count);
- readfd = fd;
+ if ((mode & 2)
+ && (fd = sp->_mouse_fd) >= 0) {
+ 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];
- /*
- * grow set as needed.
- */
- nsetsize = howmany(count, NFDBITS) * sizeof(fd_mask);
- if (setsize == 0 || setsize < nsetsize) {
- setsize = nsetsize;
- set = _nc_doalloc(set, setsize);
+ 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);
+ }
+ }
}
-
- /*
- * select() modifies the fd_set arguments; do this in the
- * loop.
- */
- memset(set, 0, setsize);
- FD_SET(readfd, set);
+#endif
if (milliseconds >= 0) {
struct timeval ntimeout;
ntimeout.tv_sec = milliseconds / 1000;
ntimeout.tv_usec = (milliseconds % 1000) * 1000;
- result = select(count + 1, set, NULL, NULL, &ntimeout);
+ result = select(count, &set, NULL, NULL, &ntimeout);
} else {
- result = select(count + 1, set, NULL, NULL, NULL);
+ 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
- returntime = _nc_gettime(FALSE);
+#endif /* USE_FUNC_POLL, etc */
+
+ returntime = _nc_gettime(&t0, 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
@@ -232,7 +400,7 @@ _nc_timed_wait
* 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;
}
@@ -242,8 +410,8 @@ _nc_timed_wait
if (timeleft)
*timeleft = milliseconds;
- T(("end twait: returned %d (%d), remaining time %d msec",
- result, errno, milliseconds));
+ TR(TRACE_IEVENT, ("end twait: returned %d (%d), remaining time %d msec",
+ result, errno, milliseconds));
/*
* Both 'poll()' and 'select()' return the number of file descriptors
@@ -255,7 +423,7 @@ _nc_timed_wait
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,16 +433,20 @@ _nc_timed_wait
result = 1; /* redundant, but simple */
#elif HAVE_SELECT
if ((mode & 2)
- && (fd = SP->_mouse_fd) >= 0
- && FD_ISSET(fd, set))
+ && (fd = sp->_mouse_fd) >= 0
+ && FD_ISSET(fd, &set))
result |= 2;
if ((mode & 1)
- && FD_ISSET(SP->_ifd, set))
+ && FD_ISSET(sp->_ifd, &set))
result |= 1;
#endif
} else
result = 0;
}
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((mode & 4) && evl && evl->result_flags)
+ result |= 4;
+#endif
return (result);
}
diff --git a/lib/libcurses/tty/lib_vidattr.c b/lib/libcurses/tty/lib_vidattr.c
index 4a5c9354b72..5553a348ead 100644
--- a/lib/libcurses/tty/lib_vidattr.c
+++ b/lib/libcurses/tty/lib_vidattr.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_vidattr.c,v 1.8 2001/01/22 18:02:00 millert Exp $ */
+/* $OpenBSD: lib_vidattr.c,v 1.9 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2006,2007 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,6 +31,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 *
****************************************************************************/
/*
@@ -66,7 +67,7 @@
#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$From: lib_vidattr.c,v 1.36 2000/12/10 03:05:48 tom Exp $")
+MODULE_ID("$Id: lib_vidattr.c,v 1.9 2010/01/12 23:22:07 nicm Exp $")
#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
@@ -88,15 +89,14 @@ MODULE_ID("$From: lib_vidattr.c,v 1.36 2000/12/10 03:05:48 tom Exp $")
} \
}
+#define PreviousAttr _nc_prescreen.previous_attr
+
NCURSES_EXPORT(int)
-vidputs
-(attr_t newmode, int (*outc) (int))
+vidputs(chtype newmode, int (*outc) (int))
{
- static attr_t previous_attr = A_NORMAL;
attr_t turn_on, turn_off;
int pair;
bool reverse = FALSE;
- bool used_ncv = FALSE;
bool can_color = (SP == 0 || SP->_coloron);
#if NCURSES_EXT_FUNCS
bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color);
@@ -104,19 +104,56 @@ vidputs
#define fix_pair0 FALSE
#endif
+ newmode &= A_ATTRIBUTES;
T((T_CALLED("vidputs(%s)"), _traceattr(newmode)));
/* this allows us to go on whether or not newterm() has been called */
if (SP)
- previous_attr = SP->_current_attr;
+ PreviousAttr = AttrOf(SCREEN_ATTRS(SP));
- TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(previous_attr)));
+ TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(PreviousAttr)));
-#if !USE_XMC_SUPPORT
if ((SP != 0)
- && (magic_cookie_glitch > 0))
+ && (magic_cookie_glitch > 0)) {
+#if USE_XMC_SUPPORT
+ static const 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
@@ -150,7 +187,7 @@ vidputs
newmode &= ~mask;
}
- if (newmode == previous_attr)
+ if (newmode == PreviousAttr)
returnCode(OK);
pair = PAIR_NUMBER(newmode);
@@ -159,17 +196,17 @@ vidputs
newmode &= ~A_REVERSE;
}
- turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR;
- turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR;
+ turn_off = (~newmode & PreviousAttr) & ALL_BUT_COLOR;
+ turn_on = (newmode & ~PreviousAttr) & ALL_BUT_COLOR;
- SetColorsIf(((pair == 0) && !fix_pair0), previous_attr);
+ SetColorsIf(((pair == 0) && !fix_pair0), PreviousAttr);
if (newmode == A_NORMAL) {
- if ((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) {
+ if ((PreviousAttr & A_ALTCHARSET) && exit_alt_charset_mode) {
doPut(exit_alt_charset_mode);
- previous_attr &= ~A_ALTCHARSET;
+ PreviousAttr &= ~A_ALTCHARSET;
}
- if (previous_attr) {
+ if (PreviousAttr) {
if (exit_attribute_mode) {
doPut(exit_attribute_mode);
} else {
@@ -180,11 +217,11 @@ vidputs
TurnOff(A_STANDOUT, exit_standout_mode);
}
}
- previous_attr &= ~A_COLOR;
+ PreviousAttr &= ALL_BUT_COLOR;
}
- SetColorsIf((pair != 0) || fix_pair0, previous_attr);
- } else if (set_attributes && !used_ncv) {
+ SetColorsIf((pair != 0) || fix_pair0, PreviousAttr);
+ } else if (set_attributes) {
if (turn_on || turn_off) {
TPUTS_TRACE("set_attributes");
tputs(tparm(set_attributes,
@@ -197,9 +234,9 @@ vidputs
(newmode & A_INVIS) != 0,
(newmode & A_PROTECT) != 0,
(newmode & A_ALTCHARSET) != 0), 1, outc);
- previous_attr &= ~A_COLOR;
+ PreviousAttr &= ALL_BUT_COLOR;
}
- SetColorsIf((pair != 0) || fix_pair0, previous_attr);
+ SetColorsIf((pair != 0) || fix_pair0, PreviousAttr);
} else {
TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off)));
@@ -216,10 +253,10 @@ 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);
+ PreviousAttr &= ALL_BUT_COLOR;
}
- SetColorsIf((pair != 0) || fix_pair0, previous_attr);
+ SetColorsIf((pair != 0) || fix_pair0, PreviousAttr);
TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on)));
/* *INDENT-OFF* */
@@ -232,12 +269,14 @@ vidputs
TurnOn(A_PROTECT, enter_protected_mode);
TurnOn(A_INVIS, enter_secure_mode);
TurnOn(A_UNDERLINE, enter_underline_mode);
+#if USE_WIDEC_SUPPORT
TurnOn(A_HORIZONTAL, enter_horizontal_hl_mode);
TurnOn(A_LEFT, enter_left_hl_mode);
TurnOn(A_LOW, enter_low_hl_mode);
TurnOn(A_RIGHT, enter_right_hl_mode);
TurnOn(A_TOP, enter_top_hl_mode);
TurnOn(A_VERTICAL, enter_vertical_hl_mode);
+#endif
/* *INDENT-ON* */
}
@@ -246,15 +285,15 @@ vidputs
newmode |= A_REVERSE;
if (SP)
- SP->_current_attr = newmode;
+ SetAttr(SCREEN_ATTRS(SP), newmode);
else
- previous_attr = newmode;
+ PreviousAttr = newmode;
returnCode(OK);
}
NCURSES_EXPORT(int)
-vidattr(attr_t newmode)
+vidattr(chtype newmode)
{
T((T_CALLED("vidattr(%s)"), _traceattr(newmode)));
diff --git a/lib/libcurses/tty/tty_display.h b/lib/libcurses/tty/tty_display.h
index f1e0f47e1d1..f62abe2891a 100644
--- a/lib/libcurses/tty/tty_display.h
+++ b/lib/libcurses/tty/tty_display.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: tty_display.h,v 1.3 2001/01/22 18:02:00 millert Exp $ */
+/* $OpenBSD: tty_display.h,v 1.4 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * 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 *
@@ -31,6 +31,9 @@
#ifndef TTY_DISPLAY_H
#define TTY_DISPLAY_H 1
+/*
+ * $Id: tty_display.h,v 1.4 2010/01/12 23:22:07 nicm 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);
@@ -113,11 +116,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 \
@@ -130,7 +133,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/lib/libcurses/tty/tty_input.h b/lib/libcurses/tty/tty_input.h
index 21f551a49a2..cff0bb54e4b 100644
--- a/lib/libcurses/tty/tty_input.h
+++ b/lib/libcurses/tty/tty_input.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty_input.h,v 1.2 2001/01/22 18:02:00 millert Exp $ */
+/* $OpenBSD: tty_input.h,v 1.3 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
@@ -29,7 +29,7 @@
****************************************************************************/
/*
- * $From: tty_input.h,v 1.2 2000/12/10 02:26:51 tom Exp $
+ * $Id: tty_input.h,v 1.3 2010/01/12 23:22:07 nicm Exp $
*/
#ifndef TTY_INPUT_H
diff --git a/lib/libcurses/tty/tty_update.c b/lib/libcurses/tty/tty_update.c
index 28b6b99927e..bd2f088adf6 100644
--- a/lib/libcurses/tty/tty_update.c
+++ b/lib/libcurses/tty/tty_update.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: tty_update.c,v 1.15 2001/02/22 04:16:35 millert Exp $ */
+/* $OpenBSD: tty_update.c,v 1.16 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2008 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,24 +31,31 @@
/****************************************************************************
* 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).
*
*-----------------------------------------------------------------*/
+#include <curses.priv.h>
+
+#if defined __HAIKU__ && defined __BEOS__
+#undef __BEOS__
+#endif
+
#ifdef __BEOS__
+#undef false
+#undef true
#include <OS.h>
#endif
-#include <curses.priv.h>
-
#if defined(TRACE) && HAVE_SYS_TIMES_H && HAVE_TIMES
#define USE_TRACE_TIMES 1
#else
@@ -70,9 +77,10 @@
#endif
#endif
+#include <ctype.h>
#include <term.h>
-MODULE_ID("$From: tty_update.c,v 1.151 2001/02/03 23:41:55 tom Exp $")
+MODULE_ID("$Id: tty_update.c,v 1.16 2010/01/12 23:22:07 nicm Exp $")
/*
* This define controls the line-breakout optimization. Every once in a
@@ -87,6 +95,9 @@ MODULE_ID("$From: tty_update.c,v 1.151 2001/02/03 23:41:55 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,12 +105,12 @@ MODULE_ID("$From: tty_update.c,v 1.151 2001/02/03 23:41:55 tom Exp $")
*/
/* #define POSITION_DEBUG */
-static inline chtype ClrBlank(WINDOW *win);
+static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win);
static int ClrBottom(int total);
-static void ClearScreen(chtype blank);
+static void ClearScreen(NCURSES_CH_T blank);
static void ClrUpdate(void);
static void DelChar(int count);
-static void InsStr(chtype * line, int count);
+static void InsStr(NCURSES_CH_T * line, int count);
static void TransformLine(int const lineno);
#ifdef POSITION_DEBUG
@@ -162,56 +173,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)
{
- chtype 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
-PutAttrChar(chtype ch)
+static NCURSES_INLINE void
+PutAttrChar(CARG_CH_T ch)
{
- int data;
-
- if (tilde_glitch && (TextOf(ch) == '~'))
- ch = ('`' | AttrOf(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)",
- _tracechtype(ch),
+ _tracech_t(ch),
SP->_cursrow, SP->_curscol));
- UpdateAttrs(ch);
- data = TextOf(ch);
+#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('`'), AttrOf(attr));
+ ch = CHREF(tilde);
+ }
+
+ 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(data);
- } else {
- putc(data, SP->_ofp); /* macro's fastest... */
-#ifdef TRACE
- _nc_outchars++;
-#endif /* TRACE */
+ SP->_outch(UChar(ch));
+ } else
+#endif
+ {
+ PUTC(CHDEREF(ch), SP->_ofp); /* macro's fastest... */
+ COUNT_OUTCHARS(1);
}
- SP->_curscol++;
+ SP->_curscol += chlen;
if (char_padding) {
TPUTS_TRACE("char_padding");
putp(char_padding);
@@ -256,19 +342,16 @@ check_pending(void)
have_pending = TRUE;
}
#elif HAVE_SELECT
- fd_set *fdset;
+ fd_set fdset;
struct timeval ktimeout;
ktimeout.tv_sec =
ktimeout.tv_usec = 0;
- fdset = calloc(howmany(SP->_checkfd + 1, NFDBITS), sizeof(fd_mask));
- if (fdset != NULL) {
- FD_SET(SP->_checkfd, fdset);
- if (select(SP->_checkfd + 1, fdset, NULL, NULL, &ktimeout) != 0) {
- have_pending = TRUE;
- }
- free(fdset);
+ FD_ZERO(&fdset);
+ FD_SET(SP->_checkfd, &fdset);
+ if (select(SP->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) {
+ have_pending = TRUE;
}
#endif
}
@@ -281,7 +364,7 @@ check_pending(void)
/* put char at lower right corner */
static void
-PutCharLR(chtype const ch)
+PutCharLR(const ARG_CH_T ch)
{
if (!auto_right_margin) {
/* we can put the char directly */
@@ -306,39 +389,49 @@ PutCharLR(chtype const 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
-PutChar(chtype const ch)
+static NCURSES_INLINE void
+PutChar(const ARG_CH_T ch)
/* insert character, handling automargin stuff */
{
if (SP->_cursrow == screen_lines - 1 && SP->_curscol == screen_columns - 1)
@@ -358,20 +451,30 @@ PutChar(chtype const 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
-can_clear_with(chtype ch)
+static NCURSES_INLINE bool
+can_clear_with(ARG_CH_T ch)
{
if (!back_color_erase && SP->_coloron) {
- if (ch & A_COLOR)
- return FALSE;
#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 ((pair = GetPair(CHDEREF(ch))) != 0) {
+ short fg, bg;
+ pair_content(pair, &fg, &bg);
+ if (fg != C_MASK || bg != C_MASK)
+ return FALSE;
+ }
+#else
+ if (AttrOfD(ch) & A_COLOR)
+ return FALSE;
#endif
}
- return ((ch & ~(NONBLANK_ATTR | A_COLOR)) == BLANK);
+ return (ISBLANK(CHDEREF(ch)) &&
+ (AttrOfD(ch) & ~(NONBLANK_ATTR | A_COLOR)) == BLANK_ATTR);
}
/*
@@ -387,28 +490,30 @@ can_clear_with(chtype ch)
* This code is optimized using ech and rep.
*/
static int
-EmitRange(const chtype * ntext, int num)
+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;
- chtype ntext0;
+ NCURSES_CH_T ntext0;
- while (num > 1 && ntext[0] != ntext[1]) {
- PutChar(ntext[0]);
+ while (num > 1 && !CharEq(ntext[0], ntext[1])) {
+ PutChar(CHREF(ntext[0]));
ntext++;
num--;
}
ntext0 = ntext[0];
if (num == 1) {
- PutChar(ntext0);
+ PutChar(CHREF(ntext0));
return 0;
}
runcount = 2;
- while (runcount < num && ntext[runcount] == ntext0)
+ while (runcount < num && CharEq(ntext[runcount], ntext0))
runcount++;
/*
@@ -421,9 +526,9 @@ EmitRange(const chtype * ntext, int num)
*/
if (erase_chars
&& runcount > SP->_ech_cost + SP->_cup_ch_cost
- && can_clear_with(ntext0)) {
+ && can_clear_with(CHREF(ntext0))) {
UpdateAttrs(ntext0);
- putp(tparm(erase_chars, runcount));
+ putp(TPARM_1(erase_chars, runcount));
/*
* If this is the last part of the given interval,
@@ -443,14 +548,15 @@ EmitRange(const chtype * ntext, int num)
rep_count--;
UpdateAttrs(ntext0);
- putp(tparm(repeat_char, TextOf(ntext0), rep_count));
+ tputs(TPARM_2(repeat_char, CharOf(ntext0), rep_count),
+ rep_count, _nc_outch);
SP->_curscol += rep_count;
if (wrap_possible)
- PutChar(ntext0);
+ PutChar(CHREF(ntext0));
} else {
for (i = 0; i < runcount; i++)
- PutChar(ntext[i]);
+ PutChar(CHREF(ntext[i]));
}
ntext += runcount;
num -= runcount;
@@ -459,7 +565,7 @@ EmitRange(const chtype * ntext, int num)
}
for (i = 0; i < num; i++)
- PutChar(ntext[i]);
+ PutChar(CHREF(ntext[i]));
return 0;
}
@@ -472,31 +578,37 @@ EmitRange(const chtype * ntext, int num)
* Returns: same as EmitRange
*/
static int
-PutRange(
- const chtype * otext,
- const chtype * 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 (otext[j] == ntext[j]) {
- run++;
+ for (j = first, same = 0; j <= last; j++) {
+ if (!same && isWidecExt(otext[j]))
+ continue;
+ if (CharEq(otext[j], ntext[j])) {
+ 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);
}
@@ -518,13 +630,18 @@ doupdate(void)
T((T_CALLED("doupdate()")));
+ if (curscr == 0
+ || newscr == 0)
+ returnCode(ERR);
+
#ifdef TRACE
- if (_nc_tracing & TRACE_UPDATE) {
+ if (USE_TRACEF(TRACE_UPDATE)) {
if (curscr->_clear)
_tracef("curscr is clear");
else
_tracedump("curscr", curscr);
_tracedump("newscr", newscr);
+ _nc_unlock_global(tracef);
}
#endif /* TRACE */
@@ -534,7 +651,7 @@ doupdate(void)
SP->_fifohold--;
#if USE_SIZECHANGE
- if (SP->_endwin || SP->_sig_winch) {
+ if (SP->_endwin || _nc_handle_sigwinch(SP)) {
/*
* This is a transparent extension: XSI does not address it,
* and applications need not know that ncurses can do it.
@@ -543,7 +660,7 @@ doupdate(void)
* (this can happen in an xterm, for example), and resize the
* ncurses data structures accordingly.
*/
- _nc_update_screensize();
+ _nc_update_screensize(SP);
}
#endif
@@ -560,22 +677,20 @@ doupdate(void)
}
#if USE_TRACE_TIMES
/* zero the metering machinery */
- _nc_outchars = 0;
+ RESET_OUTCHARS();
(void) times(&before);
#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) {
@@ -585,11 +700,13 @@ doupdate(void)
for (i = 0; i < screen_lines; i++) {
for (j = 0; j < screen_columns; j++) {
bool failed = FALSE;
- chtype 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;
}
@@ -597,23 +714,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) & (chtype)~NONBLANK_ATTR))
- if (TextOf(newscr->_line[i].text[j]) == ' ' && SAFE(turnon)) {
- 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
- || TextOf(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;
@@ -622,7 +749,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)",
@@ -638,25 +766,37 @@ doupdate(void)
foundit:;
if (end_onscreen) {
- chtype *lastline = newscr->_line[m].text;
+ 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
- && TextOf(lastline[n]) == ' '
- && SAFE(AttrOf(lastline[n])))
- lastline[n--] &= ~turnon;
+ && ISBLANK(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
- || TextOf(lastline[n + k]) != ' '
- || !SAFE(AttrOf(lastline[n + k])))
+ || !ISBLANK(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;
+ }
+ }
}
}
@@ -670,9 +810,10 @@ 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;
- newscr->_line[p].text[q] &= ~turnon;
+ RemAttr(newscr->_line[p].text[q], turnon);
}
q = 0;
}
@@ -683,22 +824,23 @@ 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++)
- newscr->_line[i].text[j - k] |= turnon;
+ AddAttr(thisline[j - k], turnon);
}
- rattr = AttrOf(newscr->_line[i].text[j]);
+ rattr = thisattr;
}
}
#ifdef TRACE
/* show altered highlights after magic-cookie check */
- if (_nc_tracing & TRACE_UPDATE) {
+ if (USE_TRACEF(TRACE_UPDATE)) {
_tracef("After magic-cookie check...");
_tracedump("newscr", newscr);
+ _nc_unlock_global(tracef);
}
#endif /* TRACE */
}
@@ -706,7 +848,6 @@ doupdate(void)
nonempty = 0;
if (curscr->_clear || newscr->_clear) { /* force refresh ? */
- TR(TRACE_UPDATE, ("clearing and updating from scratch"));
ClrUpdate();
curscr->_clear = FALSE; /* reset flag */
newscr->_clear = FALSE; /* reset flag */
@@ -774,21 +915,26 @@ 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);
TR(TRACE_TIMES,
("Update cost: %ld chars, %ld clocks system time, %ld clocks user time",
_nc_outchars,
- after.tms_stime - before.tms_stime,
- after.tms_utime - before.tms_utime));
+ (long) (after.tms_stime - before.tms_stime),
+ (long) (after.tms_utime - before.tms_utime)));
#endif /* USE_TRACE_TIMES */
_nc_signal_handler(TRUE);
@@ -807,14 +953,14 @@ doupdate(void)
* in the wbkgd() call. Assume 'stdscr' for this case.
*/
#define BCE_ATTRS (A_NORMAL|A_COLOR)
-#define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_bkgd)
+#define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_nc_bkgd)
-static inline chtype
+static NCURSES_INLINE NCURSES_CH_T
ClrBlank(WINDOW *win)
{
- chtype blank = BLANK;
+ NCURSES_CH_T blank = blankchar;
if (back_color_erase)
- blank |= (BCE_BKGD(win) & BCE_ATTRS);
+ AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS));
return blank;
}
@@ -829,10 +975,10 @@ static void
ClrUpdate(void)
{
int i;
- chtype blank = ClrBlank(stdscr);
+ NCURSES_CH_T blank = ClrBlank(stdscr);
int nonempty = min(screen_lines, newscr->_maxy + 1);
- TR(TRACE_UPDATE, ("ClrUpdate() called"));
+ TR(TRACE_UPDATE, (T_CALLED("ClrUpdate")));
ClearScreen(blank);
@@ -842,6 +988,8 @@ ClrUpdate(void)
for (i = 0; i < nonempty; i++)
TransformLine(i);
+
+ TR(TRACE_UPDATE, (T_RETURN("")));
}
/*
@@ -851,7 +999,7 @@ ClrUpdate(void)
*/
static void
-ClrToEOL(chtype blank, bool needclear)
+ClrToEOL(NCURSES_CH_T blank, bool needclear)
{
int j;
@@ -859,9 +1007,9 @@ ClrToEOL(chtype blank, bool needclear)
&& SP->_cursrow >= 0) {
for (j = SP->_curscol; j < screen_columns; j++) {
if (j >= 0) {
- chtype *cp = &(curscr->_line[SP->_cursrow].text[j]);
+ NCURSES_CH_T *cp = &(curscr->_line[SP->_cursrow].text[j]);
- if (*cp != blank) {
+ if (!CharEq(*cp, blank)) {
*cp = blank;
needclear = TRUE;
}
@@ -874,12 +1022,12 @@ ClrToEOL(chtype blank, bool needclear)
if (needclear) {
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(blank);
- } else {
- putp(clr_eol);
+ PutChar(CHREF(blank));
}
}
}
@@ -891,7 +1039,7 @@ ClrToEOL(chtype blank, bool needclear)
*/
static void
-ClrToEOS(chtype blank)
+ClrToEOS(NCURSES_CH_T blank)
{
int row, col;
@@ -925,39 +1073,51 @@ ClrBottom(int total)
int col;
int top = total;
int last = min(screen_columns, newscr->_maxx + 1);
- chtype blank = ClrBlank(stdscr);
+ NCURSES_CH_T blank = newscr->_line[total - 1].text[last - 1];
bool ok;
- if (clr_eos && can_clear_with(blank)) {
+ if (clr_eos && can_clear_with(CHREF(blank))) {
for (row = total - 1; row >= 0; row--) {
for (col = 0, ok = TRUE; ok && col < last; col++) {
- ok = (newscr->_line[row].text[col] == blank);
+ ok = (CharEq(newscr->_line[row].text[col], blank));
}
if (!ok)
break;
for (col = 0; ok && col < last; col++) {
- ok = (curscr->_line[row].text[col] == blank);
+ ok = (CharEq(curscr->_line[row].text[col], blank));
}
if (!ok)
top = row;
}
/* 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
+#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)
+#endif
+
+#define xmc_new(r,c) newscr->_line[r].text[c]
+#define xmc_turn_off(a,b) xmc_turn_on(b,a)
+#endif /* USE_XMC_SUPPORT */
+
/*
** TransformLine(lineno)
**
@@ -980,19 +1140,17 @@ static void
TransformLine(int const lineno)
{
int firstChar, oLastChar, nLastChar;
- chtype *newLine = newscr->_line[lineno].text;
- chtype *oldLine = curscr->_line[lineno].text;
+ NCURSES_CH_T *newLine = newscr->_line[lineno].text;
+ NCURSES_CH_T *oldLine = curscr->_line[lineno].text;
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) ((n) & A_COLOR)
-#define unColor(n) ((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
@@ -1000,24 +1158,19 @@ TransformLine(int const lineno)
* they are equivalent.
*/
if (SP->_coloron) {
- chtype oldColor;
- chtype newColor;
int oldPair;
int newPair;
for (n = 0; n < screen_columns; n++) {
- if (newLine[n] != oldLine[n]) {
- oldColor = ColorOf(oldLine[n]);
- newColor = ColorOf(newLine[n]);
- if (oldColor != newColor
+ if (!CharEq(newLine[n], oldLine[n])) {
+ 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]) {
- oldLine[n] &= ~A_COLOR;
- oldLine[n] |= ColorOf(newLine[n]);
+ SetPair(oldLine[n], GetPair(newLine[n]));
}
}
}
@@ -1027,8 +1180,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++;
}
}
@@ -1041,10 +1196,6 @@ TransformLine(int const lineno)
PutRange(oldLine, newLine, lineno, 0, (screen_columns - 1));
#if USE_XMC_SUPPORT
-#define NEW(r,c) newscr->_line[r].text[c]
-#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0)
-#define xmc_turn_off(a,b) xmc_turn_on(b,a)
-
/*
* This is a very simple loop to paint characters which may have the
* magic cookie glitch embedded. It doesn't know much about video
@@ -1065,86 +1216,96 @@ TransformLine(int const lineno)
* If we are writing an attributed blank, where the
* previous cell is not attributed.
*/
- if (TextOf(newLine[n]) == ' '
+ if (ISBLANK(newLine[n])
&& ((n > 0
&& xmc_turn_on(newLine[n - 1], newLine[n]))
|| (n == 0
&& lineno > 0
- && xmc_turn_on(NEW(lineno - 1, screen_columns - 1),
+ && xmc_turn_on(xmc_new(lineno - 1, screen_columns - 1),
newLine[n])))) {
n = m;
}
- PutChar(newLine[n]);
+ PutChar(CHREF(newLine[n]));
/* check for turn-off:
* If we are writing an attributed non-blank, where the
* next cell is blank, and not attributed.
*/
- if (TextOf(newLine[n]) != ' '
+ if (!ISBLANK(newLine[n])
&& ((n + 1 < screen_columns
&& xmc_turn_off(newLine[n], newLine[n + 1]))
|| (n + 1 >= screen_columns
&& lineno + 1 < screen_lines
- && xmc_turn_off(newLine[n], NEW(lineno + 1, 0))))) {
+ && xmc_turn_off(newLine[n], xmc_new(lineno + 1, 0))))) {
n = m;
}
}
-#undef NEW
#endif
} else {
- chtype blank;
-
- /* find the first differing character */
- while (firstChar < screen_columns &&
- newLine[firstChar] == oldLine[firstChar])
- firstChar++;
-
- /* if there wasn't one, we're done */
- if (firstChar >= screen_columns)
- return;
+ NCURSES_CH_T blank;
/* it may be cheap to clear leading whitespace with clr_bol */
- if (clr_bol && can_clear_with(blank = newLine[0])) {
+ blank = newLine[0];
+ if (clr_bol && can_clear_with(CHREF(blank))) {
int oFirstChar, nFirstChar;
for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++)
- if (oldLine[oFirstChar] != blank)
+ if (!CharEq(oldLine[oFirstChar], blank))
break;
for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++)
- if (newLine[nFirstChar] != blank)
+ 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(blank);
- TPUTS_TRACE("clr_eol");
- putp(clr_eol);
- } else {
- GoTo(lineno, nFirstChar - 1);
- UpdateAttrs(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];
- if (!can_clear_with(blank)) {
+ if (!can_clear_with(CHREF(blank))) {
/* find the last differing character */
nLastChar = screen_columns - 1;
while (nLastChar > firstChar
- && newLine[nLastChar] == oldLine[nLastChar])
+ && CharEq(newLine[nLastChar], oldLine[nLastChar]))
nLastChar--;
if (nLastChar >= firstChar) {
@@ -1152,29 +1313,30 @@ TransformLine(int const lineno)
PutRange(oldLine, newLine, lineno, firstChar, nLastChar);
memcpy(oldLine + firstChar,
newLine + firstChar,
- (nLastChar - firstChar + 1) * sizeof(chtype));
+ (nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T));
}
+ TR(TRACE_UPDATE, (T_RETURN("")));
return;
}
/* find last non-blank character on old line */
oLastChar = screen_columns - 1;
- while (oLastChar > firstChar && oldLine[oLastChar] == blank)
+ while (oLastChar > firstChar && CharEq(oldLine[oLastChar], blank))
oLastChar--;
/* find last non-blank character on new line */
nLastChar = screen_columns - 1;
- while (nLastChar > firstChar && newLine[nLastChar] == blank)
+ while (nLastChar > firstChar && CharEq(newLine[nLastChar], blank))
nLastChar--;
if ((nLastChar == firstChar)
&& (SP->_el_cost < (oLastChar - nLastChar))) {
GoTo(lineno, firstChar);
- if (newLine[firstChar] != blank)
- PutChar(newLine[firstChar]);
+ if (!CharEq(newLine[firstChar], blank))
+ PutChar(CHREF(newLine[firstChar]));
ClrToEOL(blank, FALSE);
} else if ((nLastChar != oLastChar)
- && (newLine[nLastChar] != oldLine[oLastChar]
+ && (!CharEq(newLine[nLastChar], oldLine[oLastChar])
|| !(_nc_idcok && has_ic()))) {
GoTo(lineno, firstChar);
if ((oLastChar - nLastChar) > SP->_el_cost) {
@@ -1190,14 +1352,16 @@ TransformLine(int const lineno)
int oLastNonblank = oLastChar;
/* find the last characters that really differ */
- while (newLine[nLastChar] == oldLine[oLastChar]) {
- if (nLastChar != 0
- && oLastChar != 0) {
- nLastChar--;
- oLastChar--;
- } else {
+ /* can be -1 if no characters differ */
+ while (CharEq(newLine[nLastChar], oldLine[oLastChar])) {
+ /* don't split a wide char */
+ if (isWidecExt(newLine[nLastChar]) &&
+ !CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1]))
+ break;
+ nLastChar--;
+ oLastChar--;
+ if (nLastChar == -1 || oLastChar == -1)
break;
- }
}
n = min(oLastChar, nLastChar);
@@ -1208,9 +1372,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);
@@ -1243,7 +1413,9 @@ TransformLine(int const lineno)
if (screen_columns > firstChar)
memcpy(oldLine + firstChar,
newLine + firstChar,
- (screen_columns - firstChar) * sizeof(chtype));
+ (screen_columns - firstChar) * sizeof(NCURSES_CH_T));
+ TR(TRACE_UPDATE, (T_RETURN("")));
+ return;
}
/*
@@ -1254,7 +1426,7 @@ TransformLine(int const lineno)
*/
static void
-ClearScreen(chtype blank)
+ClearScreen(NCURSES_CH_T blank)
{
int i, j;
bool fast_clear = (clear_screen || clr_eos || clr_eol);
@@ -1264,7 +1436,7 @@ ClearScreen(chtype 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;
}
@@ -1284,7 +1456,7 @@ ClearScreen(chtype 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;
@@ -1301,7 +1473,7 @@ ClearScreen(chtype blank)
for (i = 0; i < screen_lines; i++) {
GoTo(i, 0);
for (j = 0; j < screen_columns; j++)
- PutChar(blank);
+ PutChar(CHREF(blank));
}
GoTo(0, 0);
}
@@ -1322,7 +1494,7 @@ ClearScreen(chtype blank)
*/
static void
-InsStr(chtype * line, int count)
+InsStr(NCURSES_CH_T * line, int count)
{
TR(TRACE_UPDATE, ("InsStr(%p,%d) called", line, count));
@@ -1331,9 +1503,9 @@ InsStr(chtype * 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(*line);
+ PutAttrChar(CHREF(*line));
line++;
count--;
}
@@ -1341,7 +1513,7 @@ InsStr(chtype * line, int count)
TPUTS_TRACE("enter_insert_mode");
putp(enter_insert_mode);
while (count) {
- PutAttrChar(*line);
+ PutAttrChar(CHREF(*line));
if (insert_padding) {
TPUTS_TRACE("insert_padding");
putp(insert_padding);
@@ -1355,7 +1527,7 @@ InsStr(chtype * line, int count)
while (count) {
TPUTS_TRACE("insert_character");
putp(insert_character);
- PutAttrChar(*line);
+ PutAttrChar(CHREF(*line));
if (insert_padding) {
TPUTS_TRACE("insert_padding");
putp(insert_padding);
@@ -1379,12 +1551,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");
@@ -1394,19 +1568,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
@@ -1440,53 +1601,54 @@ _nc_outstr(const char *str)
/* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */
static int
-scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank)
+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(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(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(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(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(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(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++)
- PutChar(blank);
+ PutChar(CHREF(blank));
}
}
#endif
@@ -1496,53 +1658,55 @@ scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank)
/* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */
/* n > 0 */
static int
-scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank)
+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(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(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(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(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(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(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++)
- PutChar(blank);
+ PutChar(CHREF(blank));
}
}
#endif
@@ -1552,7 +1716,7 @@ scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank)
/* scroll by using delete_line at del and insert_line at ins */
/* n > 0 */
static int
-scroll_idl(int n, int del, int ins, chtype blank)
+scroll_idl(int n, int del, int ins, NCURSES_CH_T blank)
{
int i;
@@ -1563,14 +1727,14 @@ scroll_idl(int n, int del, int ins, chtype 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);
}
}
@@ -1578,26 +1742,33 @@ scroll_idl(int n, int del, int ins, chtype 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 */
{
- chtype blank = ClrBlank(stdscr);
+ NCURSES_CH_T blank = ClrBlank(stdscr);
int i;
bool cursor_saved = FALSE;
int res;
@@ -1626,13 +1797,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;
}
@@ -1640,7 +1811,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;
}
@@ -1652,13 +1823,14 @@ _nc_scrolln
*/
if (res != ERR
&& (non_dest_scroll_region || (memory_below && bot == maxy))) {
+ static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
if (bot == maxy && clr_eos) {
- GoTo(bot - n, 0);
- ClrToEOS(BLANK);
+ GoTo(bot - n + 1, 0);
+ ClrToEOS(blank2);
} else {
for (i = 0; i < n; i++) {
GoTo(bot - i, 0);
- ClrToEOL(BLANK, FALSE);
+ ClrToEOL(blank2, FALSE);
}
}
}
@@ -1671,13 +1843,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;
}
@@ -1685,7 +1857,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;
}
@@ -1697,9 +1869,10 @@ _nc_scrolln
*/
if (res != ERR
&& (non_dest_scroll_region || (memory_above && top == 0))) {
+ static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
for (i = 0; i < -n; i++) {
GoTo(i + top, 0);
- ClrToEOL(BLANK, FALSE);
+ ClrToEOL(blank2, FALSE);
}
}
}
@@ -1719,11 +1892,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 {
@@ -1751,28 +1940,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) {
+ 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);
+ 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) {