Some Windows gcc fixes

This commit is contained in:
nhmall
2024-11-30 19:06:05 -05:00
parent bc88266081
commit b89e792873
8 changed files with 53 additions and 31 deletions

View File

@@ -98,7 +98,7 @@ extern char *windows_exepath(void);
*=============================================== *===============================================
*/ */
#ifdef __MINGW32__ #ifdef __GNUC__
#define MD_USE_TMPFILE_S #define MD_USE_TMPFILE_S
# #
#ifdef strncasecmp #ifdef strncasecmp
@@ -110,10 +110,11 @@ extern char *windows_exepath(void);
#ifdef __USE_MINGW_ANSI_STDIO #ifdef __USE_MINGW_ANSI_STDIO
#undef __USE_MINGW_ANSI_STDIO #undef __USE_MINGW_ANSI_STDIO
#endif #endif
#define __USE_MINGW_ANSI_STDIO 1 /* with UCRT, we don't define this to 1 */
#define __USE_MINGW_ANSI_STDIO 0
#endif #endif
/* extern int getlock(void); */ /* extern int getlock(void); */
#endif /* __MINGW32__ */ #endif /* __GNUC__ */
#ifdef _MSC_VER #ifdef _MSC_VER
#define MD_USE_TMPFILE_S #define MD_USE_TMPFILE_S

View File

@@ -55,14 +55,13 @@ windsound_init_nhsound(void)
} }
static void static void
windsound_exit_nhsound(const char *reason) windsound_exit_nhsound(const char *reason UNUSED)
{ {
} }
static void 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; const char *filename;
char resourcename[120], buf[PATHLEN]; char resourcename[120], buf[PATHLEN];
int findsound_approach = sff_base_only; 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, filename = base_soundname_to_filename(resourcename,
buf, sizeof buf, findsound_approach); buf, sizeof buf, findsound_approach);
if (filename) { if (filename) {
reslt = PlaySound(filename, NULL, fdwsound); (void) PlaySound(filename, NULL, fdwsound);
} }
} }
static void static void
windsound_ambience(int32_t ambienceid, int32_t ambience_action, windsound_ambience(int32_t ambienceid UNUSED, int32_t ambience_action UNUSED,
int32_t hero_proximity) int32_t hero_proximity UNUSED)
{ {
} }
static void static void
windsound_verbal(char *text, int32_t gender, int32_t tone, windsound_verbal(char *text UNUSED, int32_t gender UNUSED, int32_t tone UNUSED,
int32_t vol, int32_t moreinfo) int32_t vol UNUSED, int32_t moreinfo UNUSED)
{ {
} }
static void 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 #ifdef SND_SOUNDEFFECTS_AUTOMAP
int reslt = 0; /* int reslt = 0; */
int32_t findsound_approach = sff_base_only; int32_t findsound_approach = sff_base_only;
char buf[PATHLEN]; char buf[PATHLEN];
const char *filename; const char *filename;
@@ -147,7 +146,7 @@ windsound_soundeffect(char *desc, int32_t seid, int32_t volume)
} }
if (filename) { if (filename) {
reslt = PlaySound(filename, NULL, fdwsound); (void) PlaySound(filename, NULL, fdwsound);
} }
#endif #endif
} }
@@ -155,7 +154,7 @@ windsound_soundeffect(char *desc, int32_t seid, int32_t volume)
#define WAVEMUSIC_SOUNDS #define WAVEMUSIC_SOUNDS
static void 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 #ifdef WAVEMUSIC_SOUNDS
int reslt = 0; 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 */ /* the final, or only, one is played ASYNC */
maybe_preinsert_directory(findsound_approach, exedir, buf, sizeof buf); maybe_preinsert_directory(findsound_approach, exedir, buf, sizeof buf);
reslt = PlaySound(buf, NULL, fdwsound); reslt = PlaySound(buf, NULL, fdwsound);
nhUse(filename);
nhUse(reslt);
#endif #endif
} }

View File

