clear up a few gcc warnings

This commit is contained in:
nhmall
2022-12-05 23:19:38 -05:00
parent afef4bc781
commit 215808abd1
10 changed files with 165 additions and 95 deletions

View File

@@ -2571,6 +2571,12 @@ extern int add_sound_mapping(const char *);
extern void play_sound_for_message(const char *);
extern void maybe_play_sound(const char *);
extern void release_sound_mappings(void);
#if defined(WIN32) || defined(QT_GRAPHICS)
extern void play_usersound(const char *, int);
#endif
#if defined(TTY_SOUND_ESCCODES)
extern void play_usersound_via_idx(int, int);
#endif
#endif /* USER SOUNDS */
/* ### sp_lev.c ### */

View File

@@ -108,6 +108,8 @@ extern void interject(int);
#endif
#ifdef strcasecmp
#undef strcasecmp
/* https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/ */
#define __USE_MINGW_ANSI_STDIO 1
#endif
/* extern int getlock(void); */
#endif

View File

@@ -1400,13 +1400,6 @@ tiphat(void)
#ifdef USER_SOUNDS
#if defined(WIN32) || defined(QT_GRAPHICS)
extern void play_usersound(const char *, int);
#endif
#if defined(TTY_SOUND_ESCCODES)
extern void play_usersound_via_idx(int, int);
#endif
typedef struct audio_mapping_rec {
struct nhregex *regex;
char *filename;

View File

@@ -59,6 +59,13 @@ INTERNET_AVAILABLE = N
GIT_AVAILABLE = N
#
#---------------------------------------------------------------
# Do you want to turn on the same gcc warnings as on Unix builds?
#
GCC_EXTRA_WARNINGS = N
#
#===============================================
#======= End of Modification Section ===========
@@ -289,6 +296,20 @@ 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
CPPFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \
-Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \
-Wmissing-declarations -Wformat-nonliteral -Wunreachable-code
endif
COMMONDEF = -DWIN32 -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
DLLDEF = $(COMMONDEF) -D_WINDOWS -D_USRDLL -D_WINDLL
CONSOLEDEF = $(COMMONDEF) -D_CONSOLE
@@ -727,7 +748,8 @@ COREOBJS = $(addsuffix .o, allmain alloc apply artifact attrib ball bones botl c
teleport timeout topten track trap u_init uhitm utf8map vault version vision \
weapon were wield windmain windows windsys wizard worm worn write zap)
CFLAGSW = $(CFLAGS) $(COMMONDEF) $(DLBFLG) -DTILES -D_WINDOWS -DMSWIN_GRAPHICS -DSAFEPROCS -DNOTTYGRAPHICS
CFLAGSW = $(CFLAGS) $(CFLAGSXTRA) $(COMMONDEF) $(DLBFLG) -DTILES -D_WINDOWS -DMSWIN_GRAPHICS -DSAFEPROCS -DNOTTYGRAPHICS
CPPFLAGSW = $(CFLAGS) $(CPPFLAGSXTRA) $(COMMONDEF) $(DLBFLG) -DTILES -D_WINDOWS -DMSWIN_GRAPHICS -DSAFEPROCS -DNOTTYGRAPHICS
ONHW = $(O)nethackw
NHWONLY = $(addsuffix .o, mhaskyn mhdlg mhfont mhinput mhmain mhmap mhmenu \
@@ -759,7 +781,10 @@ $(ONHW)/date.o: $(SRC)/date.c $(NHWOBJS) | $(ONHW)
$(cc) $(CFLAGSW) $(GITHASH) $(GITBRANCH) $< -o$@
$(ONHW)/cppregex.o: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONHW)
$(cc) $(CFLAGSW) $< -o$@
$(cc) $(CPPFLAGSW) $< -o$@
$(ONH)/cppregex.o: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONH)
$(cc) $(CPPFLAGSNH) $< -o$@
$(ONHW)/%.o: $(SSYS)/%.c $(NHLUAH) | $(ONHW)
$(cc) $(CFLAGSW) $< -o$@
@@ -792,7 +817,8 @@ CLEAN_FILE += $(NHWTARGETS) $(NHWOBJS) $(NHWRES) $(BMPS)
#==========================================
# nethack
#==========================================
CFLAGSNH = $(CFLAGSU) -DNO_TILE_C -DSAFEPROCS -D_LIB -DWIN32CON
CFLAGSNH = $(CFLAGSU) $(CFLAGSXTRA) -DNO_TILE_C -DSAFEPROCS -D_LIB -DWIN32CON
CPPFLAGSNH = $(CFLAGSU) $(CPPFLAGSXTRA) -DNO_TILE_C -DSAFEPROCS -D_LIB -DWIN32CON
ONH = $(O)nethack
@@ -827,7 +853,7 @@ $(ONH)/date.o: $(SRC)/date.c $(NHOBJS) $(NHRES) | $(ONH)
$(cc) $(CFLAGSNH) $(GITHASH) $(GITBRANCH) $< -o$@
$(ONH)/cppregex.o: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONH)
$(cc) $(CFLAGSNH) $< -o$@
$(cc) $(CPPFLAGSNH) $< -o$@
$(ONH)/%.o: $(SSYS)/%.c $(NHLUAH) | $(ONH)
$(cc) $(CFLAGSNH) $< -o$@

