(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
authorDarkvater
Sat, 05 Aug 2006 00:59:45 +0000
changeset 4223 0f9535dda7ed
parent 4222 951fbf19b1ad
child 4224 4471b359da52
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
console_cmds.c
fios.c
fios.h
hal.h
misc_gui.c
network_gui.c
os2.c
unix.c
win32.c
--- a/console_cmds.c	Sat Aug 05 00:53:09 2006 +0000
+++ b/console_cmds.c	Sat Aug 05 00:59:45 2006 +0000
@@ -15,7 +15,7 @@
 #include "network_udp.h"
 #include "command.h"
 #include "settings.h"
-#include "hal.h" /* for file list */
+#include "fios.h"
 #include "vehicle.h"
 #include "station.h"
 #include "strings.h"
@@ -345,7 +345,7 @@
 	}
 
 	// XXX - Workaround for broken file handling
-	FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME);
+	FiosGetSavegameList(SLD_LOAD_GAME);
 	FiosFreeSavegameList();
 
 	FiosGetDescText(&path, NULL);
--- a/fios.c	Sat Aug 05 00:53:09 2006 +0000
+++ b/fios.c	Sat Aug 05 00:59:45 2006 +0000
@@ -11,7 +11,6 @@
 #include "variables.h"
 #include "functions.h"
 #include "table/strings.h"
-#include "hal.h"
 #include "fios.h"
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -23,9 +22,12 @@
 # include <dirent.h>
 #endif /* WIN32 */
 
-char *_fios_path;
-FiosItem *_fios_items;
-int _fios_count, _fios_alloc;
+/* Variables to display file lists */
+int _fios_num;
+
+static char *_fios_path;
+static FiosItem *_fios_items;
+static int _fios_count, _fios_alloc;
 
 /* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
 extern bool FiosIsRoot(const char *path);
@@ -184,7 +186,7 @@
  *  @param mode The mode we are in. Some modes don't allow 'parent'.
  *  @param callback The function that is called where you need to do the filtering.
  *  @return Return the list of files. */
-static FiosItem *FiosGetFileList(int *num, int mode, fios_getlist_callback_proc *callback_proc)
+static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_proc)
 {
 	struct stat sb;
 	struct dirent *dirent;
@@ -265,7 +267,7 @@
 	/* Show drives */
 	if (mode != SLD_NEW_GAME) FiosGetDrives();
 
-	*num = _fios_count;
+	_fios_num = _fios_count;
 	return _fios_items;
 }
 
@@ -305,7 +307,7 @@
  * @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
  * @see FiosGetFileList
  */
-FiosItem *FiosGetSavegameList(int *num, int mode)
+FiosItem *FiosGetSavegameList(int mode)
 {
 	static char *_fios_save_path = NULL;
 
@@ -316,7 +318,7 @@
 
 	_fios_path = _fios_save_path;
 
-	return FiosGetFileList(num, mode, &FiosGetSavegameListCallback);
+	return FiosGetFileList(mode, &FiosGetSavegameListCallback);
 }
 
 /**
@@ -353,7 +355,7 @@
  * @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
  * @see FiosGetFileList
  */
-FiosItem *FiosGetScenarioList(int *num, int mode)
+FiosItem *FiosGetScenarioList(int mode)
 {
 	static char *_fios_scn_path = NULL;
 
@@ -364,5 +366,5 @@
 
 	_fios_path = _fios_scn_path;
 
-	return FiosGetFileList(num, mode, &FiosGetScenarioListCallback);
+	return FiosGetFileList(mode, &FiosGetScenarioListCallback);
 }
--- a/fios.h	Sat Aug 05 00:53:09 2006 +0000
+++ b/fios.h	Sat Aug 05 00:59:45 2006 +0000
@@ -3,6 +3,50 @@
 #ifndef FIOS_H
 #define FIOS_H
 
+/* Deals with finding savegames */
+typedef struct {
+	byte type;
+	uint64 mtime;
+	char title[64];
+	char name[256 - 12 - 64];
+} FiosItem;
+
+enum {
+	FIOS_TYPE_DRIVE = 0,
+	FIOS_TYPE_PARENT = 1,
+	FIOS_TYPE_DIR = 2,
+	FIOS_TYPE_FILE = 3,
+	FIOS_TYPE_OLDFILE = 4,
+	FIOS_TYPE_SCENARIO = 5,
+	FIOS_TYPE_OLD_SCENARIO = 6,
+	FIOS_TYPE_DIRECT = 7,
+	FIOS_TYPE_INVALID = 255,
+};
+
+/* Variables to display file lists */
+extern FiosItem *_fios_list; // defined in misc_gui.c
+extern int _fios_num;        // defined in fios.c, read_only version of _fios_count
+extern int _saveload_mode;   // defined in misc_gui.c
+
+// Get a list of savegames
+FiosItem *FiosGetSavegameList(int mode);
+// Get a list of scenarios
+FiosItem *FiosGetScenarioList(int mode);
+// Free the list of savegames
+void FiosFreeSavegameList(void);
+// Browse to. Returns a filename w/path if we reached a file.
+char *FiosBrowseTo(const FiosItem *item);
+// Return path, free space and stringID
+StringID FiosGetDescText(const char **path, uint32 *total_free);
+// Delete a name
+bool FiosDelete(const char *name);
+// Make a filename from a name
+void FiosMakeSavegameName(char *buf, const char *name, size_t size);
+// Allocate a new FiosItem
+FiosItem *FiosAlloc(void);
+
+int CDECL compare_FiosItems(const void *a, const void *b);
+
 /* Implementation of opendir/readdir/closedir for Windows */
 #if defined(WIN32)
 #include <windows.h>
