changeset 9031:9c6b04429f26 draft

(svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
author peter1138 <peter1138@openttd.org>
date Wed, 23 Apr 2008 12:03:47 +0000
parents 17520dee2ed1
children e95cf3676a54
files src/fios.cpp src/fios.h src/misc_gui.cpp
diffstat 3 files changed, 45 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -152,6 +152,10 @@
 			snprintf(str_buffr, lengthof(str_buffr), "%s%s", path, item->name);
 			return str_buffr;
 		}
+
+		case FIOS_TYPE_DRIVE:
+		case FIOS_TYPE_INVALID:
+			break;
 	}
 
 	return NULL;
@@ -208,13 +212,13 @@
 #endif
 }
 
-typedef byte fios_getlist_callback_proc(int mode, const char *filename, const char *ext, char *title);
+typedef FiosType fios_getlist_callback_proc(SaveLoadDialogMode mode, const char *filename, const char *ext, char *title);
 
 /** Create a list of the files in a directory, according to some arbitrary rule.
  *  @param mode The mode we are in. Some modes don't allow 'parent'.
  *  @param callback_proc The function that is called where you need to do the filtering.
  *  @return Return the list of files. */
-static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_proc)
+static FiosItem *FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc)
 {
 	struct stat sb;
 	struct dirent *dirent;
@@ -277,7 +281,7 @@
 			if ((t = strrchr(d_name, '.')) == NULL) continue;
 			fios_title[0] = '\0'; // reset the title;
 
-			byte type = callback_proc(mode, d_name, t, fios_title);
+			FiosType type = callback_proc(mode, d_name, t, fios_title);
 			if (type != FIOS_TYPE_INVALID) {
 				fios = FiosAlloc();
 				fios->mtime = sb.st_mtime;
@@ -313,7 +317,7 @@
  * @see FiosGetFileList
  * @see FiosGetSavegameList
  */
-static byte FiosGetSavegameListCallback(int mode, const char *file, const char *ext, char *title)
+static FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
 {
 	/* Show savegame files
 	 * .SAV OpenTTD saved game
@@ -339,16 +343,16 @@
  * @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 mode)
+FiosItem *FiosGetSavegameList(SaveLoadDialogMode mode)
 {
-	static char *_fios_save_path = NULL;
+	static char *fios_save_path = NULL;
 
-	if (_fios_save_path == NULL) {
-		_fios_save_path = MallocT<char>(MAX_PATH);
-		FioGetDirectory(_fios_save_path, MAX_PATH, SAVE_DIR);
+	if (fios_save_path == NULL) {
+		fios_save_path = MallocT<char>(MAX_PATH);
+		FioGetDirectory(fios_save_path, MAX_PATH, SAVE_DIR);
 	}
 
-	_fios_path = _fios_save_path;
+	_fios_path = fios_save_path;
 
 	return FiosGetFileList(mode, &FiosGetSavegameListCallback);
 }
@@ -363,7 +367,7 @@
  * @see FiosGetFileList
  * @see FiosGetScenarioList
  */
-static byte FiosGetScenarioListCallback(int mode, const char *file, const char *ext, char *title)
+static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
 {
 	/* Show scenario files
 	 * .SCN OpenTTD style scenario file
@@ -387,22 +391,22 @@
  * @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 mode)
+FiosItem *FiosGetScenarioList(SaveLoadDialogMode mode)
 {
-	static char *_fios_scn_path = NULL;
+	static char *fios_scn_path = NULL;
 
 	/* Copy the default path on first run or on 'New Game' */
-	if (_fios_scn_path == NULL) {
-		_fios_scn_path = MallocT<char>(MAX_PATH);
-		FioGetDirectory(_fios_scn_path, MAX_PATH, SCENARIO_DIR);
+	if (fios_scn_path == NULL) {
+		fios_scn_path = MallocT<char>(MAX_PATH);
+		FioGetDirectory(fios_scn_path, MAX_PATH, SCENARIO_DIR);
 	}
 
-	_fios_path = _fios_scn_path;
+	_fios_path = fios_scn_path;
 
 	return FiosGetFileList(mode, &FiosGetScenarioListCallback);
 }
 
-static byte FiosGetHeightmapListCallback(int mode, const char *file, const char *ext, char *title)
+static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
 {
 	/* Show heightmap files
 	 * .PNG PNG Based heightmap files
@@ -419,16 +423,16 @@
 }
 
 /* Get a list of Heightmaps */
-FiosItem *FiosGetHeightmapList(int mode)
+FiosItem *FiosGetHeightmapList(SaveLoadDialogMode mode)
 {
-	static char *_fios_hmap_path = NULL;
+	static char *fios_hmap_path = NULL;
 
-	if (_fios_hmap_path == NULL) {
-		_fios_hmap_path = MallocT<char>(MAX_PATH);
-		FioGetDirectory(_fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
+	if (fios_hmap_path == NULL) {
+		fios_hmap_path = MallocT<char>(MAX_PATH);
+		FioGetDirectory(fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
 	}
 
-	_fios_path = _fios_hmap_path;
+	_fios_path = fios_hmap_path;
 
 	return FiosGetFileList(mode, &FiosGetHeightmapListCallback);
 }
--- a/src/fios.h
+++ b/src/fios.h
@@ -42,23 +42,23 @@
 	FT_HEIGHTMAP, ///< heightmap file
 };
 
-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_PNG          =   8,
-	FIOS_TYPE_BMP          =   9,
-	FIOS_TYPE_INVALID      = 255,
+enum FiosType {
+	FIOS_TYPE_DRIVE,
+	FIOS_TYPE_PARENT,
+	FIOS_TYPE_DIR,
+	FIOS_TYPE_FILE,
+	FIOS_TYPE_OLDFILE,
+	FIOS_TYPE_SCENARIO,
+	FIOS_TYPE_OLD_SCENARIO,
+	FIOS_TYPE_DIRECT,
+	FIOS_TYPE_PNG,
+	FIOS_TYPE_BMP,
+	FIOS_TYPE_INVALID = 255,
 };
 
 /* Deals with finding savegames */
 struct FiosItem {
-	byte type;
+	FiosType type;
 	uint64 mtime;
 	char title[64];
 	char name[256 - 12 - 64];
@@ -82,11 +82,11 @@
 void ShowSaveLoadDialog(SaveLoadDialogMode mode);
 
 /* Get a list of savegames */
-FiosItem *FiosGetSavegameList(int mode);
+FiosItem *FiosGetSavegameList(SaveLoadDialogMode mode);
 /* Get a list of scenarios */
-FiosItem *FiosGetScenarioList(int mode);
+FiosItem *FiosGetScenarioList(SaveLoadDialogMode mode);
 /* Get a list of Heightmaps */
-FiosItem *FiosGetHeightmapList(int mode);
+FiosItem *FiosGetHeightmapList(SaveLoadDialogMode mode);
 /* Free the list of savegames */
 void FiosFreeSavegameList();
 /* Browse to. Returns a filename w/path if we reached a file. */
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -1455,6 +1455,7 @@
 			case FIOS_TYPE_DIR:    sort_start++; break;
 			case FIOS_TYPE_PARENT: sort_start++; break;
 			case FIOS_TYPE_DRIVE:  sort_end++;   break;
+			default: break;
 		}
 	}