View File

@@ -61,7 +61,7 @@ $(ONHW)/%.d: $(SRC)/%.c $(NHLUAH) | $(ONHW)
$(cce) $(CFLAGSW) $< -o$@
$(ONHW)/cppregex.d: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONHW)
$(cce) $(CFLAGSW) $< -o$@
$(cce) $(CPPFLAGSW) $< -o$@
$(ONHW)/%.d: $(SSYS)/%.c $(NHLUAH) | $(ONHW)
$(cce) $(CFLAGSW) $< -o$@
@@ -79,7 +79,7 @@ $(ONH)/%.d: $(SRC)/%.c $(NHLUAH) | $(ONH)
$(cce) $(CFLAGSNH) $< -o$@
$(ONH)/cppregex.d: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONH)
$(cce) $(CFLAGSNH) $< -o$@
$(cce) $(CPPFLAGSNH) $< -o$@
$(ONH)/%.d: $(SSYS)/%.c $(NHLUAH) | $(ONH)
$(cce) $(CFLAGSNH) $< -o$@

View File

@@ -17,7 +17,7 @@
#ifdef USER_SOUNDS
void
play_usersound(const char* filename, int volume)
play_usersound(const char* filename, int volume UNUSED)
{
/* pline("play_usersound: %s (%d).", filename, volume); */
(void) sndPlaySound(filename, SND_ASYNC | SND_NODEFAULT);

View File

@@ -15,7 +15,7 @@ typedef struct {
int left; // in desktop coordinate pixel space
} MonitorInfo;
void win10_init();
void win10_init(void);
int win10_monitor_dpi(HWND hWnd);
double win10_monitor_scale(HWND hWnd);
void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo);

View File

