From b89e7928735726538ff6cd7ab152a23235c1caee Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 30 Nov 2024 19:06:05 -0500 Subject: [PATCH] Some Windows gcc fixes --- include/windconf.h | 7 ++++--- sound/windsound/windsound.c | 25 +++++++++++++------------ sys/windows/Makefile.mingw32 | 14 +++++++++----- sys/windows/windmain.c | 20 +++++++++++++++----- win/win32/mhmain.c | 3 ++- win/win32/mhmenu.c | 8 +++++--- win/win32/mswproc.c | 5 +++-- win/win32/winMS.h | 2 ++ 8 files changed, 53 insertions(+), 31 deletions(-) diff --git a/include/windconf.h b/include/windconf.h index ebfac1e8b..1b5b45d92 100644 --- a/include/windconf.h +++ b/include/windconf.h @@ -98,7 +98,7 @@ extern char *windows_exepath(void); *=============================================== */ -#ifdef __MINGW32__ +#ifdef __GNUC__ #define MD_USE_TMPFILE_S # #ifdef strncasecmp @@ -110,10 +110,11 @@ extern char *windows_exepath(void); #ifdef __USE_MINGW_ANSI_STDIO #undef __USE_MINGW_ANSI_STDIO #endif -#define __USE_MINGW_ANSI_STDIO 1 +/* with UCRT, we don't define this to 1 */ +#define __USE_MINGW_ANSI_STDIO 0 #endif /* extern int getlock(void); */ -#endif /* __MINGW32__ */ +#endif /* __GNUC__ */ #ifdef _MSC_VER #define MD_USE_TMPFILE_S diff --git a/sound/windsound/windsound.c b/sound/windsound/windsound.c index 8ccfe9f65..0dc486f18 100644 --- a/sound/windsound/windsound.c +++ b/sound/windsound/windsound.c @@ -55,14 +55,13 @@ windsound_init_nhsound(void) } static void -windsound_exit_nhsound(const char *reason) +windsound_exit_nhsound(const char *reason UNUSED) { } static void -windsound_achievement(schar ach1, schar ach2, int32_t repeat) +windsound_achievement(schar ach1, schar ach2, int32_t repeat UNUSED) { - int reslt = 0; const char *filename; char resourcename[120], buf[PATHLEN]; int findsound_approach = sff_base_only; @@ -108,27 +107,27 @@ windsound_achievement(schar ach1, schar ach2, int32_t repeat) filename = base_soundname_to_filename(resourcename, buf, sizeof buf, findsound_approach); if (filename) { - reslt = PlaySound(filename, NULL, fdwsound); + (void) PlaySound(filename, NULL, fdwsound); } } static void -windsound_ambience(int32_t ambienceid, int32_t ambience_action, - int32_t hero_proximity) +windsound_ambience(int32_t ambienceid UNUSED, int32_t ambience_action UNUSED, + int32_t hero_proximity UNUSED) { } static void -windsound_verbal(char *text, int32_t gender, int32_t tone, - int32_t vol, int32_t moreinfo) +windsound_verbal(char *text UNUSED, int32_t gender UNUSED, int32_t tone UNUSED, + int32_t vol UNUSED, int32_t moreinfo UNUSED) { } static void -windsound_soundeffect(char *desc, int32_t seid, int32_t volume) +windsound_soundeffect(char *desc UNUSED, int32_t seid, int32_t volume UNUSED) { #ifdef SND_SOUNDEFFECTS_AUTOMAP - int reslt = 0; +/* int reslt = 0; */ int32_t findsound_approach = sff_base_only; char buf[PATHLEN]; const char *filename; @@ -147,7 +146,7 @@ windsound_soundeffect(char *desc, int32_t seid, int32_t volume) } if (filename) { - reslt = PlaySound(filename, NULL, fdwsound); + (void) PlaySound(filename, NULL, fdwsound); } #endif } @@ -155,7 +154,7 @@ windsound_soundeffect(char *desc, int32_t seid, int32_t volume) #define WAVEMUSIC_SOUNDS static void -windsound_hero_playnotes(int32_t instrument, const char *str, int32_t volume) +windsound_hero_playnotes(int32_t instrument, const char *str, int32_t volume UNUSED) { #ifdef WAVEMUSIC_SOUNDS int reslt = 0; @@ -239,6 +238,8 @@ windsound_hero_playnotes(int32_t instrument, const char *str, int32_t volume) /* the final, or only, one is played ASYNC */ maybe_preinsert_directory(findsound_approach, exedir, buf, sizeof buf); reslt = PlaySound(buf, NULL, fdwsound); + nhUse(filename); + nhUse(reslt); #endif } diff --git a/sys/windows/Makefile.mingw32 b/sys/windows/Makefile.mingw32 index 2ac83fa5b..809b822bd 100644 --- a/sys/windows/Makefile.mingw32 +++ b/sys/windows/Makefile.mingw32 @@ -334,15 +334,19 @@ else DLBFLG = endif + ifeq "$(GCC_EXTRA_WARNINGS)" "Y" # # These match the warnings enabled on the linux.370 and macOS.370 hints builds # -CFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \ - -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \ - -Wmissing-declarations -Wformat-nonliteral -Wunreachable-code \ - -Wimplicit -Wimplicit-function-declaration -Wimplicit-int \ - -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes +CFLAGSXTRA = -Wall -Wextra -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow \ + -Wwrite-strings -pedantic -Wmissing-declarations \ + -Wformat-nonliteral -Wunreachable-code -Wimplicit \ + -Wimplicit-function-declaration -Wimplicit-int \ + -Wmissing-prototypes -Wold-style-definition \ + -Wstrict-prototypes -Wnonnull -Wformat-overflow \ + -Wmissing-parameter-type -Wimplicit-fallthrough + CPPFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \ -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \ -Wmissing-declarations -Wformat-nonliteral -Wunreachable-code diff --git a/sys/windows/windmain.c b/sys/windows/windmain.c index df7e009b1..cd1bdf9bd 100644 --- a/sys/windows/windmain.c +++ b/sys/windows/windmain.c @@ -69,7 +69,7 @@ void windows_nhbell(void); int windows_nh_poskey(int *, int *, int *); void windows_raw_print(const char *); char windows_yn_function(const char *, const char *, char); -static void windows_getlin(const char *, char *); +/* static void windows_getlin(const char *, char *); */ #ifdef WIN32CON extern int windows_console_custom_nhgetch(void); @@ -116,6 +116,11 @@ void copy_sysconf_content(void); void copy_config_content(void); void copy_hack_content(void); void copy_symbols_content(void); +void copy_file(const char *, const char *, + const char *, const char *, boolean); +void update_file(const char *, const char *, + const char *, const char *, BOOL); +void windows_raw_print_bold(const char *); #ifdef PORT_HELP void port_help(void); @@ -150,6 +155,7 @@ DISABLE_WARNING_UNREACHABLE_CODE #if defined(MSWIN_GRAPHICS) #define MAIN nethackw_main +int nethackw_main(int, char **); #else #define MAIN main #endif @@ -369,7 +375,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ (void) fname_encode( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%', fnamebuf, encodedfnamebuf, BUFSZ); - Sprintf(gl.lock, "%s", encodedfnamebuf); + Snprintf(gl.lock, sizeof gl.lock, "%s", encodedfnamebuf); /* regularize(lock); */ /* we encode now, rather than substitute */ if ((getlock_result = getlock()) == 0) nethack_exit(EXIT_SUCCESS); @@ -631,6 +637,7 @@ process_options(int argc, char * argv[]) } else raw_printf("\nUnknown switch: %s", argv[0]); FALLTHROUGH; + /* FALLTHRU */ case '?': nhusage(); nethack_exit(EXIT_SUCCESS); @@ -989,6 +996,7 @@ copy_symbols_content(void) copy_file(gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS, gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS_TEMPLATE, TRUE); } + nhUse(no_template); } void @@ -1107,10 +1115,10 @@ boolean fakeconsole(void) { if (!hStdOut) { - HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); - HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); + HANDLE fkhStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE fkhStdIn = GetStdHandle(STD_INPUT_HANDLE); - if (!hStdOut && !hStdIn) { + if (!fkhStdOut && !fkhStdIn) { /* Bool rval; */ AllocConsole(); AttachConsole(GetCurrentProcessId()); @@ -1277,11 +1285,13 @@ windows_yn_function(const char *query UNUSED, const char *resp UNUSED, } /*ARGSUSED*/ +#if 0 static void windows_getlin(const char *prompt UNUSED, char *outbuf) { Strcpy(outbuf, "\033"); } +#endif #ifdef PC_LOCKING static int diff --git a/win/win32/mhmain.c b/win/win32/mhmain.c index 46a71b7d4..053324db8 100644 --- a/win/win32/mhmain.c +++ b/win/win32/mhmain.c @@ -1022,7 +1022,8 @@ onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) pFile = _tfopen(filename, TEXT("wt+,ccs=UTF-8")); if (!pFile) { TCHAR buf[4096]; - _stprintf(buf, TEXT("Cannot open %s for writing!"), filename); + nh_stprintf(buf, sizeof buf, + TEXT("Cannot open %s for writing!"), filename); NHMessageBox(hWnd, buf, MB_OK | MB_ICONERROR); if (text) free(text); diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 41442cc69..0899bc747 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -1188,10 +1188,12 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) && data->menui.menu.items[lpdis->itemID].count != 0 && item->glyphinfo.glyph != NO_GLYPH) { if (data->menui.menu.items[lpdis->itemID].count == -1) { - _stprintf(wbuf, TEXT("Count: All")); + nh_stprintf(wbuf, sizeof wbuf, + TEXT("Count: All")); } else { - _stprintf(wbuf, TEXT("Count: %d"), - data->menui.menu.items[lpdis->itemID].count); + nh_stprintf(wbuf, sizeof wbuf, + TEXT("Count: %d"), + data->menui.menu.items[lpdis->itemID].count); } /* TODO: add blinking for blink text */ diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 42abf9a19..cf4f63a44 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -1061,8 +1061,9 @@ mswin_display_file(const char *filename, boolean must_exist) if (!f) { if (must_exist) { TCHAR message[90]; - _stprintf(message, TEXT("Warning! Could not find file: %s\n"), - NH_A2W(filename, wbuf, sizeof(wbuf))); + nh_stprintf(message, sizeof message, + TEXT("Warning! Could not find file: %s\n"), + NH_A2W(filename, wbuf, sizeof(wbuf))); NHMessageBox(GetNHApp()->hMainWnd, message, MB_OK | MB_ICONEXCLAMATION); } diff --git a/win/win32/winMS.h b/win/win32/winMS.h index 1cb26aed2..ed7e24e8f 100644 --- a/win/win32/winMS.h +++ b/win/win32/winMS.h @@ -249,12 +249,14 @@ extern COLORREF message_fg_color; /* unicode stuff */ #define NH_CODEPAGE (SYMHANDLING(H_IBM) ? GetOEMCP() : GetACP()) #ifdef _UNICODE +#define nh_stprintf swprintf #define NH_W2A(w, a, cb) \ (WideCharToMultiByte(NH_CODEPAGE, 0, (w), -1, (a), (cb), NULL, NULL), (a)) #define NH_A2W(a, w, cb) \ (MultiByteToWideChar(NH_CODEPAGE, 0, (a), -1, (w), (cb)), (w)) #else +#define nh_stprintf snprintf #define NH_W2A(w, a, cb) (strncpy((a), (w), (cb))) #define NH_A2W(a, w, cb) (strncpy((w), (a), (cb)))