diff options
Diffstat (limited to 'ncurses/base')
-rwxr-xr-x | ncurses/base/MKlib_gen.sh | 35 | ||||
-rw-r--r-- | ncurses/base/keyok.c | 6 | ||||
-rw-r--r-- | ncurses/base/lib_addch.c | 20 | ||||
-rw-r--r-- | ncurses/base/lib_addstr.c | 10 | ||||
-rw-r--r-- | ncurses/base/lib_bkgd.c | 76 | ||||
-rw-r--r-- | ncurses/base/lib_color.c | 115 | ||||
-rw-r--r-- | ncurses/base/lib_dft_fgbg.c | 8 | ||||
-rw-r--r-- | ncurses/base/lib_driver.c | 4 | ||||
-rw-r--r-- | ncurses/base/lib_freeall.c | 6 | ||||
-rw-r--r-- | ncurses/base/lib_getch.c | 78 | ||||
-rw-r--r-- | ncurses/base/lib_getstr.c | 10 | ||||
-rw-r--r-- | ncurses/base/lib_initscr.c | 9 | ||||
-rw-r--r-- | ncurses/base/lib_instr.c | 6 | ||||
-rw-r--r-- | ncurses/base/lib_mouse.c | 75 | ||||
-rw-r--r-- | ncurses/base/lib_newterm.c | 13 | ||||
-rw-r--r-- | ncurses/base/lib_pad.c | 6 | ||||
-rw-r--r-- | ncurses/base/lib_screen.c | 57 | ||||
-rw-r--r-- | ncurses/base/lib_set_term.c | 50 | ||||
-rw-r--r-- | ncurses/base/lib_slkrefr.c | 6 | ||||
-rw-r--r-- | ncurses/base/new_pair.c | 31 | ||||
-rw-r--r-- | ncurses/base/resizeterm.c | 6 | ||||
-rw-r--r-- | ncurses/base/safe_sprintf.c | 29 | ||||
-rw-r--r-- | ncurses/base/wresize.c | 12 |
23 files changed, 459 insertions, 209 deletions
diff --git a/ncurses/base/MKlib_gen.sh b/ncurses/base/MKlib_gen.sh index 5a3770e..9dc0855 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.63 2020/02/02 23:34:34 tom Exp $) +# ($Id: MKlib_gen.sh,v 1.71 2021/09/26 22:08:53 tom Exp $) # ############################################################################## -# Copyright 2018,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 # @@ -69,16 +69,25 @@ 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. -PRG=`echo "$1" | $AWK '{ sub(/^[ ]*/,""); sub(/[ ].*$/, ""); print; }' || exit 0` -FSF=`"$PRG" --version 2>/dev/null || exit 0 | fgrep "Free Software Foundation" | head -n 1` +# +# 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` ALL=`"$PRG" -dumpversion 2>/dev/null || exit 0` -ONE=`echo "$ALL" | sed -e 's/\..*$//'` +ONE=`echo "$ALL" | sed -e 's/[^0-9].*$//'` if test -n "$FSF" && test -n "$ALL" && test -n "$ONE" ; then - if test $ONE -ge 5 ; then + if test "$ONE" -ge 5 ; then echo ".. adding -P option to work around $PRG $ALL" >&2 preprocessor="$preprocessor -P" fi @@ -96,7 +105,6 @@ trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0 1 2 3 15 ALL=$USE if test "$USE" = implemented ; then - CALL="call_" cat >$ED1 <<EOF1 /^extern.*implemented/{ h @@ -119,7 +127,6 @@ if test "$USE" = implemented ; then } EOF1 else - CALL="" cat >$ED1 <<EOF1 /^extern.*${ALL}/{ h @@ -178,7 +185,7 @@ EOF3 if test "$USE" = generated ; then cat >$ED4 <<EOF - s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) (\2) (\3)/ + s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) \2 (\3)/ /attr_[sg]et.* z)/s,z),z GCC_UNUSED), EOF else @@ -433,6 +440,7 @@ BEGIN { print "#include <ncurses_cfg.h>" print "" print "#undef NCURSES_NOMACROS /* _this_ file uses macros */" + print "#define NCURSES_NOMACROS 1" print "" print "#include <curses.priv.h>" print "" @@ -462,8 +470,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); @@ -495,7 +504,7 @@ EOF sed -n -f $ED1 \ | sed -e 's/NCURSES_EXPORT(\(.*\)) \(.*\) (\(.*\))/\1 \2(\3)/' \ | sed -f $ED2 \ -| $AWK -f $AW1 using=$USE \ +| "$AWK" -f $AW1 using="$USE" \ | sed \ -e 's/ [ ]*$//g' \ -e 's/^\([a-zA-Z_][a-zA-Z_]*[ *]*\)/\1 gen_/' \ @@ -507,7 +516,7 @@ $preprocessor $TMP 2>/dev/null \ -e 's/ / /g' \ -e 's/^ //' \ -e 's/_Bool/NCURSES_BOOL/g' \ -| $AWK -f $AW2 \ +| "$AWK" -f $AW2 \ | sed -f $ED3 \ | sed \ -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \ diff --git a/ncurses/base/keyok.c b/ncurses/base/keyok.c index 8e0b962..945228a 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 604b13b..a144328 100644 --- a/ncurses/base/lib_addch.c +++ b/ncurses/base/lib_addch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-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 * @@ -37,7 +37,7 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: lib_addch.c,v 1.134 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_addch.c,v 1.138 2021/06/17 21:11:08 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). */ @@ -208,6 +208,20 @@ _nc_build_wch(WINDOW *win, ARG_CH_T ch) WINDOW_EXT(win, addch_x) = x; WINDOW_EXT(win, addch_y) = y; + /* + * If the background character is a wide-character, that may interfere with + * processing multibyte characters in this function. + */ + if (!is8bits(CharOf(CHDEREF(ch)))) { + if (WINDOW_EXT(win, addch_used) != 0) { + /* discard the incomplete multibyte character */ + WINDOW_EXT(win, addch_used) = 0; + TR(TRACE_VIRTPUT, + ("Alert discarded incomplete multibyte")); + } + return 1; + } + init_mb(state); buffer[WINDOW_EXT(win, addch_used)] = (char) CharOf(CHDEREF(ch)); WINDOW_EXT(win, addch_used) += 1; diff --git a/ncurses/base/lib_addstr.c b/ncurses/base/lib_addstr.c index 19ebfcd..a1e8829 100644 --- a/ncurses/base/lib_addstr.c +++ b/ncurses/base/lib_addstr.c @@ -45,7 +45,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_addstr.c,v 1.56 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_addstr.c,v 1.57 2020/12/05 20:06:19 tom Exp $") NCURSES_EXPORT(int) waddnstr(WINDOW *win, const char *astr, int n) @@ -60,10 +60,10 @@ waddnstr(WINDOW *win, const char *astr, int n) ("... current %s", _traceattr(WINDOW_ATTRS(win)))); code = OK; if (n < 0) - n = (int) strlen(astr); + n = INT_MAX; TR(TRACE_VIRTPUT, ("str is not null, length = %d", n)); - while ((n-- > 0) && (*str != '\0')) { + while ((*str != '\0') && (n-- > 0)) { NCURSES_CH_T ch; TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str))); SetChar(ch, UChar(*str++), A_NORMAL); @@ -232,10 +232,10 @@ waddnwstr(WINDOW *win, const wchar_t *str, int n) ("... current %s", _traceattr(WINDOW_ATTRS(win)))); code = OK; if (n < 0) - n = (int) wcslen(str); + n = INT_MAX; TR(TRACE_VIRTPUT, ("str is not null, length = %d", n)); - while ((n-- > 0) && (*str != L('\0'))) { + while ((*str != L('\0')) && (n-- > 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 2030030..4f99080 100644 --- a/ncurses/base/lib_bkgd.c +++ b/ncurses/base/lib_bkgd.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2021 Thomas E. Dickey * * Copyright 1998-2014,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -37,7 +37,9 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_bkgd.c,v 1.54 2020/02/02 23:34:34 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); /* * Set the window's background information. @@ -49,7 +51,7 @@ static NCURSES_INLINE void #endif wbkgrndset(WINDOW *win, const ARG_CH_T ch) { - T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracech_t(ch))); + T((T_CALLED("wbkgrndset(%p,%s)"), (void *) win, _tracech_t(ch))); if (win) { attr_t off = AttrOf(win->_nc_bkgd); @@ -62,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); @@ -103,26 +105,36 @@ NCURSES_EXPORT(void) wbkgdset(WINDOW *win, chtype ch) { NCURSES_CH_T wch; + T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracechtype(ch))); SetChar2(wch, ch); wbkgrndset(win, CHREF(wch)); + returnVoid; } /* * Set the window's background information and apply it to each cell. */ -#if USE_WIDEC_SUPPORT -NCURSES_EXPORT(int) -#else static NCURSES_INLINE int -#undef wbkgrnd -#endif -wbkgrnd(WINDOW *win, const ARG_CH_T ch) +_nc_background(WINDOW *win, const ARG_CH_T ch, bool narrow) { #undef SP_PARM #define SP_PARM SP /* to use Charable() */ int code = ERR; - T((T_CALLED("wbkgd(%p,%s)"), (void *) win, _tracech_t(ch))); +#if USE_WIDEC_SUPPORT + T((T_CALLED("%s(%p,%s)"), + narrow ? "wbkgd" : "wbkgrnd", + (void *) win, + _tracecchar_t(ch))); +#define TraceChar(c) _tracecchar_t2(1, &(c)) +#else + T((T_CALLED("%s(%p,%s)"), + "wbkgd", + (void *) win, + _tracech_t(ch))); + (void) narrow; +#define TraceChar(c) _tracechar(CharOf(c)) +#endif if (SP == 0) { ; @@ -143,6 +155,14 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch) SetPair(new_bkgd, 0); } + /* avoid setting background-character to a null */ + if (CharOf(new_bkgd) == 0) { + NCURSES_CH_T tmp_bkgd = blank; + SetAttr(tmp_bkgd, AttrOf(new_bkgd)); + SetPair(tmp_bkgd, GetPair(new_bkgd)); + new_bkgd = tmp_bkgd; + } + memset(&old_bkgd, 0, sizeof(old_bkgd)); (void) wgetbkgrnd(win, &old_bkgd); @@ -160,7 +180,7 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch) old_pair = 0; } T(("... old background char %s, attr %s, pair %d", - _tracechar(CharOf(old_char)), _traceattr(old_attr), old_pair)); + TraceChar(old_char), _traceattr(old_attr), old_pair)); new_char = new_bkgd; RemAttr(new_char, ~A_CHARTEXT); @@ -168,14 +188,18 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch) new_pair = GetPair(new_bkgd); /* SVr4 limits background character to printable 7-bits */ - if (!Charable(new_bkgd)) { + if ( +#if USE_WIDEC_SUPPORT + narrow && +#endif + !Charable(new_bkgd)) { new_char = old_char; } if (!(new_attr & A_COLOR)) { new_pair = 0; } T(("... new background char %s, attr %s, pair %d", - _tracechar(CharOf(new_char)), _traceattr(new_attr), new_pair)); + TraceChar(new_char), _traceattr(new_attr), new_pair)); (void) wbkgrndset(win, CHREF(new_bkgd)); @@ -196,7 +220,19 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch) attr_t tmp_attr = AttrOf(*cp); if (CharEq(*cp, old_bkgd)) { - SetChar2(*cp, CharOf(new_char)); +#if USE_WIDEC_SUPPORT + if (!narrow) { + if (Charable(new_bkgd)) { + SetChar2(*cp, CharOf(new_char)); + } else { + SetChar(*cp, L' ', AttrOf(new_char)); + } + memcpy(cp->chars, + new_char.chars, + CCHARW_MAX * sizeof(cp->chars[0])); + } else +#endif + SetChar2(*cp, CharOf(new_char)); } if (tmp_pair != 0) { if (tmp_pair == old_pair) { @@ -220,10 +256,18 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch) returnCode(code); } +#if USE_WIDEC_SUPPORT +NCURSES_EXPORT(int) +wbkgrnd(WINDOW *win, const ARG_CH_T ch) +{ + return _nc_background(win, ch, FALSE); +} +#endif + NCURSES_EXPORT(int) wbkgd(WINDOW *win, chtype ch) { NCURSES_CH_T wch; SetChar2(wch, ch); - return wbkgrnd(win, CHREF(wch)); + return _nc_background(win, CHREF(wch), TRUE); } diff --git a/ncurses/base/lib_color.c b/ncurses/base/lib_color.c index 376ad4f..e4dc79b 100644 --- a/ncurses/base/lib_color.c +++ b/ncurses/base/lib_color.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 * @@ -49,7 +49,7 @@ #define CUR SP_TERMTYPE #endif -MODULE_ID("$Id: lib_color.c,v 1.143 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_color.c,v 1.148 2021/10/02 22:55:48 tom Exp $") #ifdef USE_TERM_DRIVER #define CanChange InfoOf(SP_PARM).canchange @@ -140,7 +140,6 @@ NCURSES_EXPORT_VAR(const color_t*) _nc_hls_palette = hls_palette; #endif /* *INDENT-ON* */ - #if NCURSES_EXT_FUNCS /* * These are called from _nc_do_color(), which in turn is called from @@ -190,12 +189,12 @@ set_background_color(NCURSES_SP_DCLx int bg, NCURSES_SP_OUTC outc) if (set_a_background) { TPUTS_TRACE("set_a_background"); NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx - TPARM_1(set_a_background, bg), + TIPARM_1(set_a_background, bg), 1, outc); } else { TPUTS_TRACE("set_background"); NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx - TPARM_1(set_background, toggled_colors(bg)), + TIPARM_1(set_background, toggled_colors(bg)), 1, outc); } #endif @@ -210,12 +209,12 @@ set_foreground_color(NCURSES_SP_DCLx int fg, NCURSES_SP_OUTC outc) if (set_a_foreground) { TPUTS_TRACE("set_a_foreground"); NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx - TPARM_1(set_a_foreground, fg), + TIPARM_1(set_a_foreground, fg), 1, outc); } else { TPUTS_TRACE("set_foreground"); NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx - TPARM_1(set_foreground, toggled_colors(fg)), + TIPARM_1(set_foreground, toggled_colors(fg)), 1, outc); } #endif @@ -253,20 +252,21 @@ init_direct_colors(NCURSES_SP_DCL0) { static NCURSES_CONST char name[] = "RGB"; - int n; - const char *s; - int width; rgb_bits_t *result = &(SP_PARM->_direct_color); result->value = 0; if (COLORS >= 8) { + int n; + const char *s; + int width; + /* find the number of bits needed for the maximum color value */ for (width = 0; (1 << width) - 1 < (COLORS - 1); ++width) { ; } - if ((n = tigetflag(name)) > 0) { + if (tigetflag(name) > 0) { n = (width + 2) / 3; result->bits.red = UChar(n); result->bits.green = UChar(n); @@ -361,7 +361,6 @@ NCURSES_EXPORT(int) NCURSES_SP_NAME(start_color) (NCURSES_SP_DCL0) { int result = ERR; - int maxpairs = 0, maxcolors = 0; T((T_CALLED("start_color(%p)"), (void *) SP_PARM)); @@ -370,8 +369,8 @@ NCURSES_SP_NAME(start_color) (NCURSES_SP_DCL0) } else if (SP_PARM->_coloron) { result = OK; } else { - maxpairs = MaxPairs; - maxcolors = MaxColors; + int maxpairs = MaxPairs; + int maxcolors = MaxColors; if (reset_color_pair(NCURSES_SP_ARG) != TRUE) { set_foreground_color(NCURSES_SP_ARGx default_fg(NCURSES_SP_ARG), @@ -672,14 +671,14 @@ _nc_init_pair(SCREEN *sp, int pair, int f, int b) (int) tp[b].red, (int) tp[b].green, (int) tp[b].blue)); NCURSES_PUTP2("initialize_pair", - TPARM_7(initialize_pair, - pair, - (int) tp[f].red, - (int) tp[f].green, - (int) tp[f].blue, - (int) tp[b].red, - (int) tp[b].green, - (int) tp[b].blue)); + TIPARM_7(initialize_pair, + pair, + (int) tp[f].red, + (int) tp[f].green, + (int) tp[f].blue, + (int) tp[b].red, + (int) tp[b].green, + (int) tp[b].blue)); } #endif @@ -746,7 +745,7 @@ _nc_init_color(SCREEN *sp, int color, int r, int g, int b) CallDriver_4(sp, td_initcolor, color, r, g, b); #else NCURSES_PUTP2("initialize_color", - TPARM_4(initialize_color, color, r, g, b)); + TIPARM_4(initialize_color, color, r, g, b)); #endif sp->_color_defs = max(color + 1, sp->_color_defs); @@ -832,7 +831,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, @@ -841,52 +839,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); } @@ -1004,7 +1007,7 @@ NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_DCLx if (set_color_pair) { TPUTS_TRACE("set_color_pair"); NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx - TPARM_1(set_color_pair, pair), + TIPARM_1(set_color_pair, pair), 1, outc); return; } else if (SP_PARM != 0) { diff --git a/ncurses/base/lib_dft_fgbg.c b/ncurses/base/lib_dft_fgbg.c index 95dc0c2..4dd43bb 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_driver.c b/ncurses/base/lib_driver.c index 5467607..c53802f 100644 --- a/ncurses/base/lib_driver.c +++ b/ncurses/base/lib_driver.c @@ -34,8 +34,9 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_driver.c,v 1.8 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_driver.c,v 1.9 2020/08/29 19:53:35 tom Exp $") +#ifndef EXP_WIN32_DRIVER typedef struct DriverEntry { const char *name; TERM_DRIVER *driver; @@ -77,6 +78,7 @@ _nc_get_driver(TERMINAL_CONTROL_BLOCK * TCB, const char *name, int *errret) } returnCode(code); } +#endif /* !EXP_WIN32_DRIVER */ NCURSES_EXPORT(int) NCURSES_SP_NAME(has_key) (SCREEN *sp, int keycode) diff --git a/ncurses/base/lib_freeall.c b/ncurses/base/lib_freeall.c index 9133d08..c027151 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.74 2021/03/20 22:57:53 tom Exp $") /* * Free all ncurses data. This is used for testing only (there's no practical @@ -171,8 +171,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 bf2115d..bdb8a04 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-2020,2021 Thomas E. Dickey * * Copyright 1998-2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -41,9 +41,10 @@ ** */ +#define NEED_KEY_EVENT #include <curses.priv.h> -MODULE_ID("$Id: lib_getch.c,v 1.139 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_getch.c,v 1.142 2021/09/04 10:52:55 tom Exp $") #include <fifo_defs.h> @@ -134,7 +135,7 @@ _nc_use_meta(WINDOW *win) } #ifdef USE_TERM_DRIVER -# ifdef _WIN32 +# if defined(_NC_WINDOWS) && !defined(EXP_WIN32_DRIVER) static HANDLE _nc_get_handle(int fd) { @@ -155,7 +156,14 @@ check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl)) #ifdef USE_TERM_DRIVER TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp); rc = TCBOf(sp)->drv->td_testmouse(TCBOf(sp), delay EVENTLIST_2nd(evl)); -# ifdef _WIN32 +# if defined(EXP_WIN32_DRIVER) + /* if we emulate terminfo on console, we have to use the console routine */ + if (IsTermInfoOnConsole(sp)) { + rc = _nc_console_testmouse(sp, + _nc_console_handle(sp->_ifd), + delay EVENTLIST_2nd(evl)); + } else +# elif defined(_NC_WINDOWS) /* if we emulate terminfo on console, we have to use the console routine */ if (IsTermInfoOnConsole(sp)) { HANDLE fd = _nc_get_handle(sp->_ifd); @@ -163,29 +171,36 @@ check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl)) } else # endif rc = TCB->drv->td_testmouse(TCB, delay EVENTLIST_2nd(evl)); -#else -#if USE_SYSMOUSE +#else /* !USE_TERM_DRIVER */ +# if USE_SYSMOUSE if ((sp->_mouse_type == M_SYSMOUSE) && (sp->_sysmouse_head < sp->_sysmouse_tail)) { rc = TW_MOUSE; } else -#endif +# endif { +# if defined(EXP_WIN32_DRIVER) + rc = _nc_console_testmouse(sp, + _nc_console_handle(sp->_ifd), + delay + EVENTLIST_2nd(evl)); +# else rc = _nc_timed_wait(sp, TWAIT_MASK, delay, (int *) 0 EVENTLIST_2nd(evl)); -#if USE_SYSMOUSE +# endif +# if USE_SYSMOUSE if ((sp->_mouse_type == M_SYSMOUSE) && (sp->_sysmouse_head < sp->_sysmouse_tail) && (rc == 0) && (errno == EINTR)) { rc |= TW_MOUSE; } -#endif +# endif } -#endif +#endif /* USE_TERM_DRIVER */ return rc; } @@ -290,31 +305,54 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl)) } else #endif { /* Can block... */ -#ifdef USE_TERM_DRIVER +#if defined(USE_TERM_DRIVER) int buf; -#ifdef _WIN32 +# 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 + n = _nc_console_read(sp, + _nc_console_handle(sp->_ifd), + &buf); +# if USE_PTHREADS_EINTR + _nc_globals.read_thread = 0; +# endif + } else +# elif defined(_NC_WINDOWS) if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && sp->_cbreak) n = _nc_mingw_console_read(sp, _nc_get_handle(sp->_ifd), &buf); else -#endif +# endif /* EXP_WIN32_DRIVER */ n = CallDriver_1(sp, td_read, &buf); ch = buf; -#else +#else /* !USE_TERM_DRIVER */ +#if defined(EXP_WIN32_DRIVER) + int buf; +#endif unsigned char c2 = 0; -# if USE_PTHREADS_EINTR -# if USE_WEAK_SYMBOLS +#if USE_PTHREADS_EINTR +#if USE_WEAK_SYMBOLS if ((pthread_self) && (pthread_kill) && (pthread_equal)) -# endif +#endif _nc_globals.read_thread = pthread_self(); -# endif +#endif +#if defined(EXP_WIN32_DRIVER) + n = _nc_console_read(sp, + _nc_console_handle(sp->_ifd), + &buf); + c2 = buf; +#else n = (int) read(sp->_ifd, &c2, (size_t) 1); +#endif #if USE_PTHREADS_EINTR _nc_globals.read_thread = 0; #endif ch = c2; -#endif +#endif /* USE_TERM_DRIVER */ } if ((n == -1) || (n == 0)) { @@ -513,7 +551,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 diff --git a/ncurses/base/lib_getstr.c b/ncurses/base/lib_getstr.c index d0b09a3..5feb351 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-2020,2021 Thomas E. Dickey * * Copyright 1998-2011,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -39,9 +39,10 @@ ** */ +#define NEED_KEY_EVENT #include <curses.priv.h> -MODULE_ID("$Id: lib_getstr.c,v 1.34 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_getstr.c,v 1.37 2021/09/04 10:29:15 tom Exp $") /* * This wipes out the last character, no matter whether it was a tab, control @@ -99,8 +100,7 @@ wgetnstr_events(WINDOW *win, oldcbreak = sp->_cbreak; 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); + NCURSES_SP_NAME(raw) (NCURSES_SP_ARG); erasec = NCURSES_SP_NAME(erasechar) (NCURSES_SP_ARG); killc = NCURSES_SP_NAME(killchar) (NCURSES_SP_ARG); @@ -114,7 +114,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. */ diff --git a/ncurses/base/lib_initscr.c b/ncurses/base/lib_initscr.c index 2ace092..6b91491 100644 --- a/ncurses/base/lib_initscr.c +++ b/ncurses/base/lib_initscr.c @@ -46,7 +46,7 @@ #include <sys/termio.h> /* needed for ISC */ #endif -MODULE_ID("$Id: lib_initscr.c,v 1.45 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_initscr.c,v 1.48 2020/09/07 14:26:48 tom Exp $") NCURSES_EXPORT(WINDOW *) initscr(void) @@ -66,10 +66,9 @@ initscr(void) _nc_globals.init_screen = TRUE; - if ((env = getenv("TERM")) == 0 - || *env == '\0') { - env = "unknown"; - } + env = getenv("TERM"); + (void) VALID_TERM_ENV(env, "unknown"); + if ((name = strdup(env)) == NULL) { fprintf(stderr, "Error opening allocating $TERM.\n"); ExitProgram(EXIT_FAILURE); diff --git a/ncurses/base/lib_instr.c b/ncurses/base/lib_instr.c index 2aa0fc3..b9874b7 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 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.25 2021/04/03 22:24:18 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,6 +78,7 @@ 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); diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c index 2530dec..2fb261d 100644 --- a/ncurses/base/lib_mouse.c +++ b/ncurses/base/lib_mouse.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 * @@ -85,7 +85,7 @@ #define CUR SP_TERMTYPE #endif -MODULE_ID("$Id: lib_mouse.c,v 1.184 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_mouse.c,v 1.193 2021/03/20 12:56:32 tom Exp $") #include <tic.h> @@ -142,19 +142,29 @@ make an error #define MASK_RESERVED_EVENT(x) (mmask_t) NCURSES_MOUSE_MASK(x, 040) #if NCURSES_MOUSE_VERSION == 1 + #define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED) #define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED) #define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED) #define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED) #define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED) + #define MAX_BUTTONS 4 + #else + #define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED | BUTTON5_CLICKED) #define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED) #define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED | BUTTON5_RELEASED) #define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED | BUTTON5_DOUBLE_CLICKED) #define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED | BUTTON5_TRIPLE_CLICKED) + +#if NCURSES_MOUSE_VERSION == 2 #define MAX_BUTTONS 5 +#else +#define MAX_BUTTONS 11 +#endif + #endif #define INVALID_EVENT -1 @@ -409,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 @@ -426,7 +445,7 @@ enable_xterm_mouse(SCREEN *sp, int enable) #if USE_EMX_MOUSE sp->_emxmouse_activated = enable; #else - NCURSES_PUTP2("xterm-mouse", TPARM_1(sp->_mouse_xtermcap, enable)); + NCURSES_PUTP2("xterm-mouse", TIPARM_1(sp->_mouse_xtermcap, enable)); #endif sp->_mouse_active = enable; } @@ -477,8 +496,6 @@ unload_gpm_library(SCREEN *sp) T(("unload GPM library")); sp->_mouse_gpm_loaded = FALSE; sp->_mouse_fd = -1; - dlclose(sp->_dlopen_gpm); - sp->_dlopen_gpm = 0; } } @@ -486,7 +503,14 @@ static void load_gpm_library(SCREEN *sp) { sp->_mouse_gpm_found = FALSE; - if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) { + + /* + * If we already had a successful dlopen, reuse it. + */ + if (sp->_dlopen_gpm != 0) { + sp->_mouse_gpm_found = TRUE; + sp->_mouse_gpm_loaded = TRUE; + } else if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) { #if (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" @@ -500,13 +524,15 @@ load_gpm_library(SCREEN *sp) #endif T(("GPM initialization failed: %s", dlerror())); unload_gpm_library(sp); + dlclose(sp->_dlopen_gpm); + sp->_dlopen_gpm = 0; } else { sp->_mouse_gpm_found = TRUE; sp->_mouse_gpm_loaded = TRUE; } } } -#endif +#endif /* HAVE_LIBDL */ static bool enable_gpm_mouse(SCREEN *sp, bool enable) @@ -928,7 +954,7 @@ handle_wheel(SCREEN *sp, MEVENT * eventp, int button, int wheel) break; case 1: if (wheel) { -#if NCURSES_MOUSE_VERSION == 2 +#if NCURSES_MOUSE_VERSION >= 2 eventp->bstate = MASK_PRESS(5); /* See comment above for button 4 */ #else @@ -953,10 +979,24 @@ static bool decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro) { bool result; + int button = 0; + int wheel = (intro & 96) == 96; eventp->bstate = 0; - if (!handle_wheel(sp, eventp, (int) intro, (intro & 96) == 96)) { + if (intro >= 96) { + if (intro >= 160) { + button = (int) (intro - 152); /* buttons 8-11 */ + } else { + button = (int) (intro - 92); /* buttons 4-7 */ + } + } else { + button = (intro & 3); + } + + if (button > MAX_BUTTONS) { + eventp->bstate = REPORT_MOUSE_POSITION; + } else if (!handle_wheel(sp, eventp, (int) intro, wheel)) { /* * Release events aren't reported for individual buttons, just for @@ -1261,10 +1301,21 @@ decode_xterm_SGR1006(SCREEN *sp, MEVENT * eventp) if (read_SGR(sp, &data)) { int b = data.params[0]; int b3 = 1 + (b & 3); + int wheel = ((b & 64) == 64); + + if (b >= 132) { + b3 = MAX_BUTTONS + 1; + } else if (b >= 128) { + b3 = (b - 120); /* buttons 8-11 */ + } else if (b >= 64) { + b3 = (b - 60); /* buttons 6-7 */ + } eventp->id = NORMAL_EVENT; if (data.final == 'M') { - (void) handle_wheel(sp, eventp, b, (b & 64) == 64); + (void) handle_wheel(sp, eventp, b, wheel); + } else if (b3 > MAX_BUTTONS) { + eventp->bstate = REPORT_MOUSE_POSITION; } else { mmask_t pressed = (mmask_t) NCURSES_MOUSE_MASK(b3, NCURSES_BUTTON_PRESSED); mmask_t release = (mmask_t) NCURSES_MOUSE_MASK(b3, NCURSES_BUTTON_RELEASED); diff --git a/ncurses/base/lib_newterm.c b/ncurses/base/lib_newterm.c index ac89790..bba97ba 100644 --- a/ncurses/base/lib_newterm.c +++ b/ncurses/base/lib_newterm.c @@ -49,7 +49,7 @@ #include <tic.h> -MODULE_ID("$Id: lib_newterm.c,v 1.102 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_newterm.c,v 1.103 2020/09/05 21:34:04 tom Exp $") #ifdef USE_TERM_DRIVER #define NumLabels InfoOf(SP_PARM).numlabels @@ -88,6 +88,12 @@ _nc_initscr(NCURSES_SP_DCL0) buf.c_oflag &= (unsigned) ~(ONLCR); #elif HAVE_SGTTY_H buf.sg_flags &= ~(ECHO | CRMOD); +#elif defined(EXP_WIN32_DRIVER) + buf.dwFlagIn = CONMODE_IN_DEFAULT; + buf.dwFlagOut = CONMODE_OUT_DEFAULT | VT_FLAG_OUT; + if (WINCONSOLE.isTermInfoConsole) { + buf.dwFlagIn |= VT_FLAG_IN; + } #else memset(&buf, 0, sizeof(buf)); #endif @@ -195,6 +201,11 @@ NCURSES_SP_NAME(newterm) (NCURSES_SP_DCLx current = CURRENT_SCREEN; its_term = (current ? current->_term : 0); +#if defined(EXP_WIN32_DRIVER) + _setmode(fileno(_ifp), _O_BINARY); + _setmode(fileno(_ofp), _O_BINARY); +#endif + INIT_TERM_DRIVER(); /* this loads the capability entry, then sets LINES and COLS */ if ( diff --git a/ncurses/base/lib_pad.c b/ncurses/base/lib_pad.c index 73978fb..f49a5eb 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.49 2021/09/04 10:52:55 tom Exp $") NCURSES_EXPORT(WINDOW *) NCURSES_SP_NAME(newpad) (NCURSES_SP_DCLx int l, int c) @@ -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 diff --git a/ncurses/base/lib_screen.c b/ncurses/base/lib_screen.c index 164356d..eacb03a 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-2020,2021 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.97 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_screen.c,v 1.103 2021/10/18 22:40:48 tom Exp $") #define MAX_SIZE 0x3fff /* 16k is big enough for a window or pad */ @@ -58,7 +58,7 @@ MODULE_ID("$Id: lib_screen.c,v 1.97 2020/02/02 23:34:34 tom Exp $") #define ARG_SLIMIT(name) /* nothing */ #endif -#define CUR_SLIMIT _nc_SLIMIT(limit - (target - base)) +#define CUR_SLIMIT _nc_SLIMIT(limit - (size_t) (target - base)) #define TOP_SLIMIT _nc_SLIMIT(sizeof(buffer)) /* @@ -67,7 +67,7 @@ MODULE_ID("$Id: lib_screen.c,v 1.97 2020/02/02 23:34:34 tom Exp $") * format. It happens to be unused in the file 5.22 database (2015/03/07). */ static const char my_magic[] = -{'\210', '\210', '\210', '\210'}; +{'\210', '\210', '\210', '\210', 0}; #if NCURSES_EXT_PUTWIN typedef enum { @@ -200,7 +200,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 +214,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 +272,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 +329,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 +347,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; @@ -441,7 +441,7 @@ read_win(WINDOW *win, FILE *fp) } static int -read_row(char *source, NCURSES_CH_T * prior, NCURSES_CH_T * target, int length) +read_row(char *source, NCURSES_CH_T *prior, NCURSES_CH_T *target, int length) { while (*source != '\0' && length > 0) { #if NCURSES_WIDECHAR @@ -940,6 +940,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 +974,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 +1004,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 +1031,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 c5f26bc..264fb98 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-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,10 +44,17 @@ #include <curses.priv.h> #include <tic.h> +#if USE_GPM_SUPPORT +#ifdef HAVE_LIBDL +/* use dynamic loader to avoid linkage dependency */ +#include <dlfcn.h> +#endif +#endif + #undef CUR #define CUR SP_TERMTYPE -MODULE_ID("$Id: lib_set_term.c,v 1.169 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_set_term.c,v 1.179 2021/05/08 21:48:34 tom Exp $") #ifdef USE_TERM_DRIVER #define MaxColors InfoOf(sp).maxcolors @@ -140,8 +147,8 @@ delscreen(SCREEN *sp) _nc_lock_global(curses); if (delink_screen(sp)) { #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++) { @@ -197,6 +204,14 @@ delscreen(SCREEN *sp) if (_nc_find_prescr() == sp) { _nc_forget_prescr(); } +#if USE_GPM_SUPPORT +#ifdef HAVE_LIBDL + if (sp->_dlopen_gpm != 0) { + dlclose(sp->_dlopen_gpm); + sp->_dlopen_gpm = 0; + } +#endif +#endif /* USE_GPM_SUPPORT */ free(sp); /* @@ -314,9 +329,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(); } @@ -340,8 +360,9 @@ NCURSES_SP_NAME(_nc_setupscreen) ( sp->_next_screen = _nc_screen_chain; _nc_screen_chain = sp; - if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) + if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) { returnCode(ERR); + } #endif /* @@ -391,7 +412,11 @@ NCURSES_SP_NAME(_nc_setupscreen) ( fflush(output); setmode(output, O_BINARY); #endif - NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_ARGx output, TRUE); +#if defined(EXP_WIN32_DRIVER) + T(("setting output mode to binary")); + fflush(output); + _setmode(fileno(output), _O_BINARY); +#endif sp->_lines = (NCURSES_SIZE_T) slines; sp->_lines_avail = (NCURSES_SIZE_T) slines; sp->_columns = (NCURSES_SIZE_T) scolumns; @@ -399,6 +424,10 @@ NCURSES_SP_NAME(_nc_setupscreen) ( fflush(output); sp->_ofd = output ? fileno(output) : -1; sp->_ofp = output; +#if defined(EXP_WIN32_DRIVER) + if (output) + _setmode(fileno(output), _O_BINARY); +#endif sp->out_limit = (size_t) ((2 + slines) * (6 + scolumns)); if ((sp->out_buffer = malloc(sp->out_limit)) == 0) sp->out_limit = 0; @@ -470,7 +499,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) { @@ -667,6 +696,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; } diff --git a/ncurses/base/lib_slkrefr.c b/ncurses/base/lib_slkrefr.c index c6bf9d2..7a40624 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/new_pair.c b/ncurses/base/new_pair.c index 547ab28..70866c6 100644 --- a/ncurses/base/new_pair.c +++ b/ncurses/base/new_pair.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2021 Thomas E. Dickey * * Copyright 2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -61,7 +61,7 @@ #endif -MODULE_ID("$Id: new_pair.c,v 1.19 2020/02/02 23:34:34 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) @@ -144,17 +144,16 @@ static int _nc_find_color_pair(SCREEN *sp, int fg, int bg) { colorpair_t find; - int result; - void *pp; + int result = -1; find.fg = fg; find.bg = bg; - if (sp != 0 && - (pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) { - colorpair_t *temp = *(colorpair_t **) pp; - result = (int) (temp - sp->_color_pairs); - } else { - result = -1; + if (sp != 0) { + void *pp; + if ((pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) { + colorpair_t *temp = *(colorpair_t **) pp; + result = (int) (temp - sp->_color_pairs); + } } return result; } @@ -197,7 +196,10 @@ NCURSES_EXPORT(void) _nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next) { colorpair_t *last; + if (ValidPair(sp, pair)) { + bool used; + ReservePairs(sp, pair); last = &(sp->_color_pairs[pair]); delink_color_pair(sp, pair); @@ -205,6 +207,11 @@ _nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next) (last->fg != next->fg || last->bg != next->bg)) { /* remove the old entry from fast index */ tdelete(last, &sp->_ordered_pairs, compare_data); + used = FALSE; + } else { + used = (last->mode != cpFREE); + } + if (!used) { /* create a new entry in fast index */ *last = *next; tsearch(last, &sp->_ordered_pairs, compare_data); @@ -290,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 9b04287..225f552 100644 --- a/ncurses/base/resizeterm.c +++ b/ncurses/base/resizeterm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2021 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.51 2021/09/04 10:54:35 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) diff --git a/ncurses/base/safe_sprintf.c b/ncurses/base/safe_sprintf.c index 1868c00..3fff2e8 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-2020,2021 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.35 2021/10/03 00:25:09 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,30 @@ 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; + while ((used = vsnprintf(my_buffer, my_length, fmt, ap)) + >= (int) my_length) { + my_length = (size_t) ((3 * used) / 2); + my_buffer = typeRealloc(char, my_length, my_buffer); + } # 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/wresize.c b/ncurses/base/wresize.c index 93276ef..30718b8 100644 --- a/ncurses/base/wresize.c +++ b/ncurses/base/wresize.c @@ -34,7 +34,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: wresize.c,v 1.39 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: wresize.c,v 1.41 2020/04/18 21:01:00 tom Exp $") static int cleanup_lines(struct ldat *data, int length) @@ -176,7 +176,15 @@ wresize(WINDOW *win, int ToLines, int ToCols) if (s == 0) returnCode(cleanup_lines(new_lines, row)); for (col = 0; col <= ToCols; ++col) { - s[col] = (col <= size_x + bool valid = (col <= size_x); + if_WIDEC({ + if (col == ToCols + && col < size_x + && isWidecBase(win->_line[row].text[col])) { + valid = FALSE; + } + }); + s[col] = (valid ? win->_line[row].text[col] : win->_nc_bkgd); } |