@@ -100,6 +100,28 @@ static struct stat hbuf;
extern char orgdir[];
int get_known_folder_path(const KNOWNFOLDERID * folder_id,
char * path, size_t path_size);
void create_directory(const char * path);
int build_known_folder_path(const KNOWNFOLDERID * folder_id,
char * path, size_t path_size, boolean versioned);
void build_environment_path(const char * env_str, const char * folder,
char * path, size_t path_size);
boolean folder_file_exists(const char * folder, const char * file_name);
boolean test_portable_config(const char *executable_path,
char *portable_device_path, size_t portable_device_path_size);
void set_default_prefix_locations(const char *programPath);
void copy_sysconf_content(void);
void copy_config_content(void);
void copy_hack_content(void);
#ifdef PORT_HELP
void port_help(void);
#endif
void windows_raw_print(const char* str);
DISABLE_WARNING_UNREACHABLE_CODE
int
@@ -125,7 +147,8 @@ get_known_folder_path(
// silently handle this problem
return FALSE;
} else if (err != 0) {
error("Failed folder (%u) path string conversion, unexpected err = %d", folder_id->Data1, err);
error("Failed folder (%lu) path string conversion, unexpected err = %d",
folder_id->Data1, err);
return FALSE;
}
@@ -156,7 +179,7 @@ build_known_folder_path(
strcat(path, "\\NetHack\\");
create_directory(path);
if (versioned) {
Sprintf(eos(path), "%d.%d\\",
Sprintf(eos(path), "%d.%d\\",
VERSION_MAJOR, VERSION_MINOR);
create_directory(path);
}
@@ -226,7 +249,7 @@ test_portable_config(
*/
*portable_device_path = '\0';
lth = sizeof tmppath - strlen(sysconf);
lth = sizeof tmppath - strlen(sysconf);
(void) strncpy(tmppath, executable_path, lth - 1);
tmppath[lth - 1] = '\0';
(void) strcat(tmppath, sysconf);
@@ -260,14 +283,14 @@ const char *get_portable_device(void)
}
void
set_default_prefix_locations(const char *programPath)
set_default_prefix_locations(const char *programPath UNUSED)
{
static char executable_path[MAX_PATH];
static char profile_path[MAX_PATH];
static char versioned_profile_path[MAX_PATH];
static char versioned_user_data_path[MAX_PATH];
static char versioned_global_data_path[MAX_PATH];
static char versioninfo[20];
/* static char versioninfo[20] UNUSED; */
strcpy(executable_path, get_executable_path());
append_slash(executable_path);
@@ -594,7 +617,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
load_symset("RogueEpyx", ROGUESET);
}
/* Has the callback for the symset been invoked? Config file processing to
load a symset runs too early to accomplish that because
load a symset runs too early to accomplish that because
the various *graphics_mode_callback pointers don't get set until
term_start_screen, unfortunately */
#if defined(TERMLIB) || defined(CURSES_GRAPHICS)
@@ -1005,7 +1028,7 @@ fakeconsole(void)
}
has_fakeconsole = TRUE;
}
/* Obtain handles for the standard Console I/O devices */
hConIn = GetStdHandle(STD_INPUT_HANDLE);
hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -1135,14 +1158,15 @@ windows_nhbell(void)
/*ARGSUSED*/
int
windows_nh_poskey(int *x, int *y, int *mod)
windows_nh_poskey(int *x UNUSED, int *y UNUSED, int *mod UNUSED)
{
return '\033';
}
/*ARGSUSED*/
char
windows_yn_function(const char* query, const char* resp, char def)
windows_yn_function(const char* query UNUSED, const char* resp UNUSED,
char def UNUSED)
{
return '\033';
}
@@ -1329,7 +1353,7 @@ file_exists(const char* path)
RESTORE_WARNING_UNREACHABLE_CODE
/*
/*
file_newer returns TRUE if the file at a_path is newer then the file
at b_path. If a_path does not exist, it returns FALSE. If b_path
does not exist, it returns TRUE.

View File

@@ -4,7 +4,7 @@
/*
* WIN32 system functions.
*
*
* Included in both console-based and window-based clients on the windows platform.
*
* Initial Creation: Michael Allison - January 31/93
@@ -49,14 +49,22 @@ extern boolean getreturn_enabled;
int redirect_stdout;
#ifdef WIN32CON
typedef HWND(WINAPI *GETCONSOLEWINDOW)();
typedef HWND(WINAPI *GETCONSOLEWINDOW)(void);
#ifdef WIN32CON
static HWND GetConsoleHandle(void);
static HWND GetConsoleHwnd(void);
#endif
#if !defined(TTY_GRAPHICS)
extern void backsp(void);
#endif
int windows_console_custom_nhgetch(void);
extern void safe_routines(void);
int windows_early_options(const char *window_opt);
unsigned long sys_random_seed(void);
#if 0
static int max_filename(void);
#endif
/* The function pointer nt_kbhit contains a kbhit() equivalent
* which varies depending on which window port is active.
@@ -66,7 +74,7 @@ extern void safe_routines(void);
*/
int def_kbhit(void);
int (*nt_kbhit)() = def_kbhit;
int (*nt_kbhit)(void) = def_kbhit;
#endif /* WIN32CON */
#ifndef WIN32CON
@@ -157,6 +165,7 @@ chdrive(char* str)
}
}
#if 0
static int
max_filename(void)
{
@@ -170,6 +179,7 @@ max_filename(void)
else
return 0;
}
#endif
int
def_kbhit(void)
@@ -208,6 +218,8 @@ extern void mswin_raw_print_flush(void);
extern void mswin_raw_print(const char *);
#endif
DISABLE_WARNING_FORMAT_NONLITERAL
/* fatal error */
/*VARARGS1*/
void error
@@ -237,6 +249,8 @@ VA_DECL(const char *, s)
exit(EXIT_FAILURE);
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
Delay(int ms)
{
@@ -317,7 +331,7 @@ void
interject(int interjection_type)
{
if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES)
msmsg(interjection_buf[interjection_type]);
msmsg("%s", interjection_buf[interjection_type]);
}
#ifdef RUNTIME_PASTEBUF_SUPPORT
@@ -328,22 +342,23 @@ void port_insert_pastebuf(char *buf)
* to accomplish this.
*/
HGLOBAL hglbCopy;
HGLOBAL hglbCopy;
WCHAR *w, w2[2];
int cc, rc, abytes;
/* int cc; */
int rc, abytes;
LPWSTR lpwstrCopy;
HANDLE hresult;
if (!buf)
return;
cc = strlen(buf);
return;
/* cc = strlen(buf); */
/* last arg=0 means "tell me the size of the buffer that I need" */
rc = MultiByteToWideChar(GetConsoleOutputCP(), 0, buf, -1, w2, 0);
if (!rc) return;
abytes = rc * sizeof(WCHAR);
w = (WCHAR *)alloc(abytes);
w = (WCHAR *)alloc(abytes);
/* Housekeeping need: +free(w) */
rc = MultiByteToWideChar(GetConsoleOutputCP(), 0, buf, -1, w, rc);
@@ -357,18 +372,18 @@ void port_insert_pastebuf(char *buf)
}
/* Housekeeping need: +CloseClipboard(), free(w) */
EmptyClipboard();
EmptyClipboard();
/* allocate global mem obj to hold the text */
hglbCopy = GlobalAlloc(GMEM_MOVEABLE, abytes);
if (hglbCopy == NULL) {
CloseClipboard();
if (hglbCopy == NULL) {
CloseClipboard();
free(w);
return;
}
}
/* Housekeeping need: +GlobalFree(hglbCopy), CloseClipboard(), free(w) */
lpwstrCopy = (LPWSTR)GlobalLock(hglbCopy);
/* Housekeeping need: +GlobalUnlock(hglbCopy), GlobalFree(hglbCopy),
CloseClipboard(), free(w) */
@@ -384,8 +399,8 @@ void port_insert_pastebuf(char *buf)
GlobalFree(hglbCopy); /* only needed if clipboard didn't accept data */
}
/* Housekeeping need: CloseClipboard(), free(w) */
CloseClipboard();
CloseClipboard();
free(w);
return;
}
@@ -566,8 +581,10 @@ WCHAR *
winos_ascii_to_wide_str(const unsigned char * src, WCHAR * dst, size_t dstLength)
{
size_t i = 0;
while(i < dstLength - 1 && src[i] != 0)
dst[i++] = cp437[src[i]];
while(i < dstLength - 1 && src[i] != 0) {
dst[i] = cp437[src[i]];
i++;
}
dst[i] = 0;
return dst;
}
@@ -644,7 +661,8 @@ windows_early_options(const char *window_opt)
return 1;
} else {
raw_printf(
"-%swindows:cursorblink is the only supported option.\n");
"-%s windows:cursorblink is the only supported option.\n",
window_opt);
}
return 0;
}
@@ -690,10 +708,10 @@ sys_random_seed(void)
status = BCryptOpenAlgorithmProvider(&hRa, BCRYPT_RNG_ALGORITHM,
(LPCWSTR) 0, 0);
if (hRa && status == STATUS_SUCCESS) {
if (hRa && status == (NTSTATUS) STATUS_SUCCESS) {
status = BCryptGenRandom(hRa, (PUCHAR) &ourseed,
(ULONG) sizeof ourseed, 0);
if (status == STATUS_SUCCESS) {
if (status == (NTSTATUS) STATUS_SUCCESS) {
BCryptCloseAlgorithmProvider(hRa,0);
has_strong_rngseed = TRUE;
Plan_B = FALSE;
@@ -726,7 +744,7 @@ nt_assert_failed(const char *expression, const char *filepath, int line)
if (IsDebuggerPresent()) {
char message[BUFSIZ];
snprintf(message, sizeof(message),
snprintf(message, sizeof(message),
"nhassert(%s) failed in file '%s' at line %d",
expression, filename, line);
OutputDebugStringA(message);

View File

@@ -145,7 +145,7 @@ safe_get_nh_event(void)
}
void
safe_suspend_nhwindows(const char *str)
safe_suspend_nhwindows(const char *str UNUSED)
{
return;
}
@@ -157,44 +157,44 @@ safe_resume_nhwindows(void)
}
void
safe_exit_nhwindows(const char *str)
safe_exit_nhwindows(const char *str UNUSED)
{
return;
}
winid
safe_create_nhwindow(int type)
safe_create_nhwindow(int type UNUSED)
{
return WIN_ERR;
}
void
safe_clear_nhwindow(winid window)
safe_clear_nhwindow(winid window UNUSED)
{
return;
}
/*ARGSUSED*/
void
safe_display_nhwindow(winid window,boolean blocking)
safe_display_nhwindow(winid window UNUSED, boolean blocking UNUSED)
{
return;
}
void
safe_dismiss_nhwindow(winid window)
safe_dismiss_nhwindow(winid window UNUSED)
{
return;
}
void
safe_destroy_nhwindow(winid window)
safe_destroy_nhwindow(winid window UNUSED)
{
return;
}
void
safe_curs(winid window, int x, int y)
safe_curs(winid window UNUSED, int x UNUSED, int y UNUSED)
{
return;
}
@@ -206,19 +206,19 @@ safe_putstr(winid window, int attr, const char *str)
}
void
safe_putmixed(winid window, int attr, const char *str)
safe_putmixed(winid window UNUSED, int attr UNUSED, const char *str UNUSED)
{
return;
}
void
safe_display_file(const char * fname, boolean complain)
safe_display_file(const char * fname UNUSED, boolean complain UNUSED)
{
return;
}
void
safe_start_menu(winid window, unsigned long mbehavior)
safe_start_menu(winid window UNUSED, unsigned long mbehavior UNUSED)
{
return;
}
@@ -230,15 +230,15 @@ safe_start_menu(winid window, unsigned long mbehavior)
*/
void
safe_add_menu(
winid window, /* window to use, must be of type NHW_MENU */
winid window UNUSED, /* window to use, must be of type NHW_MENU */
const glyph_info *glyphinfo UNUSED, /* glyph plus glyph info */
const anything *identifier, /* what to return if selected */
char ch, /* keyboard accelerator (0 = pick our own) */
char gch, /* group accelerator (0 = no group) */
int attr, /* attribute for string (like safe_putstr()) */
int clr, /* colour for string */
const char *str, /* menu string */
unsigned int itemflags) /* itemflags such as marked as selected */
const anything *identifier UNUSED, /* what to return if selected */
char ch UNUSED, /* keyboard accelerator (0 = pick our own) */
char gch UNUSED, /* group accelerator (0 = no group) */
int attr UNUSED, /* attribute for string (like safe_putstr()) */
int clr UNUSED, /* colour for string */
const char *str UNUSED, /* menu string */
unsigned int itemflags UNUSED) /* itemflags such as marked as selected */
{
return;
}
@@ -248,17 +248,17 @@ safe_add_menu(
*/
void
safe_end_menu(
winid window, /* menu to use */
const char *prompt) /* prompt to for menu */
winid window UNUSED, /* menu to use */
const char *prompt UNUSED) /* prompt to for menu */
{
return;
}
int
safe_select_menu(
winid window,
int how,
menu_item **menu_list)
winid window UNUSED,
int how UNUSED,
menu_item **menu_list UNUSED)
{
return 0;
}
@@ -266,9 +266,9 @@ safe_select_menu(
/* special hack for treating top line --More-- as a one item menu */
char
safe_message_menu(
char let,
int how,
const char *mesg)
char let UNUSED,
int how UNUSED,
const char *mesg UNUSED)
{
return '\033';
}
@@ -285,7 +285,7 @@ safe_wait_synch(void)
#ifdef CLIPPING
void
safe_cliparound(int x, int y)
safe_cliparound(int x UNUSED, int y UNUSED)
{
}
#endif /* CLIPPING */
@@ -307,13 +307,13 @@ safe_print_glyph(
}
void
safe_raw_print(const char *str)
safe_raw_print(const char *str UNUSED)
{
return;
}
void
safe_raw_print_bold(const char *str)
safe_raw_print_bold(const char *str UNUSED)
{
return;
}
@@ -331,20 +331,20 @@ safe_nhgetch(void)
*/
/*ARGSUSED*/
int
safe_nh_poskey(coordxy *x, coordxy *y, int *mod)
safe_nh_poskey(coordxy *x UNUSED, coordxy *y UNUSED, int *mod UNUSED)
{
return '\033';
}
void
win_safe_init(int dir)
win_safe_init(int dir UNUSED)
{
return;
}
#ifdef POSITIONBAR
void
safe_update_positionbar(char *posbar)
safe_update_positionbar(char *posbar UNUSED)
{
return;
}
@@ -379,7 +379,8 @@ safe_doprev_message(void)
}
char
safe_yn_function(const char * query, const char* resp, char def)
safe_yn_function(const char *query UNUSED,
const char *resp UNUSED, char def UNUSED)
{
return '\033';
}
@@ -422,7 +423,7 @@ safe_end_screen(void)
}
void
safe_outrip(winid tmpwin, int how, time_t when)
safe_outrip(winid tmpwin UNUSED, int how UNUSED, time_t when UNUSED)
{
return;
}
@@ -442,8 +443,8 @@ safe_getmsghistory(boolean init UNUSED)
void
safe_putmsghistory(
const char *msg,
boolean is_restoring)
const char *msg UNUSED,
boolean is_restoring UNUSED)
{
}
@@ -454,18 +455,18 @@ safe_status_finish(void)
void
safe_status_enablefield(
int fieldidx,
const char *nm,
const char *fmt,
boolean enable)
int fieldidx UNUSED,
const char *nm UNUSED,
const char *fmt UNUSED,
boolean enable UNUSED)
{
}
/* call once for each field, then call with BL_FLUSH to output the result */
void
safe_status_update(
int idx,
genericptr_t ptr,
int idx UNUSED,
genericptr_t ptr UNUSED,
int chg UNUSED,
int percent UNUSED,
int color UNUSED,
@@ -481,9 +482,9 @@ safe_update_inventory(int arg UNUSED)
win_request_info *
safe_ctrl_nhwindow(
winid window,
int request,
win_request_info *wri)
winid window UNUSED,
int request UNUSED,
win_request_info *wri UNUSED)
{
return (win_request_info *) 0;
}