aboutsummaryrefslogtreecommitdiff
path: root/ncurses/base
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2024-06-20 08:11:38 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2024-06-20 08:11:38 +0000
commit24fa7a5107c5b75d1c197accf0305be64bc72882 (patch)
tree183f09c93417ac0e5f7f49760329a3d2cfaacda9 /ncurses/base
parentbf0ab54638a5ef969749f6ceae30e864f9556ea8 (diff)
Diffstat (limited to 'ncurses/base')
-rwxr-xr-xncurses/base/MKlib_gen.sh23
-rw-r--r--ncurses/base/MKunctrl.awk7
-rw-r--r--ncurses/base/key_defined.c7
-rw-r--r--ncurses/base/keyok.c6
-rw-r--r--ncurses/base/lib_addch.c35
-rw-r--r--ncurses/base/lib_addstr.c32
-rw-r--r--ncurses/base/lib_bkgd.c4
-rw-r--r--ncurses/base/lib_clreol.c8
-rw-r--r--ncurses/base/lib_color.c82
-rw-r--r--ncurses/base/lib_delwin.c38
-rw-r--r--ncurses/base/lib_dft_fgbg.c8
-rw-r--r--ncurses/base/lib_echo.c8
-rw-r--r--ncurses/base/lib_endwin.c28
-rw-r--r--ncurses/base/lib_erase.c6
-rw-r--r--ncurses/base/lib_freeall.c11
-rw-r--r--ncurses/base/lib_getch.c63
-rw-r--r--ncurses/base/lib_getstr.c35
-rw-r--r--ncurses/base/lib_insnstr.c9
-rw-r--r--ncurses/base/lib_instr.c8
-rw-r--r--ncurses/base/lib_mouse.c153
-rw-r--r--ncurses/base/lib_mvwin.c8
-rw-r--r--ncurses/base/lib_newterm.c7
-rw-r--r--ncurses/base/lib_newwin.c8
-rw-r--r--ncurses/base/lib_nl.c8
-rw-r--r--ncurses/base/lib_overlay.c16
-rw-r--r--ncurses/base/lib_pad.c12
-rw-r--r--ncurses/base/lib_refresh.c24
-rw-r--r--ncurses/base/lib_restart.c17
-rw-r--r--ncurses/base/lib_screen.c61
-rw-r--r--ncurses/base/lib_set_term.c51
-rw-r--r--ncurses/base/lib_slk.c8
-rw-r--r--ncurses/base/lib_slkinit.c7
-rw-r--r--ncurses/base/lib_slkrefr.c6
-rw-r--r--ncurses/base/lib_wattron.c8
-rw-r--r--ncurses/base/lib_window.c10
-rw-r--r--ncurses/base/new_pair.c6
-rw-r--r--ncurses/base/resizeterm.c14
-rw-r--r--ncurses/base/safe_sprintf.c36
-rw-r--r--ncurses/base/tries.c7
-rw-r--r--ncurses/base/vsscanf.c11
-rw-r--r--ncurses/base/wresize.c10
41 files changed, 532 insertions, 374 deletions
diff --git a/ncurses/base/MKlib_gen.sh b/ncurses/base/MKlib_gen.sh
index 3829eff8eecb..f0ac0452e8ef 100755
--- a/ncurses/base/MKlib_gen.sh
+++ b/ncurses/base/MKlib_gen.sh
@@ -2,10 +2,10 @@
#
# MKlib_gen.sh -- generate sources from curses.h macro definitions
#
-# ($Id: MKlib_gen.sh,v 1.68 2020/08/23 00:02:29 tom Exp $)
+# ($Id: MKlib_gen.sh,v 1.73 2022/10/01 13:14:20 tom Exp $)
#
##############################################################################
-# Copyright 2018,2020 Thomas E. Dickey #
+# Copyright 2018-2021,2022 Thomas E. Dickey #
# Copyright 1998-2016,2017 Free Software Foundation, Inc. #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
@@ -69,12 +69,21 @@ USE="$3"
# A patch discussed here:
# https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
+#
# introduces spurious #line markers into the preprocessor output. The result
# appears in gcc 5.0 and (with modification) in 5.1, making it necessary to
# determine if we are using gcc, and if so, what version because the proposed
# solution uses a nonstandard option.
+#
+# As illustrated in
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60723
+#
+# gcc developers chose to ignore the problems with this, and summarized those
+# as "intriguing problems" in
+# https://gcc.gnu.org/gcc-5/porting_to.html
+
PRG=`echo "$1" | "$AWK" '{ sub(/^[ ]*/,""); sub(/[ ].*$/, ""); print; }' || exit 0`
-FSF=`("$PRG" --version 2>/dev/null || exit 0) | fgrep "Free Software Foundation" | head -n 1`
+FSF=`("$PRG" --version 2>/dev/null || exit 0) | ${FGREP-grep -F} "Free Software Foundation" | head -n 1`
ALL=`"$PRG" -dumpversion 2>/dev/null || exit 0`
ONE=`echo "$ALL" | sed -e 's/[^0-9].*$//'`
if test -n "$FSF" && test -n "$ALL" && test -n "$ONE" ; then
@@ -92,7 +101,8 @@ ED4=sed4_${PID}.sed
AW1=awk1_${PID}.awk
AW2=awk2_${PID}.awk
TMP=gen__${PID}.c
-trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0 1 2 3 15
+trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP; exit 1" 1 2 3 15
+trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0
ALL=$USE
if test "$USE" = implemented ; then
@@ -461,8 +471,9 @@ END {
if ( value !~ /P_POUNDC/ ) {
gsub(/[ \t]+/," ",value);
sub(/^[0-9a-zA-Z_]+ /,"",value);
- sub(/^\* /,"",value);
- gsub(/[0-9a-zA-Z_]+ \* /,"",value);
+ sub(/^[*][ \t]*/,"",value);
+ gsub("struct[ \t]*[0-9a-zA-Z_]+[ \t]*[*]","",value);
+ gsub(/[0-9a-zA-Z_]+[ \t]*[*][ \t]*/,"",value);
gsub(/ (const) /," ",value);
gsub(/ (int|short|attr_t|chtype|wchar_t|NCURSES_BOOL|NCURSES_OUTC|NCURSES_OUTC_sp|va_list) /," ",value);
gsub(/ void /,"",value);
diff --git a/ncurses/base/MKunctrl.awk b/ncurses/base/MKunctrl.awk
index 9a2a6db63876..e5362bd60d15 100644
--- a/ncurses/base/MKunctrl.awk
+++ b/ncurses/base/MKunctrl.awk
@@ -1,6 +1,6 @@
-# $Id: MKunctrl.awk,v 1.29 2020/02/02 23:34:34 tom Exp $
+# $Id: MKunctrl.awk,v 1.30 2024/02/03 21:09:14 tom Exp $
##############################################################################
-# Copyright 2020 Thomas E. Dickey #
+# Copyright 2020,2024 Thomas E. Dickey #
# Copyright 1998-2012,2017 Free Software Foundation, Inc. #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
@@ -144,7 +144,7 @@ END {
print "\tint check = (int) ChCharOf(ch);"
print "\tconst char *result;"
print ""
- print "(void) sp;"
+ print "\t(void) sp;"
print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
print "#if NCURSES_EXT_FUNCS"
print "\t\tif ((sp != 0)"
@@ -155,6 +155,7 @@ END {
print "\t\telse"
print "\t\tif ((check >= 160)"
print "\t\t && (check < 256)"
+ print "\t\t && !_nc_unicode_locale()"
print "\t\t && ((sp != 0)"
print "\t\t && ((sp->_legacy_coding > 0)"
print "\t\t || (sp->_legacy_coding == 0"
diff --git a/ncurses/base/key_defined.c b/ncurses/base/key_defined.c
index 25d5a674e1b8..147e5fe2db93 100644
--- a/ncurses/base/key_defined.c
+++ b/ncurses/base/key_defined.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 2003-2006,2009 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -32,8 +32,9 @@
****************************************************************************/
#include <curses.priv.h>
+#include <tic.h>
-MODULE_ID("$Id: key_defined.c,v 1.10 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: key_defined.c,v 1.11 2023/06/24 15:36:32 tom Exp $")
static int
find_definition(TRIES * tree, const char *str)
@@ -41,7 +42,7 @@ find_definition(TRIES * tree, const char *str)
TRIES *ptr;
int result = OK;
- if (str != 0 && *str != '\0') {
+ if (VALID_STRING(str) && *str != '\0') {
for (ptr = tree; ptr != 0; ptr = ptr->sibling) {
if (UChar(*str) == UChar(ptr->ch)) {
if (str[1] == '\0' && ptr->child != 0) {
diff --git a/ncurses/base/keyok.c b/ncurses/base/keyok.c
index 8e0b9629db20..945228aa8035 100644
--- a/ncurses/base/keyok.c
+++ b/ncurses/base/keyok.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019,2020 Thomas E. Dickey *
+ * Copyright 2019-2020,2021 Thomas E. Dickey *
* Copyright 1998-2012,2014 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -34,13 +34,13 @@
#include <curses.priv.h>
-MODULE_ID("$Id: keyok.c,v 1.16 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: keyok.c,v 1.17 2021/06/17 21:26:02 tom Exp $")
/*
* Enable (or disable) ncurses' interpretation of a keycode by adding (or
* removing) the corresponding 'tries' entry.
*
- * Do this by storing a second tree of tries, which records the disabled keys.
+ * Do this by storing a second tree of tries, which records the disabled keys.
* The simplest way to copy is to make a function that returns the string (with
* nulls set to 0200), then use that to reinsert the string into the
* corresponding tree.
diff --git a/ncurses/base/lib_addch.c b/ncurses/base/lib_addch.c
index 378c2881faac..a14bfd3b0e05 100644
--- a/ncurses/base/lib_addch.c
+++ b/ncurses/base/lib_addch.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019-2020,2021 Thomas E. Dickey *
+ * Copyright 2019-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -37,7 +37,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_addch.c,v 1.137 2021/02/20 22:24:34 tom Exp $")
+MODULE_ID("$Id: lib_addch.c,v 1.141 2022/06/12 15:16:41 tom Exp $")
static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
@@ -140,7 +140,7 @@ newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T *ypos)
* wrapped the cursor. We don't do anything with this flag except set it when
* wrapping, and clear it whenever we move the cursor. If we try to wrap at
* the lower-right corner of a window, we cannot move the cursor (since that
- * wouldn't be legal). So we return an error (which is what SVr4 does).
+ * wouldn't be legal). So we return an error (which is what SVr4 does).
* Unlike SVr4, we can successfully add a character to the lower-right corner
* (Solaris 2.6 does this also, however).
*/
@@ -321,20 +321,29 @@ waddch_literal(WINDOW *win, NCURSES_CH_T ch)
int len = _nc_wacs_width(CharOf(ch));
int i;
int j;
- wchar_t *chars;
if (len == 0) { /* non-spacing */
if ((x > 0 && y >= 0)
|| (win->_maxx >= 0 && win->_cury >= 1)) {
- if (x > 0 && y >= 0)
- chars = (win->_line[y].text[x - 1].chars);
- else
- chars = (win->_line[y - 1].text[win->_maxx].chars);
+ NCURSES_CH_T *dst;
+ wchar_t *chars;
+ if (x > 0 && y >= 0) {
+ for (j = x - 1; j >= 0; --j) {
+ if (!isWidecExt(win->_line[y].text[j])) {
+ win->_curx = (NCURSES_SIZE_T) j;
+ break;
+ }
+ }
+ dst = &(win->_line[y].text[j]);
+ } else {
+ dst = &(win->_line[y - 1].text[win->_maxx]);
+ }
+ chars = dst->chars;
for (i = 0; i < CCHARW_MAX; ++i) {
if (chars[i] == 0) {
TR(TRACE_VIRTPUT,
- ("added non-spacing %d: %x",
- x, (int) CharOf(ch)));
+ ("adding non-spacing %s (level %d)",
+ _tracech_t(CHREF(ch)), i));
chars[i] = CharOf(ch);
break;
}
@@ -410,9 +419,9 @@ waddch_literal(WINDOW *win, NCURSES_CH_T ch)
testwrapping:
);
- TR(TRACE_VIRTPUT, ("cell (%ld, %ld..%d) = %s",
- (long) win->_cury, (long) win->_curx, x - 1,
- _tracech_t(CHREF(ch))));
+ TR(TRACE_VIRTPUT, ("cell (%d, %d..%d) = %s",
+ win->_cury, win->_curx, x - 1,
+ _tracech_t(CHREF(line->text[win->_curx]))));
if (x > win->_maxx) {
return wrap_to_next_line(win);
diff --git a/ncurses/base/lib_addstr.c b/ncurses/base/lib_addstr.c
index a1e8829dd7f5..a3753af0d53e 100644
--- a/ncurses/base/lib_addstr.c
+++ b/ncurses/base/lib_addstr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019,2020 Thomas E. Dickey *
+ * Copyright 2019-2022,2023 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -45,7 +45,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_addstr.c,v 1.57 2020/12/05 20:06:19 tom Exp $")
+MODULE_ID("$Id: lib_addstr.c,v 1.62 2023/11/21 21:47:23 tom Exp $")
NCURSES_EXPORT(int)
waddnstr(WINDOW *win, const char *astr, int n)
@@ -55,15 +55,18 @@ waddnstr(WINDOW *win, const char *astr, int n)
T((T_CALLED("waddnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(astr, n), n));
- if (win && (str != 0)) {
+ if (win && (str != 0) && (n != 0)) {
+ bool explicit = (n > 0);
+
TR(TRACE_VIRTPUT | TRACE_ATTRS,
("... current %s", _traceattr(WINDOW_ATTRS(win))));
code = OK;
- if (n < 0)
- n = INT_MAX;
- TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
- while ((*str != '\0') && (n-- > 0)) {
+ TR(TRACE_VIRTPUT, ("str is not null, length = %d",
+ (explicit ? n : (int) strlen(str))));
+ if (!explicit)
+ n = INT_MAX;
+ while ((n-- > 0) && (*str != '\0')) {
NCURSES_CH_T ch;
TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str)));
SetChar(ch, UChar(*str++), A_NORMAL);
@@ -143,7 +146,7 @@ wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
_nc_viscbuf(astr, n),
n));
- if (!win)
+ if (!win || !astr)
returnCode(ERR);
y = win->_cury;
@@ -227,15 +230,18 @@ waddnwstr(WINDOW *win, const wchar_t *str, int n)
T((T_CALLED("waddnwstr(%p,%s,%d)"), (void *) win, _nc_viswbufn(str, n), n));
- if (win && (str != 0)) {
+ if (win && (str != 0) && (n != 0)) {
+ bool explicit = (n > 0);
+
TR(TRACE_VIRTPUT | TRACE_ATTRS,
("... current %s", _traceattr(WINDOW_ATTRS(win))));
code = OK;
- if (n < 0)
- n = INT_MAX;
- TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
- while ((*str != L('\0')) && (n-- > 0)) {
+ TR(TRACE_VIRTPUT, ("str is not null, length = %d",
+ (explicit ? n : (int) wcslen(str))));
+ if (!explicit)
+ n = INT_MAX;
+ while ((n-- > 0) && (*str != L('\0'))) {
NCURSES_CH_T ch;
TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str));
SetChar(ch, *str++, A_NORMAL);
diff --git a/ncurses/base/lib_bkgd.c b/ncurses/base/lib_bkgd.c
index 23effc7cd141..4f99080835e8 100644
--- a/ncurses/base/lib_bkgd.c
+++ b/ncurses/base/lib_bkgd.c
@@ -37,7 +37,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_bkgd.c,v 1.62 2021/02/13 20:06:54 tom Exp $")
+MODULE_ID("$Id: lib_bkgd.c,v 1.63 2021/05/08 14:58:12 tom Exp $")
static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
@@ -64,7 +64,7 @@ wbkgrndset(WINDOW *win, const ARG_CH_T ch)
{
int pair;
- if ((pair = GetPair(win->_nc_bkgd)) != 0)
+ if (GetPair(win->_nc_bkgd) != 0)
SET_WINDOW_PAIR(win, 0);
if ((pair = GetPair(CHDEREF(ch))) != 0)
SET_WINDOW_PAIR(win, pair);
diff --git a/ncurses/base/lib_clreol.c b/ncurses/base/lib_clreol.c
index d6cb9b261283..0b6b0ff8f7de 100644
--- a/ncurses/base/lib_clreol.c
+++ b/ncurses/base/lib_clreol.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2001,2009 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -41,7 +41,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_clreol.c,v 1.23 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_clreol.c,v 1.24 2021/10/23 19:06:01 tom Exp $")
NCURSES_EXPORT(int)
wclrtoeol(WINDOW *win)
@@ -61,7 +61,7 @@ wclrtoeol(WINDOW *win)
* If we have just wrapped the cursor, the clear applies to the
* new line, unless we are at the lower right corner.
*/
- if ((win->_flags & _WRAPPED) != 0
+ if (IS_WRAPPED(win) != 0
&& y < win->_maxy) {
win->_flags &= ~_WRAPPED;
}
@@ -70,7 +70,7 @@ wclrtoeol(WINDOW *win)
* There's no point in clearing if we're not on a legal
* position, either.
*/
- if ((win->_flags & _WRAPPED) != 0
+ if (IS_WRAPPED(win)
|| y > win->_maxy
|| x > win->_maxx)
returnCode(ERR);
diff --git a/ncurses/base/lib_color.c b/ncurses/base/lib_color.c
index 907e9743fcda..f001b22413fe 100644
--- a/ncurses/base/lib_color.c
+++ b/ncurses/base/lib_color.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -49,7 +49,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_color.c,v 1.146 2021/02/14 00:17:09 tom Exp $")
+MODULE_ID("$Id: lib_color.c,v 1.150 2023/09/16 16:39:15 tom Exp $")
#ifdef USE_TERM_DRIVER
#define CanChange InfoOf(SP_PARM).canchange
@@ -94,8 +94,6 @@ NCURSES_EXPORT_VAR(int) COLORS = 0;
#define DATA(r,g,b) {r,g,b, 0,0,0, 0}
-#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
-
#define MAX_PALETTE 8
#define OkColorHi(n) (((n) < COLORS) && ((n) < maxcolors))
@@ -266,7 +264,7 @@ init_direct_colors(NCURSES_SP_DCL0)
;
}
- if ((n = tigetflag(name)) > 0) {
+ if (tigetflag(name) > 0) {
n = (width + 2) / 3;
result->bits.red = UChar(n);
result->bits.green = UChar(n);
@@ -412,7 +410,7 @@ NCURSES_SP_NAME(start_color) (NCURSES_SP_DCL0)
if (init_direct_colors(NCURSES_SP_ARG)) {
result = OK;
} else {
- SP_PARM->_color_table = TYPE_CALLOC(color_t, maxcolors);
+ TYPE_CALLOC(color_t, maxcolors, SP_PARM->_color_table);
if (SP_PARM->_color_table != 0) {
MakeColorPair(SP_PARM->_color_pairs[0],
default_fg(NCURSES_SP_ARG),
@@ -529,7 +527,7 @@ _nc_reserve_pairs(SCREEN *sp, int want)
have = sp->_pair_limit;
if (sp->_color_pairs == 0) {
- sp->_color_pairs = TYPE_CALLOC(colorpair_t, have);
+ TYPE_CALLOC(colorpair_t, have, sp->_color_pairs);
} else if (have > sp->_pair_alloc) {
#if NCURSES_EXT_COLORS
colorpair_t *next;
@@ -747,7 +745,7 @@ _nc_init_color(SCREEN *sp, int color, int r, int g, int b)
NCURSES_PUTP2("initialize_color",
TIPARM_4(initialize_color, color, r, g, b));
#endif
- sp->_color_defs = max(color + 1, sp->_color_defs);
+ sp->_color_defs = Max(color + 1, sp->_color_defs);
result = OK;
}
@@ -831,7 +829,6 @@ static int
_nc_color_content(SCREEN *sp, int color, int *r, int *g, int *b)
{
int result = ERR;
- int maxcolors;
T((T_CALLED("color_content(%p,%d,%p,%p,%p)"),
(void *) sp,
@@ -840,52 +837,57 @@ _nc_color_content(SCREEN *sp, int color, int *r, int *g, int *b)
(void *) g,
(void *) b));
- if (sp == 0)
- returnCode(result);
-
- maxcolors = MaxColors;
+ if (sp != 0) {
+ int maxcolors = MaxColors;
- if (color < 0 || !OkColorHi(color) || !sp->_coloron) {
- result = ERR;
- } else {
- int c_r, c_g, c_b;
+ if (color >= 0 && OkColorHi(color) && sp->_coloron) {
+ int c_r, c_g, c_b;
- if (sp->_direct_color.value) {
- rgb_bits_t *work = &(sp->_direct_color);
+ if (sp->_direct_color.value) {
+ rgb_bits_t *work = &(sp->_direct_color);
#define max_direct_color(name) ((1 << work->bits.name) - 1)
#define value_direct_color(max) (1000 * ((color >> bitoff) & max)) / max
- int max_r = max_direct_color(red);
- int max_g = max_direct_color(green);
- int max_b = max_direct_color(blue);
+ int max_r = max_direct_color(red);
+ int max_g = max_direct_color(green);
+ int max_b = max_direct_color(blue);
- int bitoff = 0;
+ int bitoff = 0;
- c_b = value_direct_color(max_b);
- bitoff += work->bits.blue;
+ c_b = value_direct_color(max_b);
+ bitoff += work->bits.blue;
- c_g = value_direct_color(max_g);
- bitoff += work->bits.green;
+ c_g = value_direct_color(max_g);
+ bitoff += work->bits.green;
- c_r = value_direct_color(max_r);
+ c_r = value_direct_color(max_r);
- } else {
- c_r = sp->_color_table[color].red;
- c_g = sp->_color_table[color].green;
- c_b = sp->_color_table[color].blue;
- }
+ } else {
+ c_r = sp->_color_table[color].red;
+ c_g = sp->_color_table[color].green;
+ c_b = sp->_color_table[color].blue;
+ }
+ if (r)
+ *r = c_r;
+ if (g)
+ *g = c_g;
+ if (b)
+ *b = c_b;
+
+ TR(TRACE_ATTRS, ("...color_content(%d,%d,%d,%d)",
+ color, c_r, c_g, c_b));
+ result = OK;
+ }
+ }
+ if (result != OK) {
if (r)
- *r = c_r;
+ *r = 0;
if (g)
- *g = c_g;
+ *g = 0;
if (b)
- *b = c_b;
-
- TR(TRACE_ATTRS, ("...color_content(%d,%d,%d,%d)",
- color, c_r, c_g, c_b));
- result = OK;
+ *b = 0;
}
returnCode(result);
}
diff --git a/ncurses/base/lib_delwin.c b/ncurses/base/lib_delwin.c
index 2f0621cf856c..c96e417a9a48 100644
--- a/ncurses/base/lib_delwin.c
+++ b/ncurses/base/lib_delwin.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020-2021,2023 Thomas E. Dickey *
* Copyright 1998-2008,2009 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,24 +43,29 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_delwin.c,v 1.21 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_delwin.c,v 1.25 2023/10/21 11:12:44 tom Exp $")
static bool
cannot_delete(WINDOW *win)
{
- WINDOWLIST *p;
bool result = TRUE;
-#ifdef USE_SP_WINDOWLIST
- SCREEN *sp = _nc_screen_of(win);
+
+ if (IS_PAD(win)) {
+ result = FALSE;
+ } else {
+ WINDOWLIST *p;
+#if NCURSES_SP_FUNCS && defined(USE_SP_WINDOWLIST)
+ SCREEN *sp = _nc_screen_of(win);
#endif
- for (each_window(SP_PARM, p)) {
- if (&(p->win) == win) {
- result = FALSE;
- } else if ((p->win._flags & _SUBWIN) != 0
- && p->win._parent == win) {
- result = TRUE;
- break;
+ for (each_window(SP_PARM, p)) {
+ if (&(p->win) == win) {
+ result = FALSE;
+ } else if (IS_SUBWIN(&(p->win))
+ && p->win._parent == win) {
+ result = TRUE;
+ break;
+ }
}
}
return result;
@@ -77,15 +82,18 @@ delwin(WINDOW *win)
if (win == 0
|| cannot_delete(win)) {
result = ERR;
+ } else if (IS_PAD(win)) {
+ win->_parent = NULL;
+ result = _nc_freewin(win);
} else {
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
- if (win->_flags & _SUBWIN)
+ if (IS_SUBWIN(win)) {
touchwin(win->_parent);
- else if (CurScreen(SP_PARM) != 0)
+ } else if (CurScreen(SP_PARM) != 0) {
touchwin(CurScreen(SP_PARM));
-
+ }
result = _nc_freewin(win);
}
_nc_unlock_global(curses);
diff --git a/ncurses/base/lib_dft_fgbg.c b/ncurses/base/lib_dft_fgbg.c
index 95dc0c224035..4dd43bb1bbd0 100644
--- a/ncurses/base/lib_dft_fgbg.c
+++ b/ncurses/base/lib_dft_fgbg.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2014,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -38,7 +38,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_dft_fgbg.c,v 1.30 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_dft_fgbg.c,v 1.31 2021/04/03 22:27:18 tom Exp $")
/*
* Modify the behavior of color-pair 0 so that the library doesn't assume that
@@ -83,7 +83,9 @@ NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_DCLx int fg, int bg)
bool save = SP_PARM->_default_color;
SP_PARM->_assumed_color = TRUE;
SP_PARM->_default_color = TRUE;
- init_pair(0, (short) fg, (short) bg);
+ NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx 0,
+ (short)fg,
+ (short)bg);
SP_PARM->_default_color = save;
}
code = OK;
diff --git a/ncurses/base/lib_echo.c b/ncurses/base/lib_echo.c
index d8f57f292d60..de7832f4afc1 100644
--- a/ncurses/base/lib_echo.c
+++ b/ncurses/base/lib_echo.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2000,2009 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -45,7 +45,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_echo.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_echo.c,v 1.10 2023/04/29 18:57:12 tom Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(echo) (NCURSES_SP_DCL0)
@@ -53,7 +53,7 @@ NCURSES_SP_NAME(echo) (NCURSES_SP_DCL0)
T((T_CALLED("echo(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
- SP_PARM->_echo = TRUE;
+ IsEcho(SP_PARM) = TRUE;
returnCode(OK);
}
@@ -71,7 +71,7 @@ NCURSES_SP_NAME(noecho) (NCURSES_SP_DCL0)
T((T_CALLED("noecho(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
- SP_PARM->_echo = FALSE;
+ IsEcho(SP_PARM) = FALSE;
returnCode(OK);
}
diff --git a/ncurses/base/lib_endwin.c b/ncurses/base/lib_endwin.c
index b8a9e4e66a4d..85d2bdbaac05 100644
--- a/ncurses/base/lib_endwin.c
+++ b/ncurses/base/lib_endwin.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2014,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,7 +43,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_endwin.c,v 1.25 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_endwin.c,v 1.28 2023/11/11 21:27:32 tom Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(endwin) (NCURSES_SP_DCL0)
@@ -52,20 +52,24 @@ NCURSES_SP_NAME(endwin) (NCURSES_SP_DCL0)
T((T_CALLED("endwin(%p)"), (void *) SP_PARM));
- if (SP_PARM) {
+ if (SP_PARM != NULL) {
+ if (SP_PARM->_endwin != ewSuspend) {
#ifdef USE_TERM_DRIVER
- TERMINAL_CONTROL_BLOCK *TCB = TCBOf(SP_PARM);
+ TERMINAL_CONTROL_BLOCK *TCB = TCBOf(SP_PARM);
- SP_PARM->_endwin = ewSuspend;
- if (TCB && TCB->drv && TCB->drv->td_scexit)
- TCB->drv->td_scexit(SP_PARM);
+ SP_PARM->_endwin = ewSuspend;
+ if (TCB && TCB->drv && TCB->drv->td_scexit)
+ TCB->drv->td_scexit(SP_PARM);
#else
- SP_PARM->_endwin = ewSuspend;
- SP_PARM->_mouse_wrap(SP_PARM);
- _nc_screen_wrap();
- _nc_mvcur_wrap(); /* wrap up cursor addressing */
+ SP_PARM->_endwin = ewSuspend;
+ SP_PARM->_mouse_wrap(SP_PARM);
+ _nc_screen_wrap();
+ _nc_mvcur_wrap(); /* wrap up cursor addressing */
#endif
- code = NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_ARG);
+ code = OK;
+ }
+ if (NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_ARG) == ERR)
+ code = ERR;
}
returnCode(code);
diff --git a/ncurses/base/lib_erase.c b/ncurses/base/lib_erase.c
index e190ebd549ac..aa9437a19ef1 100644
--- a/ncurses/base/lib_erase.c
+++ b/ncurses/base/lib_erase.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -42,18 +42,18 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_erase.c,v 1.19 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_erase.c,v 1.20 2022/09/03 21:40:27 tom Exp $")
NCURSES_EXPORT(int)
werase(WINDOW *win)
{
int code = ERR;
- NCURSES_CH_T blank;
NCURSES_CH_T *start;
T((T_CALLED("werase(%p)"), (void *) win));
if (win) {
+ NCURSES_CH_T blank;
NCURSES_CH_T *sp;
int y;
diff --git a/ncurses/base/lib_freeall.c b/ncurses/base/lib_freeall.c
index 9133d08a7328..75bbe77e3409 100644
--- a/ncurses/base/lib_freeall.c
+++ b/ncurses/base/lib_freeall.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -40,7 +40,7 @@
extern int malloc_errfd; /* FIXME */
#endif
-MODULE_ID("$Id: lib_freeall.c,v 1.72 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_freeall.c,v 1.76 2021/11/06 21:52:49 tom Exp $")
/*
* Free all ncurses data. This is used for testing only (there's no practical
@@ -78,6 +78,9 @@ NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0)
WINDOW *p_win = &(p->win);
bool found = FALSE;
+ if (IS_PAD(p_win))
+ continue;
+
#ifndef USE_SP_WINDOWLIST
if (p->screen != SP_PARM)
continue;
@@ -92,7 +95,7 @@ NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0)
#endif
if ((p != q)
- && (q_win->_flags & _SUBWIN)
+ && IS_SUBWIN(q_win)
&& (p_win == q_win->_parent)) {
found = TRUE;
break;
@@ -171,8 +174,6 @@ NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code)
{
if (SP_PARM) {
delscreen(SP_PARM);
- if (SP_PARM->_term)
- NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx SP_PARM->_term);
}
exit(code);
}
diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c
index 38537591afc0..8e4767918bdd 100644
--- a/ncurses/base/lib_getch.c
+++ b/ncurses/base/lib_getch.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 1998-2015,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -44,7 +44,7 @@
#define NEED_KEY_EVENT
#include <curses.priv.h>
-MODULE_ID("$Id: lib_getch.c,v 1.141 2020/09/05 22:50:47 tom Exp $")
+MODULE_ID("$Id: lib_getch.c,v 1.146 2023/04/29 18:57:12 tom Exp $")
#include <fifo_defs.h>
@@ -298,8 +298,8 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
} else
#endif
#if USE_KLIBC_KBD
- if (NC_ISATTY(sp->_ifd) && sp->_cbreak) {
- ch = _read_kbd(0, 1, !sp->_raw);
+ if (NC_ISATTY(sp->_ifd) && IsCbreak(sp)) {
+ ch = _read_kbd(0, 1, !IsRaw(sp));
n = (ch == -1) ? -1 : 1;
sp->_extended_key = (ch == 0);
} else
@@ -308,20 +308,15 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
#if defined(USE_TERM_DRIVER)
int buf;
# if defined(EXP_WIN32_DRIVER)
- if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && sp->_cbreak) {
-# if USE_PTHREADS_EINTR
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
- _nc_globals.read_thread = pthread_self();
-# endif
+ if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && IsCbreak(sp)) {
+ _nc_set_read_thread(TRUE);
n = _nc_console_read(sp,
_nc_console_handle(sp->_ifd),
&buf);
-# if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-# endif
+ _nc_set_read_thread(FALSE);
} else
# elif defined(_NC_WINDOWS)
- if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && sp->_cbreak)
+ if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && IsCbreak(sp))
n = _nc_mingw_console_read(sp,
_nc_get_handle(sp->_ifd),
&buf);
@@ -334,12 +329,8 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
int buf;
#endif
unsigned char c2 = 0;
-#if USE_PTHREADS_EINTR
-#if USE_WEAK_SYMBOLS
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
-#endif
- _nc_globals.read_thread = pthread_self();
-#endif
+
+ _nc_set_read_thread(TRUE);
#if defined(EXP_WIN32_DRIVER)
n = _nc_console_read(sp,
_nc_console_handle(sp->_ifd),
@@ -348,9 +339,7 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
#else
n = (int) read(sp->_ifd, &c2, (size_t) 1);
#endif
-#if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-#endif
+ _nc_set_read_thread(FALSE);
ch = c2;
#endif /* USE_TERM_DRIVER */
}
@@ -391,7 +380,17 @@ recur_wrefresh(WINDOW *win)
{
#ifdef USE_PTHREADS
SCREEN *sp = _nc_screen_of(win);
- if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
+ bool same_sp;
+
+ if (_nc_use_pthreads) {
+ _nc_lock_global(curses);
+ same_sp = (sp == CURRENT_SCREEN);
+ _nc_unlock_global(curses);
+ } else {
+ same_sp = (sp == CURRENT_SCREEN);
+ }
+
+ if (_nc_use_pthreads && !same_sp) {
SCREEN *save_SP;
/* temporarily switch to the window's screen to check/refresh */
@@ -404,7 +403,7 @@ recur_wrefresh(WINDOW *win)
} else
#endif
if ((is_wintouched(win) || (win->_flags & _HASMOVED))
- && !(win->_flags & _ISPAD)) {
+ && !IS_PAD(win)) {
wrefresh(win);
}
}
@@ -480,8 +479,8 @@ _nc_wgetch(WINDOW *win,
*/
if (head == -1 &&
!sp->_notty &&
- !sp->_raw &&
- !sp->_cbreak &&
+ !IsRaw(sp) &&
+ !IsCbreak(sp) &&
!sp->_called_wgetch) {
char buf[MAXCOLUMNS], *bufp;
@@ -514,13 +513,13 @@ _nc_wgetch(WINDOW *win,
recur_wrefresh(win);
- if (win->_notimeout || (win->_delay >= 0) || (sp->_cbreak > 1)) {
+ if (win->_notimeout || (win->_delay >= 0) || (IsCbreak(sp) > 1)) {
if (head == -1) { /* fifo is empty */
int delay;
TR(TRACE_IEVENT, ("timed delay in wgetch()"));
- if (sp->_cbreak > 1)
- delay = (sp->_cbreak - 1) * 100;
+ if (IsCbreak(sp) > 1)
+ delay = (IsCbreak(sp) - 1) * 100;
else
delay = win->_delay;
@@ -551,7 +550,7 @@ _nc_wgetch(WINDOW *win,
* This is tricky. We only want to get special-key
* events one at a time. But we want to accumulate
* mouse events until either (a) the mouse logic tells
- * us it's picked up a complete gesture, or (b)
+ * us it has picked up a complete gesture, or (b)
* there's a detectable time lapse after one.
*
* Note: if the mouse code starts failing to compose
@@ -639,7 +638,7 @@ _nc_wgetch(WINDOW *win,
* However, we provide the same visual result as Solaris, moving the
* cursor to the left.
*/
- if (sp->_echo && !(win->_flags & _ISPAD)) {
+ if (IsEcho(sp) && !IS_PAD(win)) {
chtype backup = (chtype) ((ch == KEY_BACKSPACE) ? '\b' : ch);
if (backup < KEY_MIN)
wechochar(win, backup);
@@ -648,7 +647,7 @@ _nc_wgetch(WINDOW *win,
/*
* Simulate ICRNL mode
*/
- if ((ch == '\r') && sp->_nl)
+ if ((ch == '\r') && IsNl(sp))
ch = '\n';
/* Strip 8th-bit if so desired. We do this only for characters that
diff --git a/ncurses/base/lib_getstr.c b/ncurses/base/lib_getstr.c
index 7871fb357a62..cac21fc85bd9 100644
--- a/ncurses/base/lib_getstr.c
+++ b/ncurses/base/lib_getstr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 2018-2021,2023 Thomas E. Dickey *
* Copyright 1998-2011,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -42,7 +42,7 @@
#define NEED_KEY_EVENT
#include <curses.priv.h>
-MODULE_ID("$Id: lib_getstr.c,v 1.35 2020/07/18 20:02:24 tom Exp $")
+MODULE_ID("$Id: lib_getstr.c,v 1.39 2023/04/29 19:00:17 tom Exp $")
/*
* This wipes out the last character, no matter whether it was a tab, control
@@ -78,7 +78,7 @@ wgetnstr_events(WINDOW *win,
{
SCREEN *sp = _nc_screen_of(win);
TTY buf;
- bool oldnl, oldecho, oldraw, oldcbreak;
+ TTY_FLAGS save_flags;
char erasec;
char killc;
char *oldstr;
@@ -94,14 +94,11 @@ wgetnstr_events(WINDOW *win,
NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx &buf);
- oldnl = sp->_nl;
- oldecho = sp->_echo;
- oldraw = sp->_raw;
- oldcbreak = sp->_cbreak;
+ save_flags = sp->_tty_flags;
NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
- NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
- NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
+ if (!save_flags._raw)
+ NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
erasec = NCURSES_SP_NAME(erasechar) (NCURSES_SP_ARG);
killc = NCURSES_SP_NAME(killchar) (NCURSES_SP_ARG);
@@ -115,7 +112,7 @@ wgetnstr_events(WINDOW *win,
while ((ch = wgetch_events(win, evl)) != ERR) {
/*
* Some terminals (the Wyse-50 is the most common) generate
- * a \n from the down-arrow key. With this logic, it's the
+ * a \n from the down-arrow key. With this logic, it is the
* user's choice whether to set kcud=\n for wgetch();
* terminating *getstr() with \n should work either way.
*/
@@ -123,7 +120,7 @@ wgetnstr_events(WINDOW *win,
|| ch == '\r'
|| ch == KEY_DOWN
|| ch == KEY_ENTER) {
- if (oldecho == TRUE
+ if (save_flags._echo == TRUE
&& win->_cury == win->_maxy
&& win->_scroll)
wechochar(win, (chtype) '\n');
@@ -139,18 +136,18 @@ wgetnstr_events(WINDOW *win,
#endif
if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
if (str > oldstr) {
- str = WipeOut(win, y, x, oldstr, str, oldecho);
+ str = WipeOut(win, y, x, oldstr, str, save_flags._echo);
}
} else if (ch == killc) {
while (str > oldstr) {
- str = WipeOut(win, y, x, oldstr, str, oldecho);
+ str = WipeOut(win, y, x, oldstr, str, save_flags._echo);
}
} else if (ch >= KEY_MIN
|| (str - oldstr >= maxlen)) {
NCURSES_SP_NAME(beep) (NCURSES_SP_ARG);
} else {
*str++ = (char) ch;
- if (oldecho == TRUE) {
+ if (save_flags._echo == TRUE) {
int oldy = win->_cury;
if (waddch(win, (chtype) ch) == ERR) {
/*
@@ -160,9 +157,9 @@ wgetnstr_events(WINDOW *win,
*/
win->_flags &= ~_WRAPPED;
waddch(win, (chtype) ' ');
- str = WipeOut(win, y, x, oldstr, str, oldecho);
+ str = WipeOut(win, y, x, oldstr, str, save_flags._echo);
continue;
- } else if (win->_flags & _WRAPPED) {
+ } else if (IS_WRAPPED(win)) {
/*
* If the last waddch forced a wrap &
* scroll, adjust our reference point
@@ -191,11 +188,7 @@ wgetnstr_events(WINDOW *win,
/* Restore with a single I/O call, to fix minor asymmetry between
* raw/noraw, etc.
*/
- sp->_nl = oldnl;
- sp->_echo = oldecho;
- sp->_raw = oldraw;
- sp->_cbreak = oldcbreak;
-
+ sp->_tty_flags = save_flags;
NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
*str = '\0';
diff --git a/ncurses/base/lib_insnstr.c b/ncurses/base/lib_insnstr.c
index ff1ae573a576..caec48e8eb70 100644
--- a/ncurses/base/lib_insnstr.c
+++ b/ncurses/base/lib_insnstr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 2004-2009,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -41,7 +41,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_insnstr.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_insnstr.c,v 1.10 2023/11/21 21:58:03 tom Exp $")
NCURSES_EXPORT(int)
winsnstr(WINDOW *win, const char *s, int n)
@@ -51,7 +51,7 @@ winsnstr(WINDOW *win, const char *s, int n)
T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n));
- if (win != 0 && str != 0) {
+ if (win != 0 && str != 0 && n != 0) {
SCREEN *sp = _nc_screen_of(win);
#if USE_WIDEC_SUPPORT
/*
@@ -70,6 +70,7 @@ winsnstr(WINDOW *win, const char *s, int n)
init_mb(state);
n3 = mbstowcs(buffer, s, nn);
if (n3 != (size_t) (-1)) {
+ buffer[n3] = '\0';
code = wins_nwstr(win, buffer, (int) n3);
}
free(buffer);
@@ -82,7 +83,7 @@ winsnstr(WINDOW *win, const char *s, int n)
NCURSES_SIZE_T ox = win->_curx;
const unsigned char *cp;
- for (cp = str; (n <= 0 || (cp - str) < n) && *cp; cp++) {
+ for (cp = str; (n < 0 || (cp - str) < n) && *cp; cp++) {
_nc_insert_ch(sp, win, (chtype) UChar(*cp));
}
win->_curx = ox;
diff --git a/ncurses/base/lib_instr.c b/ncurses/base/lib_instr.c
index 2aa0fc32e9f3..221ebd290400 100644
--- a/ncurses/base/lib_instr.c
+++ b/ncurses/base/lib_instr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020-2021,2023 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -42,7 +42,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_instr.c,v 1.24 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_instr.c,v 1.26 2023/06/03 12:37:04 tom Exp $")
NCURSES_EXPORT(int)
winnstr(WINDOW *win, char *str, int n)
@@ -66,7 +66,6 @@ winnstr(WINDOW *win, char *str, int n)
cchar_t *cell = &(text[col]);
attr_t attrs;
NCURSES_PAIRS_T pair;
- mbstate_t state;
char *tmp;
if (!isWidecExt(*cell)) {
@@ -79,11 +78,12 @@ winnstr(WINDOW *win, char *str, int n)
bool done = FALSE;
if (getcchar(cell, wch, &attrs, &pair, 0) == OK) {
+ mbstate_t state;
size_t n3;
init_mb(state);
n3 = wcstombs(0, wch, (size_t) 0);
- if (!isEILSEQ(n3) && (n3 != 0)) {
+ if (!isEILSEQ(n3) && (n3 != 0) && (n3 <= MB_LEN_MAX)) {
size_t need = n3 + 10 + (size_t) i;
int have = (int) n3 + i;
diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c
index 6caef327a3c0..a03d8b8e1ab0 100644
--- a/ncurses/base/lib_mouse.c
+++ b/ncurses/base/lib_mouse.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 2018-2023,2024 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -85,7 +85,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_mouse.c,v 1.192 2021/02/14 00:17:09 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.200 2024/02/17 21:13:01 tom Exp $")
#include <tic.h>
@@ -380,7 +380,7 @@ handle_sysmouse(int sig GCC_UNUSED)
}
#endif /* USE_SYSMOUSE */
-#ifndef USE_TERM_DRIVER
+#if !defined(USE_TERM_DRIVER) || defined(EXP_WIN32_DRIVER)
#define xterm_kmous "\033[M"
static void
@@ -419,13 +419,22 @@ init_xterm_mouse(SCREEN *sp)
} else {
int code = tigetnum("XM");
switch (code) {
+#ifdef EXP_XTERM_1005
+ case 1005:
+ /* see "xterm+sm+1005" */
+ sp->_mouse_xtermcap = "\033[?1005;1000%?%p1%{1}%=%th%el%;";
+ sp->_mouse_format = MF_XTERM_1005;
+ break;
+#endif
case 1006:
+ /* see "xterm+sm+1006" */
+ sp->_mouse_xtermcap = "\033[?1006;1000%?%p1%{1}%=%th%el%;";
+ sp->_mouse_format = MF_SGR1006;
break;
default:
- code = 1000;
+ sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
break;
}
- sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
}
}
#endif
@@ -433,6 +442,9 @@ init_xterm_mouse(SCREEN *sp)
static void
enable_xterm_mouse(SCREEN *sp, int enable)
{
+ TPUTS_TRACE(enable
+ ? "xterm mouse initialization"
+ : "xterm mouse deinitialization");
#if USE_EMX_MOUSE
sp->_emxmouse_activated = enable;
#else
@@ -441,6 +453,18 @@ enable_xterm_mouse(SCREEN *sp, int enable)
sp->_mouse_active = enable;
}
+#if defined(USE_TERM_DRIVER)
+static void
+enable_win32_mouse(SCREEN *sp, int enable)
+{
+#if defined(EXP_WIN32_DRIVER)
+ enable_xterm_mouse(sp, enable);
+#else
+ sp->_mouse_active = enable;
+#endif
+}
+#endif
+
#if USE_GPM_SUPPORT
static bool
allow_gpm_mouse(SCREEN *sp GCC_UNUSED)
@@ -732,7 +756,8 @@ initialize_mousetype(SCREEN *sp)
#ifdef USE_TERM_DRIVER
CallDriver(sp, td_initmouse);
-#else
+#endif
+#if !defined(USE_TERM_DRIVER) || defined(EXP_WIN32_DRIVER)
/* we know how to recognize mouse events under "xterm" */
if (NonEmpty(key_mouse)) {
init_xterm_mouse(sp);
@@ -751,13 +776,15 @@ _nc_mouse_init(SCREEN *sp)
{
bool result = FALSE;
+ T((T_CALLED("_nc_mouse_init(%p)"), (void *) sp));
+
if (sp != 0) {
if (!sp->_mouse_initialized) {
int i;
sp->_mouse_initialized = TRUE;
- TR(MY_TRACE, ("_nc_mouse_init() called"));
+ TR(MY_TRACE, ("set _mouse_initialized"));
sp->_mouse_eventp = FirstEV(sp);
for (i = 0; i < EV_MAX; i++)
@@ -765,11 +792,11 @@ _nc_mouse_init(SCREEN *sp)
initialize_mousetype(sp);
- T(("_nc_mouse_init() set mousetype to %d", sp->_mouse_type));
+ T(("set _mouse_type to %d", sp->_mouse_type));
}
result = sp->_mouse_initialized;
}
- return result;
+ returnCode(result);
}
/*
@@ -960,6 +987,17 @@ handle_wheel(SCREEN *sp, MEVENT * eventp, int button, int wheel)
PRESS_POSITION(3);
break;
default:
+ /*
+ * case 3 is sent when the mouse buttons are released.
+ *
+ * If the terminal uses xterm mode 1003, a continuous series of
+ * button-release events is sent as the mouse moves around the screen,
+ * or as the wheel mouse is rotated.
+ *
+ * Return false in this case, so that when running in X10 mode, we will
+ * recalculate bstate.
+ */
+ eventp->bstate = REPORT_MOUSE_POSITION;
result = FALSE;
break;
}
@@ -1065,12 +1103,7 @@ decode_xterm_X10(SCREEN *sp, MEVENT * eventp)
int res;
bool result;
-# if USE_PTHREADS_EINTR
-# if USE_WEAK_SYMBOLS
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
-# endif
- _nc_globals.read_thread = pthread_self();
-# endif
+ _nc_set_read_thread(TRUE);
for (grabbed = 0; grabbed < MAX_KBUF; grabbed += (size_t) res) {
/* For VIO mouse we add extra bit 64 to disambiguate button-up. */
@@ -1084,9 +1117,7 @@ decode_xterm_X10(SCREEN *sp, MEVENT * eventp)
if (res == -1)
break;
}
-#if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-#endif
+ _nc_set_read_thread(FALSE);
kbuf[MAX_KBUF] = '\0';
TR(TRACE_IEVENT,
@@ -1120,12 +1151,7 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp)
coords[0] = 0;
coords[1] = 0;
-# if USE_PTHREADS_EINTR
-# if USE_WEAK_SYMBOLS
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
-# endif
- _nc_globals.read_thread = pthread_self();
-# endif
+ _nc_set_read_thread(TRUE);
for (grabbed = 0; grabbed < limit;) {
int res;
@@ -1158,9 +1184,7 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp)
break;
}
}
-#if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-#endif
+ _nc_set_read_thread(FALSE);
TR(TRACE_IEVENT,
("_nc_mouse_inline sees the following xterm data: %s",
@@ -1204,12 +1228,7 @@ read_SGR(SCREEN *sp, SGR_DATA * result)
int marker = 1;
memset(result, 0, sizeof(*result));
-# if USE_PTHREADS_EINTR
-# if USE_WEAK_SYMBOLS
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
-# endif
- _nc_globals.read_thread = pthread_self();
-# endif
+ _nc_set_read_thread(TRUE);
do {
int res;
@@ -1274,9 +1293,7 @@ read_SGR(SCREEN *sp, SGR_DATA * result)
}
++grabbed;
} while (!isFinal(ch));
-#if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-#endif
+ _nc_set_read_thread(FALSE);
kbuf[++grabbed] = 0;
TR(TRACE_IEVENT,
@@ -1389,11 +1406,14 @@ _nc_mouse_inline(SCREEN *sp)
static void
mouse_activate(SCREEN *sp, int on)
{
+ T((T_CALLED("mouse_activate(%p,%s)"),
+ (void *) SP_PARM, on ? "on" : "off"));
+
if (!on && !sp->_mouse_initialized)
- return;
+ returnVoid;
if (!_nc_mouse_init(sp))
- return;
+ returnVoid;
if (on) {
sp->_mouse_bstate = 0;
@@ -1402,7 +1422,6 @@ mouse_activate(SCREEN *sp, int on)
#if NCURSES_EXT_FUNCS
NCURSES_SP_NAME(keyok) (NCURSES_SP_ARGx KEY_MOUSE, on);
#endif
- TPUTS_TRACE("xterm mouse initialization");
enable_xterm_mouse(sp, 1);
break;
#if USE_GPM_SUPPORT
@@ -1421,25 +1440,28 @@ mouse_activate(SCREEN *sp, int on)
#endif
#ifdef USE_TERM_DRIVER
case M_TERM_DRIVER:
- sp->_mouse_active = TRUE;
+ enable_win32_mouse(sp, TRUE);
break;
#endif
case M_NONE:
- return;
+ returnVoid;
+ default:
+ T(("unexpected mouse mode"));
+ break;
}
/* Make runtime binding to cut down on object size of applications that
* do not use the mouse (e.g., 'clear').
*/
- sp->_mouse_event = _nc_mouse_event;
+ /* *INDENT-EQLS* */
+ sp->_mouse_event = _nc_mouse_event;
sp->_mouse_inline = _nc_mouse_inline;
- sp->_mouse_parse = _nc_mouse_parse;
+ sp->_mouse_parse = _nc_mouse_parse;
sp->_mouse_resume = _nc_mouse_resume;
- sp->_mouse_wrap = _nc_mouse_wrap;
+ sp->_mouse_wrap = _nc_mouse_wrap;
} else {
switch (sp->_mouse_type) {
case M_XTERM:
- TPUTS_TRACE("xterm mouse deinitialization");
enable_xterm_mouse(sp, 0);
break;
#if USE_GPM_SUPPORT
@@ -1455,14 +1477,18 @@ mouse_activate(SCREEN *sp, int on)
#endif
#ifdef USE_TERM_DRIVER
case M_TERM_DRIVER:
- sp->_mouse_active = FALSE;
+ enable_win32_mouse(sp, FALSE);
break;
#endif
case M_NONE:
- return;
+ returnVoid;
+ default:
+ T(("unexpected mouse mode"));
+ break;
}
}
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
+ returnVoid;
}
/**************************************************************************
@@ -1560,7 +1586,7 @@ _nc_mouse_parse(SCREEN *sp, int runcount)
if (changed) {
merge = FALSE;
for (b = 1; b <= MAX_BUTTONS; ++b) {
- if ((sp->_mouse_mask & MASK_CLICK(b))
+ if ((sp->_mouse_mask2 & MASK_CLICK(b))
&& (ep->bstate & MASK_PRESS(b))) {
next->bstate &= ~MASK_RELEASE(b);
next->bstate |= MASK_CLICK(b);
@@ -1641,7 +1667,7 @@ _nc_mouse_parse(SCREEN *sp, int runcount)
&& (next->bstate & BUTTON_CLICKED)) {
merge = FALSE;
for (b = 1; b <= MAX_BUTTONS; ++b) {
- if ((sp->_mouse_mask & MASK_DOUBLE_CLICK(b))
+ if ((sp->_mouse_mask2 & MASK_DOUBLE_CLICK(b))
&& (ep->bstate & MASK_CLICK(b))
&& (next->bstate & MASK_CLICK(b))) {
next->bstate &= ~MASK_CLICK(b);
@@ -1659,7 +1685,7 @@ _nc_mouse_parse(SCREEN *sp, int runcount)
&& (next->bstate & BUTTON_CLICKED)) {
merge = FALSE;
for (b = 1; b <= MAX_BUTTONS; ++b) {
- if ((sp->_mouse_mask & MASK_TRIPLE_CLICK(b))
+ if ((sp->_mouse_mask2 & MASK_TRIPLE_CLICK(b))
&& (ep->bstate & MASK_DOUBLE_CLICK(b))
&& (next->bstate & MASK_CLICK(b))) {
next->bstate &= ~MASK_CLICK(b);
@@ -1719,7 +1745,8 @@ _nc_mouse_parse(SCREEN *sp, int runcount)
#endif /* TRACE */
/* after all this, do we have a valid event? */
- return ValidEvent(PREV(first_invalid));
+ ep = PREV(first_invalid);
+ return ValidEvent(ep) && ((ep->bstate & sp->_mouse_mask) != 0);
}
static void
@@ -1963,10 +1990,24 @@ wenclose(const WINDOW *win, int y, int x)
if (win != 0) {
y -= win->_yoffset;
- result = ((win->_begy <= y &&
- win->_begx <= x &&
- (win->_begx + win->_maxx) >= x &&
- (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
+ if (IS_PAD(win)) {
+ if (win->_pad._pad_y >= 0 &&
+ win->_pad._pad_x >= 0 &&
+ win->_pad._pad_top >= 0 &&
+ win->_pad._pad_left >= 0 &&
+ win->_pad._pad_right >= 0 &&
+ win->_pad._pad_bottom >= 0) {
+ result = ((win->_pad._pad_top <= y &&
+ win->_pad._pad_left <= x &&
+ win->_pad._pad_right >= x &&
+ win->_pad._pad_bottom >= y) ? TRUE : FALSE);
+ }
+ } else {
+ result = ((win->_begy <= y &&
+ win->_begx <= x &&
+ (win->_begx + win->_maxx) >= x &&
+ (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
+ }
}
returnBool(result);
}
@@ -2035,6 +2076,7 @@ wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen)
int y = *pY;
int x = *pX;
+ T(("transform input %d,%d", y, x));
if (to_screen) {
y += win->_begy + win->_yoffset;
x += win->_begx;
@@ -2050,6 +2092,7 @@ wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen)
if (result) {
*pX = x;
*pY = y;
+ T(("output transform %d,%d", y, x));
}
}
returnBool(result);
diff --git a/ncurses/base/lib_mvwin.c b/ncurses/base/lib_mvwin.c
index 58bdb199f274..fca014efeb9a 100644
--- a/ncurses/base/lib_mvwin.c
+++ b/ncurses/base/lib_mvwin.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2009,2010 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,7 +43,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_mvwin.c,v 1.19 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_mvwin.c,v 1.20 2021/10/23 18:57:41 tom Exp $")
NCURSES_EXPORT(int)
mvwin(WINDOW *win, int by, int bx)
@@ -54,7 +54,7 @@ mvwin(WINDOW *win, int by, int bx)
T((T_CALLED("mvwin(%p,%d,%d)"), (void *) win, by, bx));
- if (!win || (win->_flags & _ISPAD))
+ if (!win || IS_PAD(win))
returnCode(ERR);
/*
@@ -63,7 +63,7 @@ mvwin(WINDOW *win, int by, int bx)
*/
#if 0
/* Copying subwindows is allowed, but it is expensive... */
- if (win->_flags & _SUBWIN) {
+ if (IS_SUBWIN(win)) {
int err = ERR;
WINDOW *parent = win->_parent;
if (parent) { /* Now comes the complicated and costly part, you should really
diff --git a/ncurses/base/lib_newterm.c b/ncurses/base/lib_newterm.c
index bba97ba1fae8..15d05a31b583 100644
--- a/ncurses/base/lib_newterm.c
+++ b/ncurses/base/lib_newterm.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 2018-2020,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -49,7 +49,7 @@
#include <tic.h>
-MODULE_ID("$Id: lib_newterm.c,v 1.103 2020/09/05 21:34:04 tom Exp $")
+MODULE_ID("$Id: lib_newterm.c,v 1.104 2022/07/09 18:58:58 tom Exp $")
#ifdef USE_TERM_DRIVER
#define NumLabels InfoOf(SP_PARM).numlabels
@@ -362,11 +362,14 @@ NCURSES_EXPORT(SCREEN *)
newterm(const char *name, FILE *ofp, FILE *ifp)
{
SCREEN *rc;
+
+ _nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(newterm) (CURRENT_SCREEN_PRE, name, ofp, ifp);
_nc_forget_prescr();
_nc_unlock_global(prescreen);
+
return rc;
}
#endif
diff --git a/ncurses/base/lib_newwin.c b/ncurses/base/lib_newwin.c
index 580d033b7d44..a6723197c093 100644
--- a/ncurses/base/lib_newwin.c
+++ b/ncurses/base/lib_newwin.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -44,7 +44,7 @@
#include <curses.priv.h>
#include <stddef.h>
-MODULE_ID("$Id: lib_newwin.c,v 1.75 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_newwin.c,v 1.76 2021/10/23 18:53:38 tom Exp $")
#define window_is(name) ((sp)->_##name == win)
@@ -114,7 +114,7 @@ _nc_freewin(WINDOW *win)
else
q->next = p->next;
- if (!(win->_flags & _SUBWIN)) {
+ if (!IS_SUBWIN(win)) {
int i;
for (i = 0; i <= win->_maxy; i++)
@@ -219,7 +219,7 @@ derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
if (num_columns == 0)
num_columns = orig->_maxx + 1 - begx;
- if (orig->_flags & _ISPAD)
+ if (IS_PAD(orig))
flags |= _ISPAD;
win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx num_lines, num_columns,
diff --git a/ncurses/base/lib_nl.c b/ncurses/base/lib_nl.c
index df07349fc83c..417b257d0399 100644
--- a/ncurses/base/lib_nl.c
+++ b/ncurses/base/lib_nl.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2000,2009 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -45,7 +45,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_nl.c,v 1.13 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_nl.c,v 1.14 2023/04/29 18:51:49 tom Exp $")
#ifdef __EMX__
#include <io.h>
@@ -57,7 +57,7 @@ NCURSES_SP_NAME(nl) (NCURSES_SP_DCL0)
T((T_CALLED("nl(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
- SP_PARM->_nl = TRUE;
+ IsNl(SP_PARM) = TRUE;
#ifdef __EMX__
_nc_flush();
_fsetmode(NC_OUTPUT(SP_PARM), "t");
@@ -79,7 +79,7 @@ NCURSES_SP_NAME(nonl) (NCURSES_SP_DCL0)
T((T_CALLED("nonl(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
- SP_PARM->_nl = FALSE;
+ IsNl(SP_PARM) = FALSE;
#ifdef __EMX__
_nc_flush();
_fsetmode(NC_OUTPUT(SP_PARM), "b");
diff --git a/ncurses/base/lib_overlay.c b/ncurses/base/lib_overlay.c
index 6d451d046a85..6d21c7617047 100644
--- a/ncurses/base/lib_overlay.c
+++ b/ncurses/base/lib_overlay.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2013,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -41,7 +41,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_overlay.c,v 1.33 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_overlay.c,v 1.34 2023/09/16 16:39:07 tom Exp $")
static int
overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
@@ -78,12 +78,12 @@ overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
dy2 = dy1 + dst->_maxy;
if (dx2 >= sx1 && dx1 <= sx2 && dy2 >= sy1 && dy1 <= sy2) {
- int sminrow = max(sy1, dy1) - sy1;
- int smincol = max(sx1, dx1) - sx1;
- int dminrow = max(sy1, dy1) - dy1;
- int dmincol = max(sx1, dx1) - dx1;
- int dmaxrow = min(sy2, dy2) - dy1;
- int dmaxcol = min(sx2, dx2) - dx1;
+ int sminrow = Max(sy1, dy1) - sy1;
+ int smincol = Max(sx1, dx1) - sx1;
+ int dminrow = Max(sy1, dy1) - dy1;
+ int dmincol = Max(sx1, dx1) - dx1;
+ int dmaxrow = Min(sy2, dy2) - dy1;
+ int dmaxcol = Min(sx2, dx2) - dx1;
rc = copywin(src, dst,
sminrow, smincol,
diff --git a/ncurses/base/lib_pad.c b/ncurses/base/lib_pad.c
index 73978fbb8ad2..d4bd7f111bef 100644
--- a/ncurses/base/lib_pad.c
+++ b/ncurses/base/lib_pad.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2010,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,7 +43,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_pad.c,v 1.48 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_pad.c,v 1.50 2021/10/23 22:57:27 tom Exp $")
NCURSES_EXPORT(WINDOW *)
NCURSES_SP_NAME(newpad) (NCURSES_SP_DCLx int l, int c)
@@ -90,7 +90,7 @@ subpad(WINDOW *orig, int l, int c, int begy, int begx)
T((T_CALLED("subpad(%d, %d)"), l, c));
if (orig) {
- if (!(orig->_flags & _ISPAD)
+ if (!IS_PAD(orig)
|| ((win = derwin(orig, l, c, begy, begx)) == NULL))
returnWin(0);
}
@@ -146,7 +146,7 @@ pnoutrefresh(WINDOW *win,
if (win == 0)
returnCode(ERR);
- if (!(win->_flags & _ISPAD))
+ if (!IS_PAD(win))
returnCode(ERR);
sp = _nc_screen_of(win);
@@ -296,7 +296,7 @@ pnoutrefresh(WINDOW *win,
/*
* Use the pad's current position, if it will be visible.
- * If not, don't do anything; it's not an error.
+ * If not, don't do anything; it is not an error.
*/
if (win->_leaveok == FALSE
&& win->_cury >= pminrow
@@ -334,7 +334,7 @@ pechochar(WINDOW *pad, const chtype ch)
if (pad == 0)
returnCode(ERR);
- if (!(pad->_flags & _ISPAD))
+ if (!IS_PAD(pad))
returnCode(wechochar(pad, ch));
waddch(pad, ch);
diff --git a/ncurses/base/lib_refresh.c b/ncurses/base/lib_refresh.c
index d8444289c152..bcaa4624b8a9 100644
--- a/ncurses/base/lib_refresh.c
+++ b/ncurses/base/lib_refresh.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020-2021,2023 Thomas E. Dickey *
* Copyright 1998-2010,2011 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,7 +43,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_refresh.c,v 1.46 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_refresh.c,v 1.48 2023/05/27 20:13:10 tom Exp $")
NCURSES_EXPORT(int)
wrefresh(WINDOW *win)
@@ -92,13 +92,21 @@ wnoutrefresh(WINDOW *win)
T((T_CALLED("wnoutrefresh(%p)"), (void *) win));
- /*
- * This function will break badly if we try to refresh a pad.
- */
- if ((win == 0)
- || (win->_flags & _ISPAD))
+ if (win == NULL)
returnCode(ERR);
+ /*
+ * Handle pads as a special case.
+ */
+ if (IS_PAD(win)) {
+ returnCode(pnoutrefresh(win,
+ win->_pad._pad_y,
+ win->_pad._pad_x,
+ win->_pad._pad_top,
+ win->_pad._pad_left,
+ win->_pad._pad_bottom,
+ win->_pad._pad_right));
+ }
#ifdef TRACE
if (USE_TRACEF(TRACE_UPDATE)) {
_tracedump("...win", win);
@@ -200,7 +208,6 @@ wnoutrefresh(WINDOW *win)
});
if_WIDEC({
- static cchar_t blank = BLANK;
int last_dst = begx + ((last_src < win->_maxx)
? last_src
: win->_maxx);
@@ -246,6 +253,7 @@ wnoutrefresh(WINDOW *win)
*/
if (fix_left < dst_col || fix_right > last_dst) {
for (j = fix_left; j <= fix_right; ++j) {
+ static cchar_t blank = BLANK;
nline->text[j] = blank;
CHANGED_CELL(nline, j);
}
diff --git a/ncurses/base/lib_restart.c b/ncurses/base/lib_restart.c
index 81eb368843b8..0c61cb7ea667 100644
--- a/ncurses/base/lib_restart.c
+++ b/ncurses/base/lib_restart.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2012,2015 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -42,7 +42,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_restart.c,v 1.17 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_restart.c,v 1.18 2023/04/29 19:01:25 tom Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(restartterm) (NCURSES_SP_DCLx
@@ -65,31 +65,28 @@ NCURSES_SP_NAME(restartterm) (NCURSES_SP_DCLx
if (TINFO_SETUP_TERM(&new_term, termp, filenum, errret, FALSE) != OK) {
result = ERR;
} else if (SP_PARM != 0) {
- int saveecho = SP_PARM->_echo;
- int savecbreak = SP_PARM->_cbreak;
- int saveraw = SP_PARM->_raw;
- int savenl = SP_PARM->_nl;
+ TTY_FLAGS save_flags = SP_PARM->_tty_flags;
#ifdef USE_TERM_DRIVER
SP_PARM->_term = new_term;
#endif
- if (saveecho) {
+ if (save_flags._echo) {
NCURSES_SP_NAME(echo) (NCURSES_SP_ARG);
} else {
NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
}
- if (savecbreak) {
+ if (save_flags._cbreak) {
NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
- } else if (saveraw) {
+ } else if (save_flags._raw) {
NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
NCURSES_SP_NAME(raw) (NCURSES_SP_ARG);
} else {
NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
}
- if (savenl) {
+ if (save_flags._nl) {
NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
} else {
NCURSES_SP_NAME(nonl) (NCURSES_SP_ARG);
diff --git a/ncurses/base/lib_screen.c b/ncurses/base/lib_screen.c
index 6afba6611c61..e2647b54e2eb 100644
--- a/ncurses/base/lib_screen.c
+++ b/ncurses/base/lib_screen.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019,2020 Thomas E. Dickey *
+ * Copyright 2019-2021,2023 Thomas E. Dickey *
* Copyright 1998-2017,2018 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -42,7 +42,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_screen.c,v 1.100 2020/05/25 22:48:41 tom Exp $")
+MODULE_ID("$Id: lib_screen.c,v 1.105 2023/04/28 20:58:54 tom Exp $")
#define MAX_SIZE 0x3fff /* 16k is big enough for a window or pad */
@@ -90,7 +90,6 @@ typedef struct {
typedef struct {
const char name[17];
PARAM_TYPE type;
- size_t size;
size_t offset;
} SCR_PARAMS;
@@ -120,8 +119,7 @@ static const SCR_ATTRS scr_attrs[] =
};
#undef DATA
-#define sizeof2(type,name) sizeof(((type *)0)->name)
-#define DATA(name, type) { { #name }, type, sizeof2(WINDOW, name), offsetof(WINDOW, name) }
+#define DATA(name, type) { { #name }, type, offsetof(WINDOW, name) }
static const SCR_PARAMS scr_params[] =
{
@@ -200,7 +198,7 @@ read_txt(FILE *fp)
if (ch == '\n') {
result[--used] = '\0';
- T(("READ:%s", result));
+ TR(TRACE_IEVENT, ("READ:%s", result));
} else if (used == 0) {
free(result);
result = 0;
@@ -214,7 +212,7 @@ decode_attr(char *source, attr_t *target, int *color)
{
bool found = FALSE;
- T(("decode_attr '%s'", source));
+ TR(TRACE_IEVENT, ("decode_attr '%s'", source));
while (*source) {
if (source[0] == MARKER && source[1] == L_CURL) {
@@ -272,7 +270,7 @@ decode_char(char *source, int *target)
int base = 16;
const char digits[] = "0123456789abcdef";
- T(("decode_char '%s'", source));
+ TR(TRACE_IEVENT, ("decode_char '%s'", source));
*target = ' ';
switch (*source) {
case MARKER:
@@ -329,7 +327,7 @@ decode_chtype(char *source, chtype fillin, chtype *target)
int color = PAIR_NUMBER((int) attr);
int value;
- T(("decode_chtype '%s'", source));
+ TR(TRACE_IEVENT, ("decode_chtype '%s'", source));
source = decode_attr(source, &attr, &color);
source = decode_char(source, &value);
*target = (ChCharOf(value) | attr | (chtype) COLOR_PAIR(color));
@@ -347,7 +345,7 @@ decode_cchar(char *source, cchar_t *fillin, cchar_t *target)
int append = 0;
int value = 0;
- T(("decode_cchar '%s'", source));
+ TR(TRACE_IEVENT, ("decode_cchar '%s'", source));
*target = blank;
#if NCURSES_EXT_COLORS
color = fillin->ext_color;
@@ -542,7 +540,7 @@ NCURSES_SP_NAME(getwin) (NCURSES_SP_DCLx FILE *filep)
returnWin(0);
}
- if (tmp._flags & _ISPAD) {
+ if (IS_PAD(&tmp)) {
nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
tmp._maxy + 1,
tmp._maxx + 1);
@@ -587,7 +585,7 @@ NCURSES_SP_NAME(getwin) (NCURSES_SP_DCLx FILE *filep)
nwin->_regtop = tmp._regtop;
nwin->_regbottom = tmp._regbottom;
- if (tmp._flags & _ISPAD)
+ if (IS_PAD(&tmp))
nwin->_pad = tmp._pad;
if (old_format) {
@@ -824,7 +822,7 @@ putwin(WINDOW *win, FILE *filep)
attr_t attr;
*buffer = '\0';
- if (!strncmp(name, "_pad.", (size_t) 5) && !(win->_flags & _ISPAD)) {
+ if (!strncmp(name, "_pad.", (size_t) 5) && !IS_PAD(win)) {
continue;
}
switch (scr_params[y].type) {
@@ -940,6 +938,31 @@ putwin(WINDOW *win, FILE *filep)
returnCode(code);
}
+/*
+ * Replace a window covering the whole screen, i.e., newscr or curscr.
+ */
+static WINDOW *
+replace_window(WINDOW *target, FILE *source)
+{
+ WINDOW *result = getwin(source);
+#if NCURSES_EXT_FUNCS
+ if (result != NULL) {
+ if (getmaxx(result) != getmaxx(target)
+ || getmaxy(result) != getmaxy(target)) {
+ int code = wresize(result,
+ 1 + getmaxy(target),
+ 1 + getmaxx(target));
+ if (code != OK) {
+ delwin(result);
+ result = NULL;
+ }
+ }
+ }
+#endif
+ delwin(target);
+ return result;
+}
+
NCURSES_EXPORT(int)
NCURSES_SP_NAME(scr_restore) (NCURSES_SP_DCLx const char *file)
{
@@ -949,9 +972,8 @@ NCURSES_SP_NAME(scr_restore) (NCURSES_SP_DCLx const char *file)
T((T_CALLED("scr_restore(%p,%s)"), (void *) SP_PARM, _nc_visbuf(file)));
if (_nc_access(file, R_OK) >= 0
- && (fp = fopen(file, BIN_R)) != 0) {
- delwin(NewScreen(SP_PARM));
- NewScreen(SP_PARM) = getwin(fp);
+ && (fp = safe_fopen(file, BIN_R)) != 0) {
+ NewScreen(SP_PARM) = replace_window(NewScreen(SP_PARM), fp);
#if !USE_REENTRANT
newscr = NewScreen(SP_PARM);
#endif
@@ -980,7 +1002,7 @@ scr_dump(const char *file)
T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
if (_nc_access(file, W_OK) < 0
- || (fp = fopen(file, BIN_W)) == 0) {
+ || (fp = safe_fopen(file, BIN_W)) == 0) {
result = ERR;
} else {
(void) putwin(newscr, fp);
@@ -1007,9 +1029,8 @@ NCURSES_SP_NAME(scr_init) (NCURSES_SP_DCLx const char *file)
FILE *fp = 0;
if (_nc_access(file, R_OK) >= 0
- && (fp = fopen(file, BIN_R)) != 0) {
- delwin(CurScreen(SP_PARM));
- CurScreen(SP_PARM) = getwin(fp);
+ && (fp = safe_fopen(file, BIN_R)) != 0) {
+ CurScreen(SP_PARM) = replace_window(CurScreen(SP_PARM), fp);
#if !USE_REENTRANT
curscr = CurScreen(SP_PARM);
#endif
diff --git a/ncurses/base/lib_set_term.c b/ncurses/base/lib_set_term.c
index 8573fbe7d522..78de859208b6 100644
--- a/ncurses/base/lib_set_term.c
+++ b/ncurses/base/lib_set_term.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -41,8 +41,11 @@
**
*/
+#define NEW_PAIR_INTERNAL 1
+
#include <curses.priv.h>
#include <tic.h>
+#include <new_pair.h>
#if USE_GPM_SUPPORT
#ifdef HAVE_LIBDL
@@ -54,7 +57,7 @@
#undef CUR
#define CUR SP_TERMTYPE
-MODULE_ID("$Id: lib_set_term.c,v 1.175 2020/10/10 19:09:03 juergen Exp $")
+MODULE_ID("$Id: lib_set_term.c,v 1.184 2022/12/10 21:34:12 tom Exp $")
#ifdef USE_TERM_DRIVER
#define MaxColors InfoOf(sp).maxcolors
@@ -146,9 +149,12 @@ delscreen(SCREEN *sp)
_nc_lock_global(curses);
if (delink_screen(sp)) {
+ WINDOWLIST *wl;
+ bool is_current = (sp == CURRENT_SCREEN);
+
#ifdef USE_SP_RIPOFF
- ripoff_t *rop;
if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) {
+ ripoff_t *rop;
for (rop = safe_ripoff_stack;
rop != safe_ripoff_sp && (rop - safe_ripoff_stack) < N_RIPS;
rop++) {
@@ -160,9 +166,13 @@ delscreen(SCREEN *sp)
}
#endif
- (void) _nc_freewin(CurScreen(sp));
- (void) _nc_freewin(NewScreen(sp));
- (void) _nc_freewin(StdScreen(sp));
+ /* delete all of the windows in this screen */
+ rescan:
+ for (each_window(sp, wl)) {
+ if (_nc_freewin(&(wl->win)) == OK) {
+ goto rescan;
+ }
+ }
if (sp->_slk != 0) {
@@ -187,6 +197,7 @@ delscreen(SCREEN *sp)
FreeIfNeeded(sp->_current_attr);
+ _nc_free_ordered_pairs(sp);
FreeIfNeeded(sp->_color_table);
FreeIfNeeded(sp->_color_pairs);
@@ -219,7 +230,7 @@ delscreen(SCREEN *sp)
* application might try to use (except cur_term, which may have
* multiple references in different screens).
*/
- if (sp == CURRENT_SCREEN) {
+ if (is_current) {
#if !USE_REENTRANT
curscr = 0;
newscr = 0;
@@ -234,6 +245,8 @@ delscreen(SCREEN *sp)
_nc_wacs = 0;
}
#endif
+ } else {
+ set_term(CURRENT_SCREEN);
}
}
_nc_unlock_global(curses);
@@ -329,9 +342,14 @@ NCURSES_SP_NAME(_nc_setupscreen) (
T(("_nc_alloc_screen_sp %p", (void *) sp));
*spp = sp;
}
- if (!sp
- || ((sp->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0)
- || ((sp->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) {
+ if (sp == NULL) {
+ ReturnScreenError();
+ }
+ if ((sp->_acs_map = typeCalloc(chtype, ACS_LEN)) == NULL) {
+ ReturnScreenError();
+ }
+ if ((sp->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == NULL) {
+ free(sp->_acs_map);
ReturnScreenError();
}
@@ -412,7 +430,6 @@ NCURSES_SP_NAME(_nc_setupscreen) (
fflush(output);
_setmode(fileno(output), _O_BINARY);
#endif
- NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_ARGx output, TRUE);
sp->_lines = (NCURSES_SIZE_T) slines;
sp->_lines_avail = (NCURSES_SIZE_T) slines;
sp->_columns = (NCURSES_SIZE_T) scolumns;
@@ -495,7 +512,7 @@ NCURSES_SP_NAME(_nc_setupscreen) (
p = extract_fgbg(p, &(sp->_default_fg));
p = extract_fgbg(p, &(sp->_default_bg));
if (*p) /* assume rxvt was compiled with xpm support */
- p = extract_fgbg(p, &(sp->_default_bg));
+ extract_fgbg(p, &(sp->_default_bg));
TR(TRACE_CHARPUT | TRACE_MOVE, ("decoded fg=%d, bg=%d",
sp->_default_fg, sp->_default_bg));
if (sp->_default_fg >= MaxColors) {
@@ -692,6 +709,9 @@ NCURSES_SP_NAME(_nc_setupscreen) (
formats (4-4 or 3-2-3) for which there may be some hardware
support. */
if (rop->hook == _nc_slk_initialize) {
+ if (!TerminalOf(sp)) {
+ continue;
+ }
if (!(NumLabels <= 0 || !SLK_STDFMT(slk_format))) {
continue;
}
@@ -731,6 +751,7 @@ NCURSES_SP_NAME(_nc_setupscreen) (
}
T(("creating stdscr"));
+ (void) bottom_stolen;
assert((sp->_lines_avail + sp->_topstolen + bottom_stolen) == slines);
if ((StdScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
sp->_lines_avail,
@@ -812,10 +833,13 @@ NCURSES_EXPORT(int)
_nc_ripoffline(int line, int (*init) (WINDOW *, int))
{
int rc;
+
+ _nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(_nc_ripoffline) (CURRENT_SCREEN_PRE, line, init);
_nc_unlock_global(prescreen);
+
return rc;
}
#endif
@@ -836,10 +860,13 @@ NCURSES_EXPORT(int)
ripoffline(int line, int (*init) (WINDOW *, int))
{
int rc;
+
+ _nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(ripoffline) (CURRENT_SCREEN_PRE, line, init);
_nc_unlock_global(prescreen);
+
return rc;
}
#endif
diff --git a/ncurses/base/lib_slk.c b/ncurses/base/lib_slk.c
index f4b3ce6dbf0a..47e57e0bc5bd 100644
--- a/ncurses/base/lib_slk.c
+++ b/ncurses/base/lib_slk.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2010,2011 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -48,7 +48,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_slk.c,v 1.49 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_slk.c,v 1.50 2022/08/20 18:29:22 tom Exp $")
#ifdef USE_TERM_DRIVER
#define NumLabels InfoOf(SP_PARM).numlabels
@@ -187,8 +187,10 @@ _nc_slk_initialize(WINDOW *stwin, int cols)
|| SP_PARM->_slk->labcnt <= 0
|| (SP_PARM->_slk->ent = typeCalloc(slk_ent,
(size_t) SP_PARM->_slk->labcnt))
- == NULL)
+ == NULL) {
+ free(SP_PARM->_slk->ent);
returnCode(slk_failed(NCURSES_SP_ARG));
+ }
max_length = (size_t) SP_PARM->_slk->maxlen;
for (i = 0; i < SP_PARM->_slk->labcnt; i++) {
diff --git a/ncurses/base/lib_slkinit.c b/ncurses/base/lib_slkinit.c
index e1602abc9f18..318077fc96c1 100644
--- a/ncurses/base/lib_slkinit.c
+++ b/ncurses/base/lib_slkinit.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -41,7 +41,7 @@
*/
#include <curses.priv.h>
-MODULE_ID("$Id: lib_slkinit.c,v 1.15 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_slkinit.c,v 1.16 2022/07/09 18:58:58 tom Exp $")
#ifdef USE_SP_RIPOFF
#define SoftkeyFormat SP_PARM->slk_format
@@ -77,10 +77,13 @@ NCURSES_EXPORT(int)
slk_init(int format)
{
int rc;
+
+ _nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(slk_init) (CURRENT_SCREEN_PRE, format);
_nc_unlock_global(prescreen);
+
return rc;
}
#endif
diff --git a/ncurses/base/lib_slkrefr.c b/ncurses/base/lib_slkrefr.c
index c6bf9d2e06f6..7a40624b1276 100644
--- a/ncurses/base/lib_slkrefr.c
+++ b/ncurses/base/lib_slkrefr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2013,2014 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -44,7 +44,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_slkrefr.c,v 1.31 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_slkrefr.c,v 1.32 2021/09/04 10:54:35 tom Exp $")
#ifdef USE_TERM_DRIVER
#define NumLabels InfoOf(SP_PARM).numlabels
@@ -113,7 +113,7 @@ slk_intern_refresh(SCREEN *sp)
wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
(void) wattrset(slk->win, (int) AttrOf(slk->attr));
waddstr(slk->win, slk->ent[i].form_text);
- /* if we simulate SLK's, it's looking much more
+ /* if we simulate SLK's, it is looking much more
natural to use the current ATTRIBUTE also
for the label window */
(void) wattrset(slk->win, (int) WINDOW_ATTRS(StdScreen(sp)));
diff --git a/ncurses/base/lib_wattron.c b/ncurses/base/lib_wattron.c
index c589f10473cb..906021d3b4cf 100644
--- a/ncurses/base/lib_wattron.c
+++ b/ncurses/base/lib_wattron.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2010 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,7 +43,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_wattron.c,v 1.12 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_wattron.c,v 1.13 2022/04/15 22:34:38 tom Exp $")
NCURSES_EXPORT(int)
wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
@@ -55,8 +55,10 @@ wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
GET_WINDOW_PAIR(win)));
if_EXT_COLORS({
- if (at & A_COLOR)
+ if (at & A_COLOR) {
win->_color = PairNumber(at);
+ set_extended_pair(opts, win->_color);
+ }
});
toggle_attr_on(WINDOW_ATTRS(win), at);
returnCode(OK);
diff --git a/ncurses/base/lib_window.c b/ncurses/base/lib_window.c
index 7222bfe5c656..5323fbf0348e 100644
--- a/ncurses/base/lib_window.c
+++ b/ncurses/base/lib_window.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2010,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -40,7 +40,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_window.c,v 1.31 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_window.c,v 1.32 2021/10/23 23:06:24 tom Exp $")
NCURSES_EXPORT(void)
_nc_synchook(WINDOW *win)
@@ -130,7 +130,7 @@ wsyncdown(WINDOW *win)
{
T((T_CALLED("wsyncdown(%p)"), (void *) win));
- if (win && win->_parent) {
+ if (win != NULL && win->_parent != NULL) {
WINDOW *pp = win->_parent;
int y;
@@ -187,7 +187,7 @@ dupwin(WINDOW *win)
SCREEN *sp = _nc_screen_of(win);
#endif
_nc_lock_global(curses);
- if (win->_flags & _ISPAD) {
+ if (IS_PAD(win)) {
nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
win->_maxy + 1,
win->_maxx + 1);
@@ -238,7 +238,7 @@ dupwin(WINDOW *win)
nwin->_regtop = win->_regtop;
nwin->_regbottom = win->_regbottom;
- if (win->_flags & _ISPAD)
+ if (IS_PAD(win))
nwin->_pad = win->_pad;
linesize = (unsigned) (win->_maxx + 1) * sizeof(NCURSES_CH_T);
diff --git a/ncurses/base/new_pair.c b/ncurses/base/new_pair.c
index c04f4acbb95d..70866c636812 100644
--- a/ncurses/base/new_pair.c
+++ b/ncurses/base/new_pair.c
@@ -61,7 +61,7 @@
#endif
-MODULE_ID("$Id: new_pair.c,v 1.21 2021/02/14 00:17:09 tom Exp $")
+MODULE_ID("$Id: new_pair.c,v 1.23 2021/08/16 22:11:26 tom Exp $")
#if NCURSES_EXT_COLORS
@@ -106,7 +106,7 @@ dumpit(SCREEN *sp, int pair, const char *tag)
size_t have = sizeof(bigbuf);
_nc_STRCPY(p, tag, have);
- for (n = 0; n < sp->_pair_limit; ++n) {
+ for (n = 0; n < sp->_pair_alloc; ++n) {
if (list[n].mode != cpFREE) {
p += strlen(p);
if ((size_t) (p - bigbuf) + 50 > have)
@@ -297,7 +297,7 @@ NCURSES_SP_NAME(alloc_pair) (NCURSES_SP_DCLx int fg, int bg)
found = TRUE;
}
}
- if (!found) {
+ if (!found && SP_PARM->_color_pairs != NULL) {
for (pair = 1; pair <= hint; pair++) {
if (SP_PARM->_color_pairs[pair].mode == cpFREE) {
T(("found gap %d", pair));
diff --git a/ncurses/base/resizeterm.c b/ncurses/base/resizeterm.c
index 9b04287cb56f..1a2ddb365a58 100644
--- a/ncurses/base/resizeterm.c
+++ b/ncurses/base/resizeterm.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020-2021,2024 Thomas E. Dickey *
* Copyright 1998-2015,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -46,7 +46,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: resizeterm.c,v 1.50 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: resizeterm.c,v 1.53 2024/04/20 21:54:14 tom Exp $")
/*
* If we're trying to be reentrant, do not want any local statics.
@@ -210,7 +210,7 @@ parent_depth(WINDOW *cmp)
}
/*
- * FIXME: must adjust position so it's within the parent!
+ * FIXME: must adjust position so it is within the parent!
*/
static int
adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
@@ -293,7 +293,7 @@ decrease_size(NCURSES_SP_DCLx int ToLines, int ToCols, int stolen EXTRA_DCLS)
for (each_window(SP_PARM, wp)) {
WINDOW *win = &(wp->win);
- if (!(win->_flags & _ISPAD)) {
+ if (!IS_PAD(win)) {
if (child_depth(win) == depth) {
found = TRUE;
if (adjust_window(win, ToLines, ToCols,
@@ -328,7 +328,7 @@ increase_size(NCURSES_SP_DCLx int ToLines, int ToCols, int stolen EXTRA_DCLS)
for (each_window(SP_PARM, wp)) {
WINDOW *win = &(wp->win);
- if (!(win->_flags & _ISPAD)) {
+ if (!IS_PAD(win)) {
if (parent_depth(win) == depth) {
found = TRUE;
if (adjust_window(win, ToLines, ToCols,
@@ -409,8 +409,8 @@ NCURSES_SP_NAME(resize_term) (NCURSES_SP_DCLx int ToLines, int ToCols)
#ifdef USE_TERM_DRIVER
CallDriver_2(SP_PARM, td_setsize, ToLines, ToCols);
#else
- lines = (NCURSES_SIZE_T) ToLines;
- columns = (NCURSES_SIZE_T) ToCols;
+ lines = (NCURSES_INT2) ToLines;
+ columns = (NCURSES_INT2) ToCols;
#endif
SP_PARM->_lines_avail = (NCURSES_SIZE_T) (ToLines - was_stolen);
diff --git a/ncurses/base/safe_sprintf.c b/ncurses/base/safe_sprintf.c
index 1868c009660c..8816e58c2ca8 100644
--- a/ncurses/base/safe_sprintf.c
+++ b/ncurses/base/safe_sprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 2018-2021,2023 Thomas E. Dickey *
* Copyright 1998-2012,2013 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -34,7 +34,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: safe_sprintf.c,v 1.33 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: safe_sprintf.c,v 1.37 2023/09/30 10:42:42 tom Exp $")
#if USE_SAFE_SPRINTF
@@ -223,9 +223,9 @@ NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_DCLx
const char *fmt,
va_list ap)
{
- char *result = 0;
+ char *result = NULL;
- if (SP_PARM != 0 && fmt != 0) {
+ if (SP_PARM != NULL && fmt != NULL) {
#if USE_SAFE_SPRINTF
va_list ap2;
int len;
@@ -238,7 +238,7 @@ NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_DCLx
my_length = (size_t) (2 * (len + 1));
my_buffer = typeRealloc(char, my_length, my_buffer);
}
- if (my_buffer != 0) {
+ if (my_buffer != NULL) {
*my_buffer = '\0';
if (len >= 0) {
vsprintf(my_buffer, fmt, ap);
@@ -255,21 +255,37 @@ NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_DCLx
if (screen_columns(SP_PARM) > MyCols)
MyCols = screen_columns(SP_PARM);
my_length = (size_t) (MyRows * (MyCols + 1)) + 1;
+ if (my_length < 80)
+ my_length = 80;
my_buffer = typeRealloc(char, my_length, my_buffer);
}
- if (my_buffer != 0) {
+ if (my_buffer != NULL) {
# if HAVE_VSNPRINTF
- vsnprintf(my_buffer, my_length, fmt, ap); /* SUSv2, 1997 */
+ /* SUSv2, 1997 */
+ int used;
+
+ do {
+ va_list ap2;
+
+ begin_va_copy(ap2, ap);
+ used = vsnprintf(my_buffer, my_length, fmt, ap2);
+ end_va_copy(ap2);
+ if (used < (int) my_length)
+ break;
+ my_length = (size_t) ((3 * used) / 2);
+ my_buffer = typeRealloc(char, my_length, my_buffer);
+ } while (my_buffer != NULL);
# else
- vsprintf(my_buffer, fmt, ap); /* ISO/ANSI C, 1989 */
+ /* ISO/ANSI C, 1989 */
+ vsprintf(my_buffer, fmt, ap);
# endif
result = my_buffer;
}
#endif
- } else if (my_buffer != 0) { /* see _nc_freeall() */
+ } else if (my_buffer != NULL) { /* see _nc_freeall() */
free(my_buffer);
- my_buffer = 0;
+ my_buffer = NULL;
my_length = 0;
}
return result;
diff --git a/ncurses/base/tries.c b/ncurses/base/tries.c
index 0f309c213c45..0f8c0516e88f 100644
--- a/ncurses/base/tries.c
+++ b/ncurses/base/tries.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2009,2010 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -39,8 +39,9 @@
*/
#include <curses.priv.h>
+#include <tic.h>
-MODULE_ID("$Id: tries.c,v 1.31 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: tries.c,v 1.32 2023/06/24 15:36:23 tom Exp $")
/*
* Expand a keycode into the string that it corresponds to, returning null if
@@ -124,7 +125,7 @@ _nc_remove_string(TRIES ** tree, const char *string)
{
T((T_CALLED("_nc_remove_string(%p,%s)"), (void *) tree, _nc_visbuf(string)));
- if (string == 0 || *string == 0)
+ if (!VALID_STRING(string) || *string == 0)
returnCode(FALSE);
while (*tree != 0) {
diff --git a/ncurses/base/vsscanf.c b/ncurses/base/vsscanf.c
index ef524250c36f..40ee8bb1d876 100644
--- a/ncurses/base/vsscanf.c
+++ b/ncurses/base/vsscanf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2004,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -39,15 +39,12 @@
#if !HAVE_VSSCANF
-MODULE_ID("$Id: vsscanf.c,v 1.21 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: vsscanf.c,v 1.22 2023/09/23 18:48:57 tom Exp $")
#if !(HAVE_VFSCANF || HAVE__DOSCAN)
#include <ctype.h>
-#define L_SQUARE '['
-#define R_SQUARE ']'
-
typedef enum {
cUnknown
,cError /* anything that isn't ANSI */
@@ -243,7 +240,7 @@ vsscanf(const char *str, const char *format, va_list ap)
case sPercent:
if (format[n] == '%') {
state = sUnknown;
- } else if (format[n] == L_SQUARE) {
+ } else if (format[n] == L_BLOCK) {
state = sLeft;
} else {
state = sNormal;
@@ -258,7 +255,7 @@ vsscanf(const char *str, const char *format, va_list ap)
}
break;
case sRange:
- if (format[n] == R_SQUARE) {
+ if (format[n] == R_BLOCK) {
state = sFinal;
chunk = cRange;
}
diff --git a/ncurses/base/wresize.c b/ncurses/base/wresize.c
index 30718b8878fd..6d5589e2794e 100644
--- a/ncurses/base/wresize.c
+++ b/ncurses/base/wresize.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019,2020 Thomas E. Dickey *
+ * Copyright 2019-2021,2023 Thomas E. Dickey *
* Copyright 1998-2010,2011 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -34,7 +34,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: wresize.c,v 1.41 2020/04/18 21:01:00 tom Exp $")
+MODULE_ID("$Id: wresize.c,v 1.43 2023/10/21 11:13:03 tom Exp $")
static int
cleanup_lines(struct ldat *data, int length)
@@ -55,7 +55,7 @@ repair_subwindows(WINDOW *cmp)
WINDOWLIST *wp;
struct ldat *pline = cmp->_line;
int row;
-#ifdef USE_SP_WINDOWLIST
+#if NCURSES_SP_FUNCS && defined(USE_SP_WINDOWLIST)
SCREEN *sp = _nc_screen_of(cmp);
#endif
@@ -135,7 +135,7 @@ wresize(WINDOW *win, int ToLines, int ToCols)
&& ToCols == size_x)
returnCode(OK);
- if ((win->_flags & _SUBWIN)) {
+ if (IS_SUBWIN(win)) {
/*
* Check if the new limits will fit into the parent window's size. If
* not, do not resize. We could adjust the location of the subwindow,
@@ -169,7 +169,7 @@ wresize(WINDOW *win, int ToLines, int ToCols)
int end = ToCols;
NCURSES_CH_T *s;
- if (!(win->_flags & _SUBWIN)) {
+ if (!IS_SUBWIN(win)) {
if (row <= size_y) {
if (ToCols != size_x) {
s = typeMalloc(NCURSES_CH_T, (unsigned) ToCols + 1);