From 889d65994d6bc74c2ca855340e7f083275f2511a Mon Sep 17 00:00:00 2001 From: casey langen Date: Thu, 13 Apr 2023 12:47:00 -0700 Subject: [PATCH] Merge upstream PDCursesMod@4.3.6 changes --- CHANGELOG.txt | 1 + src/3rdparty/win32_include/curses.h | 6 +-- src/3rdparty/win32_src/pdcurses/getch.c | 47 +++++++++++++++++-- src/3rdparty/win32_src/pdcurses/initscr.c | 29 +++++------- src/3rdparty/win32_src/pdcurses/pad.c | 2 + src/3rdparty/win32_src/pdcurses/window.c | 11 ++++- .../win32_src/pdcurses/wingui/pdcdisp.c | 2 +- .../win32_src/pdcurses/wingui/pdcscrn.c | 2 +- 8 files changed, 73 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d266f5a87..8bfa32fcd 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -7,6 +7,7 @@ - libcurl@8.0.1 - libmicrohttpd@0.9.76 - libopenmpt@0.6.9 +* update to PDCursesMod@4.3.6 for Windows builds -------------------------------------------------------------------------------- diff --git a/src/3rdparty/win32_include/curses.h b/src/3rdparty/win32_include/curses.h index e3087209a..2535b71bb 100755 --- a/src/3rdparty/win32_include/curses.h +++ b/src/3rdparty/win32_include/curses.h @@ -39,10 +39,10 @@ Defined by this header: /* the 'endwin_*' #defines below should be updated. */ #define PDC_VER_MAJOR 4 #define PDC_VER_MINOR 3 -#define PDC_VER_CHANGE 5 +#define PDC_VER_CHANGE 6 #define PDC_VER_YEAR 2023 -#define PDC_VER_MONTH 01 -#define PDC_VER_DAY 05 +#define PDC_VER_MONTH 04 +#define PDC_VER_DAY 12 #define PDC_STRINGIZE( x) #x #define PDC_stringize( x) PDC_STRINGIZE( x) diff --git a/src/3rdparty/win32_src/pdcurses/getch.c b/src/3rdparty/win32_src/pdcurses/getch.c index b136a26a3..86fe231c3 100644 --- a/src/3rdparty/win32_src/pdcurses/getch.c +++ b/src/3rdparty/win32_src/pdcurses/getch.c @@ -228,7 +228,7 @@ static void _copy(void) #ifdef PDC_WIDE wtmp = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); - len *= 3; + len *= 4; #endif tmp = (char *)malloc(len + 1); @@ -467,11 +467,11 @@ bool PDC_is_function_key( const int key) #define WAIT_FOREVER -1 -int wgetch(WINDOW *win) +static int _raw_wgetch(WINDOW *win) { int key = ERR, remaining_millisecs; - PDC_LOG(("wgetch() - called\n")); + PDC_LOG(("_raw_wgetch() - called\n")); assert( SP); assert( win); @@ -701,6 +701,45 @@ int PDC_return_key_modifiers(bool flag) return PDC_modifiers_set(); } +int wgetch(WINDOW *win) +{ +#ifndef PDC_WIDE + return( _raw_wgetch( win)); +#else + static unsigned char buffered[8]; + static size_t n_buff = 0; + int rval; + + if( n_buff) + { + size_t i; + rval = buffered[0]; + n_buff--; + for( i = 0; i < n_buff; i++) + buffered[i] = buffered[i + 1]; + } + else + { + rval = _raw_wgetch(win); + if( rval != ERR && (rval < 0 || rval > 127) + && !PDC_is_function_key( rval)) + { + wchar_t c = (wchar_t)rval; + + n_buff = PDC_wcstombs( (char *)buffered, &c, 1); + if( (int)n_buff <= 0) + { + n_buff = 0; + rval = ERR; + } + else /* successfully converted to multi-byte string */ + rval = wgetch( win); + } + } + return( rval); +#endif +} + #ifdef PDC_WIDE int wget_wch(WINDOW *win, wint_t *wch) { @@ -712,7 +751,7 @@ int wget_wch(WINDOW *win, wint_t *wch) if (!wch) return ERR; - key = wgetch(win); + key = _raw_wgetch(win); if (key == ERR) return ERR; diff --git a/src/3rdparty/win32_src/pdcurses/initscr.c b/src/3rdparty/win32_src/pdcurses/initscr.c index 054c844ac..127a00b1e 100644 --- a/src/3rdparty/win32_src/pdcurses/initscr.c +++ b/src/3rdparty/win32_src/pdcurses/initscr.c @@ -148,11 +148,12 @@ MOUSE_STATUS Mouse_status; extern RIPPEDOFFLINE linesripped[5]; extern char linesrippedoff; -WINDOW *initscr(void) +SCREEN *newterm(const char *type, FILE *outfd, FILE *infd) { int i; - PDC_LOG(("initscr() - called\n")); + PDC_LOG(("newterm() - called\n")); + INTENTIONALLY_UNUSED_PARAMETER( type); if (SP && SP->alive) return NULL; @@ -285,8 +286,16 @@ WINDOW *initscr(void) return NULL; SP->c_ungind = 0; SP->c_ungmax = NUNGETCH; + SP->opaque->output_fd = outfd; + SP->opaque->input_fd = infd; - return stdscr; + return SP; +} + +WINDOW *initscr(void) +{ + PDC_LOG(("initscr() - called\n")); + return( newterm( NULL, NULL, NULL) ? stdscr : NULL); } #ifdef XCURSES @@ -324,20 +333,6 @@ bool isendwin(void) return SP ? !(SP->alive) : FALSE; } -SCREEN *newterm(const char *type, FILE *outfd, FILE *infd) -{ - WINDOW *win; - - PDC_LOG(("newterm() - called\n")); - INTENTIONALLY_UNUSED_PARAMETER( type); - win = initscr( ); - if( win && outfd != stdout) - SP->opaque->output_fd = outfd; - if( win && infd != stdin) - SP->opaque->input_fd = infd; - return win ? SP : NULL; -} - SCREEN *set_term(SCREEN *new_scr) { PDC_LOG(("set_term() - called\n")); diff --git a/src/3rdparty/win32_src/pdcurses/pad.c b/src/3rdparty/win32_src/pdcurses/pad.c index 941ef31fe..c6d551712 100644 --- a/src/3rdparty/win32_src/pdcurses/pad.c +++ b/src/3rdparty/win32_src/pdcurses/pad.c @@ -86,6 +86,7 @@ WINDOW *newpad(int nlines, int ncols) PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols)); + assert( nlines > 0 && ncols > 0); win = PDC_makenew(nlines, ncols, 0, 0); if (win) win = PDC_makelines(win); @@ -136,6 +137,7 @@ WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) if (!ncols) ncols = orig->_maxx - begx; + assert( nlines > 0 && ncols > 0); win = PDC_makenew(nlines, ncols, begy, begx); if (!win) return (WINDOW *)NULL; diff --git a/src/3rdparty/win32_src/pdcurses/window.c b/src/3rdparty/win32_src/pdcurses/window.c index 70f94b71c..e82d7c142 100644 --- a/src/3rdparty/win32_src/pdcurses/window.c +++ b/src/3rdparty/win32_src/pdcurses/window.c @@ -151,6 +151,7 @@ WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx) PDC_LOG(("PDC_makenew() - called: lines %d cols %d begy %d begx %d\n", nlines, ncols, begy, begx)); + assert( nlines > 0 && ncols > 0); /* allocate the window structure itself */ win = (WINDOW *)calloc(1, sizeof(WINDOW)); @@ -257,6 +258,10 @@ WINDOW *newwin(int nlines, int ncols, int begy, int begx) if (!ncols) ncols = COLS - begx; + assert( nlines > 0 && ncols > 0); + if( nlines <= 0 || ncols <= 0) + return (WINDOW *)NULL; + assert( SP); if (!SP || begy + nlines > SP->lines || begx + ncols > SP->cols) return (WINDOW *)NULL; @@ -358,6 +363,9 @@ WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) if (!ncols) ncols = orig->_maxx - k; + assert( nlines > 0 && ncols > 0); + if( nlines <= 0 || ncols <= 0) + return (WINDOW *)NULL; win = PDC_makenew(nlines, ncols, begy, begx); if (!win) return (WINDOW *)NULL; @@ -497,7 +505,8 @@ WINDOW *resize_window(WINDOW *win, int nlines, int ncols) assert( SP); assert( win); - if (!win || !SP) + assert( nlines >= 0 && ncols >= 0); + if (!win || !SP || nlines < 0 || ncols < 0) return (WINDOW *)NULL; if (win->_flags & _SUBPAD) diff --git a/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c b/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c index 49d1e6f0e..3c9e5f23b 100644 --- a/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c +++ b/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c @@ -204,7 +204,7 @@ function address at runtime. if the method isn't available, that means we're on and older operating system, so we just return the original value */ static LONG scale_font_for_current_dpi( LONG size) { - typedef LONG(__stdcall *GetDpiForSystemProc)(); + typedef LONG(STDAPICALLTYPE *GetDpiForSystemProc)(); HMODULE user32Dll = LoadLibrary( _T("User32.dll")); if ( user32Dll) diff --git a/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c b/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c index ff477f2a0..cf1e5c111 100644 --- a/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c +++ b/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c @@ -2241,7 +2241,7 @@ int PDC_scr_open(void) wine_version = (wine_version_func)GetProcAddress(hntdll, "wine_get_version"); if ( shcoredll) { - typedef HRESULT(__stdcall *set_process_dpi_awareness_t)(int); + typedef HRESULT(STDAPICALLTYPE *set_process_dpi_awareness_t)(int); static set_process_dpi_awareness_t set_process_dpi_awareness_func; static int ADJUST_DPI_PER_MONITOR = 2; set_process_dpi_awareness_func = (set_process_dpi_awareness_t)GetProcAddress(shcoredll, "SetProcessDpiAwareness");