(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

This commit is contained in:
Darkvater 2006-08-05 00:59:45 +00:00
parent 198f6caf20
commit a9251d2d02
9 changed files with 68 additions and 83 deletions

View File

@ -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 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
}
// XXX - Workaround for broken file handling
FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME);
FiosGetSavegameList(SLD_LOAD_GAME);
FiosFreeSavegameList();
FiosGetDescText(&path, NULL);

22
fios.c
View File

@ -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 @@ typedef byte fios_getlist_callback_proc(int mode, const char *filename, const ch
* @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 @@ static FiosItem *FiosGetFileList(int *num, int mode, fios_getlist_callback_proc
/* Show drives */
if (mode != SLD_NEW_GAME) FiosGetDrives();
*num = _fios_count;
_fios_num = _fios_count;
return _fios_items;
}
@ -305,7 +307,7 @@ static byte FiosGetSavegameListCallback(int mode, const char *file, const char *
* @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 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
_fios_path = _fios_save_path;
return FiosGetFileList(num, mode, &FiosGetSavegameListCallback);
return FiosGetFileList(mode, &FiosGetSavegameListCallback);
}
/**
@ -353,7 +355,7 @@ static byte FiosGetScenarioListCallback(int mode, const char *file, const char *
* @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 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
_fios_path = _fios_scn_path;
return FiosGetFileList(num, mode, &FiosGetScenarioListCallback);
return FiosGetFileList(mode, &FiosGetScenarioListCallback);
}

44
fios.h
View File

@ -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>

49
hal.h
View File

@ -44,55 +44,6 @@ enum DriverType {
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__)

View File

@ -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 @@ void BuildFileList(void)
{
_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;
}
}

View File

@ -7,7 +7,7 @@
#include "table/sprites.h"
#include "network.h"
#include "hal.h" // for file list
#include "fios.h"
#ifdef ENABLE_NETWORK

7
os2.c
View File

@ -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';
}

4
unix.c
View File

@ -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 @@ ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
#include <SDL.h>
#endif
#endif
extern char *_fios_path;
extern FiosItem *_fios_items;
extern int _fios_count, _fios_alloc;
bool FiosIsRoot(const char *path)
{

View File

@ -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 @@ int closedir(DIR *d)
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:\...