--- a/hal.h	Sat Aug 05 00:53:09 2006 +0000
+++ b/hal.h	Sat Aug 05 00:59:45 2006 +0000
@@ -44,55 +44,6 @@
 
 void GameLoop(void);
 
-
-// Deals with finding savegames
-typedef struct {
-	byte type;
-	uint64 mtime;
-	char title[64];
-	char name[256-12-64];
-} FiosItem;
-
-enum {
-	FIOS_TYPE_DRIVE = 0,
-	FIOS_TYPE_PARENT = 1,
-	FIOS_TYPE_DIR = 2,
-	FIOS_TYPE_FILE = 3,
-	FIOS_TYPE_OLDFILE = 4,
-	FIOS_TYPE_SCENARIO = 5,
-	FIOS_TYPE_OLD_SCENARIO = 6,
-	FIOS_TYPE_DIRECT = 7,
-	FIOS_TYPE_INVALID = 255,
-};
-
-
-// Variables to display file lists
-FiosItem *_fios_list;
-int _fios_num;
-int _saveload_mode;
-
-// get the name of an oldstyle savegame
-void GetOldSaveGameName(char *title, const char *path, const char *file);
-
-// Get a list of savegames
-FiosItem *FiosGetSavegameList(int *num, int mode);
-// Get a list of scenarios
-FiosItem *FiosGetScenarioList(int *num, int mode);
-// Free the list of savegames
-void FiosFreeSavegameList(void);
-// Browse to. Returns a filename w/path if we reached a file.
-char *FiosBrowseTo(const FiosItem *item);
-// Return path, free space and stringID
-StringID FiosGetDescText(const char **path, uint32 *tot);
-// Delete a name
-bool FiosDelete(const char *name);
-// Make a filename from a name
-void FiosMakeSavegameName(char *buf, const char *name, size_t size);
-// Allocate a new FiosItem
-FiosItem *FiosAlloc(void);
-
-int CDECL compare_FiosItems(const void *a, const void *b);
-
 void CreateConsole(void);
 
 #if defined(WIN32) || defined(WIN64) || defined(__WATCOMC__)
--- a/misc_gui.c	Sat Aug 05 00:53:09 2006 +0000
+++ b/misc_gui.c	Sat Aug 05 00:59:45 2006 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "hal.h"
 #include "debug.h"
 #include "functions.h"
 #include "gfxinit.h"
@@ -26,7 +27,10 @@
 #include "vehicle.h"
 #include "train.h"
 
-#include "hal.h" // for file list
+#include "fios.h"
+/* Variables to display file lists */
+FiosItem *_fios_list;
+int _saveload_mode;
 
 static bool _fios_path_changed;
 static bool _savegame_sort_dirty;
@@ -1160,16 +1164,14 @@
 {
 	_fios_path_changed = true;
 	FiosFreeSavegameList();
+
 	switch (_saveload_mode) {
 		case SLD_NEW_GAME:
 		case SLD_LOAD_SCENARIO:
 		case SLD_SAVE_SCENARIO:
-			_fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode);
-			break;
+			_fios_list = FiosGetScenarioList(_saveload_mode); break;
 
-		default:
-			_fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode);
-			break;
+		default: _fios_list = FiosGetSavegameList(_saveload_mode); break;
 	}
 }
 
--- a/network_gui.c	Sat Aug 05 00:53:09 2006 +0000
+++ b/network_gui.c	Sat Aug 05 00:59:45 2006 +0000
@@ -7,7 +7,7 @@
 #include "table/sprites.h"
 #include "network.h"
 
-#include "hal.h" // for file list
+#include "fios.h"
 
 #ifdef ENABLE_NETWORK
 
--- a/os2.c	Sat Aug 05 00:53:09 2006 +0000
+++ b/os2.c	Sat Aug 05 00:59:45 2006 +0000
@@ -2,7 +2,6 @@
 
 #include "stdafx.h"
 #include "openttd.h"
-#include "hal.h"
 #include "variables.h"
 #include "string.h"
 #include "table/strings.h"
@@ -24,11 +23,7 @@
 #include <os2.h>
 #include <i86.h>
 
-extern char *_fios_path;
-extern FiosItem *_fios_items;
-extern int _fios_count, _fios_alloc;
-
-bool FioIsRoot(const char *path)
+bool FiosIsRoot(const char *file)
 {
 	return path[3] == '\0';
 }
--- a/unix.c	Sat Aug 05 00:53:09 2006 +0000
+++ b/unix.c	Sat Aug 05 00:59:45 2006 +0000
@@ -6,7 +6,6 @@
 #include "window.h"
 #include "string.h"
 #include "table/strings.h"
-#include "hal.h"
 #include "variables.h"
 
 #include <dirent.h>
@@ -48,9 +47,6 @@
 		#include <SDL.h>
 	#endif
 #endif
-extern char *_fios_path;
-extern FiosItem *_fios_items;
-extern int _fios_count, _fios_alloc;
 
 bool FiosIsRoot(const char *path)
 {
--- a/win32.c	Sat Aug 05 00:53:09 2006 +0000
+++ b/win32.c	Sat Aug 05 00:59:45 2006 +0000
@@ -4,7 +4,6 @@
 #include "openttd.h"
 #include "debug.h"
 #include "functions.h"
-#include "hal.h"
 #include "macros.h"
 #include "saveload.h"
 #include "string.h"
@@ -706,10 +705,6 @@
 	return 0;
 }
 
-extern char *_fios_path;
-extern FiosItem *_fios_items;
-extern int _fios_count, _fios_alloc;
-
 bool FiosIsRoot(const char *file)
 {
 	return file[3] == '\0'; // C:\...