@@ -334,15 +334,19 @@ else
DLBFLG = DLBFLG =
endif endif
ifeq "$(GCC_EXTRA_WARNINGS)" "Y" ifeq "$(GCC_EXTRA_WARNINGS)" "Y"
# #
# These match the warnings enabled on the linux.370 and macOS.370 hints builds # These match the warnings enabled on the linux.370 and macOS.370 hints builds
# #
CFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \ CFLAGSXTRA = -Wall -Wextra -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow \
-Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \ -Wwrite-strings -pedantic -Wmissing-declarations \
-Wmissing-declarations -Wformat-nonliteral -Wunreachable-code \ -Wformat-nonliteral -Wunreachable-code -Wimplicit \
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int \ -Wimplicit-function-declaration -Wimplicit-int \
-Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition \
-Wstrict-prototypes -Wnonnull -Wformat-overflow \
-Wmissing-parameter-type -Wimplicit-fallthrough
CPPFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \ CPPFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \
-Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \ -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \
-Wmissing-declarations -Wformat-nonliteral -Wunreachable-code -Wmissing-declarations -Wformat-nonliteral -Wunreachable-code

View File

@@ -69,7 +69,7 @@ void windows_nhbell(void);
int windows_nh_poskey(int *, int *, int *); int windows_nh_poskey(int *, int *, int *);
void windows_raw_print(const char *); void windows_raw_print(const char *);
char windows_yn_function(const char *, const char *, 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 #ifdef WIN32CON
extern int windows_console_custom_nhgetch(void); extern int windows_console_custom_nhgetch(void);
@@ -116,6 +116,11 @@ void copy_sysconf_content(void);
void copy_config_content(void); void copy_config_content(void);
void copy_hack_content(void); void copy_hack_content(void);
void copy_symbols_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 #ifdef PORT_HELP
void port_help(void); void port_help(void);
@@ -150,6 +155,7 @@ DISABLE_WARNING_UNREACHABLE_CODE
#if defined(MSWIN_GRAPHICS) #if defined(MSWIN_GRAPHICS)
#define MAIN nethackw_main #define MAIN nethackw_main
int nethackw_main(int, char **);
#else #else
#define MAIN main #define MAIN main
#endif #endif
@@ -369,7 +375,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
(void) fname_encode( (void) fname_encode(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%',
fnamebuf, encodedfnamebuf, BUFSZ); fnamebuf, encodedfnamebuf, BUFSZ);
Sprintf(gl.lock, "%s", encodedfnamebuf); Snprintf(gl.lock, sizeof gl.lock, "%s", encodedfnamebuf);
/* regularize(lock); */ /* we encode now, rather than substitute */ /* regularize(lock); */ /* we encode now, rather than substitute */
if ((getlock_result = getlock()) == 0) if ((getlock_result = getlock()) == 0)
nethack_exit(EXIT_SUCCESS); nethack_exit(EXIT_SUCCESS);
@@ -631,6 +637,7 @@ process_options(int argc, char * argv[])
} else } else
raw_printf("\nUnknown switch: %s", argv[0]); raw_printf("\nUnknown switch: %s", argv[0]);
FALLTHROUGH; FALLTHROUGH;
/* FALLTHRU */
case '?': case '?':
nhusage(); nhusage();
nethack_exit(EXIT_SUCCESS); nethack_exit(EXIT_SUCCESS);
@@ -989,6 +996,7 @@ copy_symbols_content(void)
copy_file(gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS, copy_file(gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS,
gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS_TEMPLATE, TRUE); gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS_TEMPLATE, TRUE);
} }
nhUse(no_template);
} }
void void
@@ -1107,10 +1115,10 @@ boolean
fakeconsole(void) fakeconsole(void)
{ {
if (!hStdOut) { if (!hStdOut) {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE fkhStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); HANDLE fkhStdIn = GetStdHandle(STD_INPUT_HANDLE);
if (!hStdOut && !hStdIn) { if (!fkhStdOut && !fkhStdIn) {
/* Bool rval; */ /* Bool rval; */
AllocConsole(); AllocConsole();
AttachConsole(GetCurrentProcessId()); AttachConsole(GetCurrentProcessId());
@@ -1277,11 +1285,13 @@ windows_yn_function(const char *query UNUSED, const char *resp UNUSED,
} }
/*ARGSUSED*/ /*ARGSUSED*/
#if 0
static void static void
windows_getlin(const char *prompt UNUSED, char *outbuf) windows_getlin(const char *prompt UNUSED, char *outbuf)
{ {
Strcpy(outbuf, "\033"); Strcpy(outbuf, "\033");
} }
#endif
#ifdef PC_LOCKING #ifdef PC_LOCKING
static int static int

View File

@@ -1022,7 +1022,8 @@ onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
pFile = _tfopen(filename, TEXT("wt+,ccs=UTF-8")); pFile = _tfopen(filename, TEXT("wt+,ccs=UTF-8"));
if (!pFile) { if (!pFile) {
TCHAR buf[4096]; 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); NHMessageBox(hWnd, buf, MB_OK | MB_ICONERROR);
if (text) if (text)
free(text); free(text);

View File

@@ -1188,10 +1188,12 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
&& data->menui.menu.items[lpdis->itemID].count != 0 && data->menui.menu.items[lpdis->itemID].count != 0
&& item->glyphinfo.glyph != NO_GLYPH) { && item->glyphinfo.glyph != NO_GLYPH) {
if (data->menui.menu.items[lpdis->itemID].count == -1) { if (data->menui.menu.items[lpdis->itemID].count == -1) {
_stprintf(wbuf, TEXT("Count: All")); nh_stprintf(wbuf, sizeof wbuf,
TEXT("Count: All"));
} else { } else {
_stprintf(wbuf, TEXT("Count: %d"), nh_stprintf(wbuf, sizeof wbuf,
data->menui.menu.items[lpdis->itemID].count); TEXT("Count: %d"),
data->menui.menu.items[lpdis->itemID].count);
} }
/* TODO: add blinking for blink text */ /* TODO: add blinking for blink text */

View File

@@ -1061,8 +1061,9 @@ mswin_display_file(const char *filename, boolean must_exist)
if (!f) { if (!f) {
if (must_exist) { if (must_exist) {
TCHAR message[90]; TCHAR message[90];
_stprintf(message, TEXT("Warning! Could not find file: %s\n"), nh_stprintf(message, sizeof message,
NH_A2W(filename, wbuf, sizeof(wbuf))); TEXT("Warning! Could not find file: %s\n"),
NH_A2W(filename, wbuf, sizeof(wbuf)));
NHMessageBox(GetNHApp()->hMainWnd, message, NHMessageBox(GetNHApp()->hMainWnd, message,
MB_OK | MB_ICONEXCLAMATION); MB_OK | MB_ICONEXCLAMATION);
} }

View File

@@ -249,12 +249,14 @@ extern COLORREF message_fg_color;
/* unicode stuff */ /* unicode stuff */
#define NH_CODEPAGE (SYMHANDLING(H_IBM) ? GetOEMCP() : GetACP()) #define NH_CODEPAGE (SYMHANDLING(H_IBM) ? GetOEMCP() : GetACP())
#ifdef _UNICODE #ifdef _UNICODE
#define nh_stprintf swprintf
#define NH_W2A(w, a, cb) \ #define NH_W2A(w, a, cb) \
(WideCharToMultiByte(NH_CODEPAGE, 0, (w), -1, (a), (cb), NULL, NULL), (a)) (WideCharToMultiByte(NH_CODEPAGE, 0, (w), -1, (a), (cb), NULL, NULL), (a))
#define NH_A2W(a, w, cb) \ #define NH_A2W(a, w, cb) \
(MultiByteToWideChar(NH_CODEPAGE, 0, (a), -1, (w), (cb)), (w)) (MultiByteToWideChar(NH_CODEPAGE, 0, (a), -1, (w), (cb)), (w))
#else #else
#define nh_stprintf snprintf
#define NH_W2A(w, a, cb) (strncpy((a), (w), (cb))) #define NH_W2A(w, a, cb) (strncpy((a), (w), (cb)))
#define NH_A2W(a, w, cb) (strncpy((w), (a), (cb))) #define NH_A2W(a, w, cb) (strncpy((w), (a), (cb)))