diff --git a/common/include/jukebox.h b/common/include/jukebox.h index eb1fd7b98..115fb9cdd 100644 --- a/common/include/jukebox.h +++ b/common/include/jukebox.h @@ -1,9 +1,11 @@ #ifndef __JUKEBOX_H__ #define __JUKEBOX_H__ +#include "physfsx.h" + #ifdef __cplusplus -extern const char *const jukebox_exts[7]; +extern const file_extension_t jukebox_exts[7]; void jukebox_unload(); void jukebox_load(); diff --git a/common/include/physfsx.h b/common/include/physfsx.h index 66cb93dd0..01be1dc24 100644 --- a/common/include/physfsx.h +++ b/common/include/physfsx.h @@ -327,7 +327,7 @@ static inline void PHYSFSX_readMatrix(vms_matrix *m,PHYSFS_file *file) #define PHYSFSX_contfile_init PHYSFSX_addRelToSearchPath #define PHYSFSX_contfile_close PHYSFSX_removeRelFromSearchPath -typedef const char *file_extension_t; +typedef char file_extension_t[5]; int PHYSFSX_checkMatchingExtension(const file_extension_t *exts, const char *filename) __attribute_nonnull(); extern int PHYSFSX_addRelToSearchPath(const char *relname, int add_to_end); extern int PHYSFSX_removeRelFromSearchPath(const char *relname); diff --git a/common/main/newdemo.h b/common/main/newdemo.h index d88cbddc0..55bd58f40 100644 --- a/common/main/newdemo.h +++ b/common/main/newdemo.h @@ -35,7 +35,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define ND_STATE_ONEFRAMEBACKWARD 7 #define DEMO_DIR "demos/" -#define DEMO_EXT ".dem" +#define DEMO_EXT "dem" +extern const file_extension_t demo_file_extensions[2]; + #ifdef WORDS_BIGENDIAN #define DEMO_BACKUP_EXT "386" #else diff --git a/common/main/songs.h b/common/main/songs.h index f3690a6bb..5b69d8614 100644 --- a/common/main/songs.h +++ b/common/main/songs.h @@ -20,12 +20,12 @@ typedef struct bim_song_info { #define SONG_CREDITS 4 #define SONG_FIRST_LEVEL_SONG 5 -#define SONG_EXT_HMP ".hmp" +#define SONG_EXT_HMP "hmp" #ifdef USE_SDLMIXER -#define SONG_EXT_MID ".mid" -#define SONG_EXT_OGG ".ogg" -#define SONG_EXT_FLAC ".flac" -#define SONG_EXT_MP3 ".mp3" +#define SONG_EXT_MID "mid" +#define SONG_EXT_OGG "ogg" +#define SONG_EXT_FLAC "flac" +#define SONG_EXT_MP3 "mp3" #endif int songs_play_file(const char *filename, int repeat, void (*hook_finished_track)()); diff --git a/similar/arch/sdl/jukebox.cpp b/similar/arch/sdl/jukebox.cpp index 499ad5b7e..5c7506878 100644 --- a/similar/arch/sdl/jukebox.cpp +++ b/similar/arch/sdl/jukebox.cpp @@ -49,7 +49,7 @@ void jukebox_unload() JukeboxSongs.num_songs = JukeboxSongs.max_songs = JukeboxSongs.max_buf = 0; } -const char *const jukebox_exts[7] = { SONG_EXT_HMP, SONG_EXT_MID, SONG_EXT_OGG, SONG_EXT_FLAC, SONG_EXT_MP3, NULL }; +const file_extension_t jukebox_exts[7] = { SONG_EXT_HMP, SONG_EXT_MID, SONG_EXT_OGG, SONG_EXT_FLAC, SONG_EXT_MP3, "" }; static int read_m3u(void) { diff --git a/similar/main/menu.cpp b/similar/main/menu.cpp index c2b62e648..6047d33e7 100644 --- a/similar/main/menu.cpp +++ b/similar/main/menu.cpp @@ -130,6 +130,8 @@ static void do_multi_player_menu(); static void do_sandbox_menu(); #endif +static int select_file_recursive(const char *title, const char *orig_path, const file_extension_t *ext_list, int select_dir, int (*when_selected)(void *userdata, const char *filename), void *userdata) __attribute_nonnull(); + // Hide all menus int hide_menus(void) { @@ -315,7 +317,7 @@ int RegisterPlayer() const char **m; char **f; char **list; - static const char *const types[] = { ".plr", NULL }; + static const file_extension_t types[] = { "plr", "" }; int i = 0, NumItems; int citem = 0; int allow_abort_flag = 1; @@ -738,10 +740,9 @@ static int demo_menu_handler( listbox *lb, d_event *event, void *userdata ) int select_demo(void) { char **list; - static const char *const types[] = { DEMO_EXT, NULL }; int NumItems; - list = PHYSFSX_findFiles(DEMO_DIR, types); + list = PHYSFSX_findFiles(DEMO_DIR, demo_file_extensions); if (!list) return 0; // memory error if ( !*list ) @@ -1318,7 +1319,7 @@ typedef struct browser void *userdata; // Whatever you want passed to when_selected char **list; // All menu items char *list_buf; // Buffer for menu item text: hopefully reduces memory fragmentation this way - const char *const *ext_list; // List of file extensions we're looking for (if looking for a music file many types are possible) + const file_extension_t *ext_list; // List of file extensions we're looking for (if looking for a music file many types are possible) int select_dir; // Allow selecting the current directory (e.g. for Jukebox level song directory) int num_files; // Number of list items found (including parent directory and current directory if selectable) int max_files; // How many entries we can have before having to grow the array @@ -1363,8 +1364,6 @@ static int list_directory(browser *b) return 1; } -static int select_file_recursive(const char *title, const char *orig_path, const char *const *ext_list, int select_dir, int (*when_selected)(void *userdata, const char *filename), void *userdata); - static int select_file_handler(listbox *menu, d_event *event, browser *b) { char newpath[PATH_MAX]; @@ -1480,7 +1479,7 @@ static int select_file_handler(listbox *menu, d_event *event, browser *b) return 0; } -static int select_file_recursive(const char *title, const char *orig_path, const char *const *ext_list, int select_dir, int (*when_selected)(void *userdata, const char *filename), void *userdata) +static int select_file_recursive(const char *title, const char *orig_path, const file_extension_t *ext_list, int select_dir, int (*when_selected)(void *userdata, const char *filename), void *userdata) { browser *b; const char *sep = PHYSFS_getDirSeparator(); @@ -1681,7 +1680,7 @@ static int sound_menuset(newmenu *menu, d_event *event, void *userdata) #ifdef USE_SDLMIXER if (citem == opt_sm_mtype3_lmpath) { - static const char *const ext_list[] = { ".m3u", NULL }; // select a directory or M3U playlist + static const file_extension_t ext_list[] = { "m3u", "" }; // select a directory or M3U playlist select_file_recursive( #ifndef _WIN32 "Select directory or\nM3U playlist to\n play level music from", diff --git a/similar/main/newdemo.cpp b/similar/main/newdemo.cpp index 93f214d88..996e004ac 100644 --- a/similar/main/newdemo.cpp +++ b/similar/main/newdemo.cpp @@ -163,6 +163,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define DEMO_MAX_LEVELS 29 +const file_extension_t demo_file_extensions[2] = { DEMO_EXT, "" }; + // In- and Out-files PHYSFS_file *infile; PHYSFS_file *outfile = NULL; @@ -3730,10 +3732,9 @@ try_again: int newdemo_count_demos() { char **find, **i; - static const char *const types[] = { DEMO_EXT, NULL }; int NumFiles=0; - find = PHYSFSX_findFiles(DEMO_DIR, types); + find = PHYSFSX_findFiles(DEMO_DIR, demo_file_extensions); for (i = find; *i != NULL; i++) NumFiles++; @@ -3757,7 +3758,6 @@ void newdemo_start_playback(const char * filename) { // Randomly pick a filename int NumFiles = 0, RandFileNum; - static const char *const types[] = { DEMO_EXT, NULL }; rnd_demo = PURPOSE_RANDOM_PLAY; NumFiles = newdemo_count_demos(); @@ -3769,7 +3769,7 @@ void newdemo_start_playback(const char * filename) RandFileNum = d_rand() % NumFiles; NumFiles = 0; - find = PHYSFSX_findFiles(DEMO_DIR, types); + find = PHYSFSX_findFiles(DEMO_DIR, demo_file_extensions); for (i = find; *i != NULL; i++) { diff --git a/similar/misc/physfsx.cpp b/similar/misc/physfsx.cpp index 8a09a00e9..c589ead12 100644 --- a/similar/misc/physfsx.cpp +++ b/similar/misc/physfsx.cpp @@ -19,14 +19,17 @@ #include "object.h" #include "newdemo.h" +static const file_extension_t archive_exts[] = { "dxa", "" }; + int PHYSFSX_checkMatchingExtension(const file_extension_t *exts, const char *filename) { const char *ext = strrchr(filename, '.'); if (!ext) return 0; + ++ext; for (const file_extension_t *k = exts;; ++k) // see if the file is of a type we want { - if (!*k) + if (!(*k)[0]) return 0; if (!d_stricmp(ext, *k)) return 1; @@ -350,7 +353,7 @@ int PHYSFSX_rename(const char *oldpath, const char *newpath) // Find files at path that have an extension listed in exts // The extension list exts must be NULL-terminated, with each ext beginning with a '.' -char **PHYSFSX_findFiles(const char *path, const char *const *exts) +char **PHYSFSX_findFiles(const char *path, const file_extension_t *exts) { char **list = PHYSFS_enumerateFiles(path); char **i, **j = list; @@ -375,7 +378,7 @@ char **PHYSFSX_findFiles(const char *path, const char *const *exts) // Same function as above but takes a real directory as second argument, only adding files originating from this directory. // This can be used to further seperate files in search path but it must be made sure realpath is properly formatted. -char **PHYSFSX_findabsoluteFiles(const char *path, const char *realpath, const char *const *exts) +char **PHYSFSX_findabsoluteFiles(const char *path, const char *realpath, const file_extension_t *exts) { char **list = PHYSFS_enumerateFiles(path); char **i, **j = list; @@ -480,7 +483,6 @@ PHYSFS_file *PHYSFSX_openWriteBuffered(const char *filename) void PHYSFSX_addArchiveContent() { char **list = NULL; - static const char *const archive_exts[] = { ".dxa", NULL }; int i = 0, content_updated = 0; con_printf(CON_DEBUG, "PHYSFS: Adding archives to the game."); @@ -531,7 +533,6 @@ void PHYSFSX_addArchiveContent() void PHYSFSX_removeArchiveContent() { char **list = NULL; - static const char *const archive_exts[] = { ".dxa", NULL }; int i = 0; // find files in Searchpath ...