filesystem: refactor variable declarations

This commit is contained in:
Alibek Omarov
2026-05-19 21:10:29 +05:00
committed by a1batross
parent c5fbc98d16
commit 37d9791f00
10 changed files with 190 additions and 276 deletions

View File

@@ -175,12 +175,8 @@ public:
FileHandle_t Open( const char *path, const char *mode, const char *id ) override
{
file_t *fd;
FixupPath( p, path );
fd = FS_Open( p, mode, IsIdGamedir( id ));
return fd;
return FS_Open( p, mode, IsIdGamedir( id ));
}
void Close( FileHandle_t handle ) override
@@ -304,19 +300,16 @@ public:
const char *FindFirst( const char *pattern, FileFindHandle_t *handle, const char *id ) override
{
CSearchState *state;
search_t *search;
if( !handle || !pattern )
return nullptr;
FixupPath( p, pattern );
search = FS_Search( p, true, IsIdGamedir( id ));
search_t *search = FS_Search( p, true, IsIdGamedir( id ));
if( !search )
return nullptr;
state = new CSearchState( &searchHead, search );
CSearchState *state = new CSearchState( &searchHead, search );
if( !state )
{
Mem_Free( search );
@@ -378,8 +371,6 @@ public:
const char *GetLocalPath( const char *name, char *buf, int size ) override
{
const char *fullpath;
if( !name )
return nullptr;
@@ -396,7 +387,7 @@ public:
return buf;
}
fullpath = FS_GetDiskPath( p, false );
const char *fullpath = FS_GetDiskPath( p, false );
if( !fullpath )
return nullptr;
@@ -407,10 +398,8 @@ public:
char *ParseFile( char *buf, char *token, bool *quoted ) override
{
qboolean qquoted;
char *p;
// filesystem_stdio expects 512 byte buffers
p = COM_ParseFileSafe( buf, token, 512, 0, nullptr, &qquoted );
char *p = COM_ParseFileSafe( buf, token, 512, 0, nullptr, &qquoted );
if( quoted )
*quoted = qquoted;

View File

@@ -55,9 +55,7 @@ struct jni_methods_s
static void Android_GetAssetManager( android_assets_t *assets )
{
jobject assetManager;
assetManager = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getAssets, assets->engine );
jobject assetManager = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getAssets, assets->engine );
if( assetManager )
assets->asset_manager = AAssetManager_fromJava( jni.env, assetManager );
@@ -68,11 +66,9 @@ static void Android_GetAssetManager( android_assets_t *assets )
static const char *Android_GetPackageName( qboolean engine )
{
static string pkg;
jstring resultJNIStr;
jstring resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, engine ? jni.getPackageName : jni.getCallingPackage );
const char *resultCStr;
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, engine ? jni.getPackageName : jni.getCallingPackage );
if( !resultJNIStr )
return NULL;
@@ -144,7 +140,6 @@ static int FS_FileTime_AndroidAssets( searchpath_t *search, const char *filename
if( !time )
{
struct tm file_tm;
strptime( g_buildcommit_date, "%Y-%m-%d %H:%M:%S", &file_tm );
time = mktime( &file_tm );
}
@@ -181,15 +176,13 @@ static void FS_Search_AndroidAssets( searchpath_t *search, stringlist_t *list, c
{
string temp;
stringlist_t dirlist;
const char *slash, *backslash, *colon, *separator;
int basepathlength, dirlistindex, resultlistindex;
const char *slash = Q_strrchr( pattern, '/' );
const char *backslash = Q_strrchr( pattern, '\\' );
const char *colon = Q_strrchr( pattern, ':' );
const char *separator = Q_max( slash, backslash );
int basepathlength, dirlistindex;
char *basepath;
slash = Q_strrchr( pattern, '/' );
backslash = Q_strrchr( pattern, '\\' );
colon = Q_strrchr( pattern, ':' );
separator = Q_max( slash, backslash );
separator = Q_max( separator, colon );
basepathlength = separator ? (separator + 1 - pattern) : 0;
@@ -209,6 +202,8 @@ static void FS_Search_AndroidAssets( searchpath_t *search, stringlist_t *list, c
if( matchpattern( temp, (char *)pattern, true ))
{
int resultlistindex;
for( resultlistindex = 0; resultlistindex < list->numstrings; resultlistindex++ )
{
if( !Q_strcmp( list->strings[resultlistindex], temp ))
@@ -245,11 +240,10 @@ static byte *FS_LoadAndroidAssetsFile( searchpath_t *search, const char *path, i
{
byte *buf;
off_t size;
AAsset *asset;
AAsset *asset = AAssetManager_open( search->assets->asset_manager, path, AASSET_MODE_BUFFER );
if( filesize ) *filesize = 0;
asset = AAssetManager_open( search->assets->asset_manager, path, AASSET_MODE_BUFFER );
if( !asset )
return NULL;

View File

@@ -65,9 +65,8 @@ static qboolean Platform_GetDirectoryCaseSensitivity( const char *dir )
return true;
#elif XASH_LINUX && defined( FS_IOC_GETFLAGS )
int flags = 0;
int fd;
int fd = open( dir, O_RDONLY | O_NONBLOCK );
fd = open( dir, O_RDONLY | O_NONBLOCK );
if( fd < 0 )
return true;
@@ -96,8 +95,7 @@ static void FS_FreeDirEntries( dir_t *dir )
{
if( dir->entries )
{
int i;
for( i = 0; i < dir->numentries; i++ )
for( int i = 0; i < dir->numentries; i++ )
FS_FreeDirEntries( &dir->entries[i] );
dir->entries = NULL;
}
@@ -107,12 +105,10 @@ static void FS_FreeDirEntries( dir_t *dir )
static void FS_InitDirEntries( dir_t *dir, const stringlist_t *list )
{
int i;
dir->numentries = list->numstrings;
dir->entries = Mem_Malloc( fs_mempool, sizeof( dir_t ) * dir->numentries );
for( i = 0; i < list->numstrings; i++ )
for( int i = 0; i < list->numstrings; i++ )
{
dir_t *entry = &dir->entries[i];
@@ -158,18 +154,14 @@ static void FS_PopulateDirEntries( dir_t *dir, const char *path )
static int FS_FindDirEntry( dir_t *dir, const char *name )
{
int left, right;
// look for the file (binary search)
left = 0;
right = dir->numentries - 1;
int left = 0;
int right = dir->numentries - 1;
while( left <= right )
{
int middle = (left + right) / 2;
int diff;
diff = Q_stricmp( dir->entries[middle].name, name );
int diff = Q_stricmp( dir->entries[middle].name, name );
// found it
if( !diff )
@@ -185,7 +177,6 @@ static int FS_FindDirEntry( dir_t *dir, const char *name )
static void FS_MergeDirEntries( dir_t *dir, const stringlist_t *list )
{
int i;
dir_t temp;
// glorified realloc for sorted dir entries
@@ -194,7 +185,7 @@ static void FS_MergeDirEntries( dir_t *dir, const stringlist_t *list )
FS_InitDirEntries( &temp, list );
for( i = 0; i < dir->numentries; i++ )
for( int i = 0; i < dir->numentries; i++ )
{
dir_t *oldentry = &dir->entries[i];
dir_t *newentry;
@@ -417,15 +408,13 @@ static void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char
{
string netpath, temp;
stringlist_t dirlist;
const char *slash, *backslash, *colon, *separator;
int basepathlength, dirlistindex, resultlistindex;
const char *slash = Q_strrchr( pattern, '/' );
const char *backslash = Q_strrchr( pattern, '\\' );
const char *colon = Q_strrchr( pattern, ':' );
const char *separator = Q_max( slash, backslash );
int basepathlength, dirlistindex;
char *basepath;
slash = Q_strrchr( pattern, '/' );
backslash = Q_strrchr( pattern, '\\' );
colon = Q_strrchr( pattern, ':' );
separator = Q_max( slash, backslash );
separator = Q_max( separator, colon );
basepathlength = separator ? (separator + 1 - pattern) : 0;
@@ -450,6 +439,8 @@ static void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char
if( matchpattern( temp, (char *)pattern, true ) )
{
int resultlistindex;
for( resultlistindex = 0; resultlistindex < list->numstrings; resultlistindex++ )
{
if( !Q_strcmp( list->strings[resultlistindex], temp ) )
@@ -476,8 +467,8 @@ static int FS_FileTime_DIR( searchpath_t *search, const char *filename )
static file_t *FS_OpenFile_DIR( searchpath_t *search, const char *filename, const char *mode, int pack_ind )
{
file_t *f;
char path[MAX_SYSPATH];
file_t *f;
Q_snprintf( path, sizeof( path ), "%s%s", search->filename, filename );
f = FS_SysOpen( path, mode );
@@ -515,9 +506,8 @@ void FS_InitDirectorySearchpath( searchpath_t *search, const char *path, int fla
searchpath_t *FS_AddDir_Fullpath( const char *path, int flags )
{
searchpath_t *search;
searchpath_t *search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
FS_InitDirectorySearchpath( search, path, flags );
Con_Printf( "Adding directory: %s\n", path );

View File

@@ -40,7 +40,7 @@ assume GameInfo is valid
static qboolean FS_WriteGameInfo( const char *filepath, const gameinfo_t *GameInfo )
{
file_t *f = FS_Open( filepath, "w", false ); // we in binary-mode
int i, write_ambients = false;
int write_ambients = false;
if( !f )
return false;
@@ -128,7 +128,7 @@ static qboolean FS_WriteGameInfo( const char *filepath, const gameinfo_t *GameIn
if( GameInfo->max_particles > 0 )
FS_Printf( f, "max_particles\t%i\n", GameInfo->max_particles );
for( i = 0; i < NUM_AMBIENTS; i++ )
for( int i = 0; i < NUM_AMBIENTS; i++ )
{
if( *GameInfo->ambientsound[i] )
{
@@ -569,10 +569,9 @@ static qboolean FS_CheckForQuakeGameDir( const char *gamedir )
// if directory contain quake.rc or progs.dat it's 100% quake gamedir
// quake mods probably always archived, so check pak0.pak too
const char *files[] = { "pak0.pak", "PAK0.PAK", "progs.dat", "quake.rc" };
int i;
// search it in the filesystem
for( i = 0; i < sizeof( files ) / sizeof( files[0] ); i++ )
for( int i = 0; i < sizeof( files ) / sizeof( files[0] ); i++ )
{
char buf[MAX_SYSPATH];
@@ -607,9 +606,8 @@ static qboolean FS_CheckForXashGameDir( const char *gamedir )
{
// if directory contain gameinfo.txt or liblist.gam it's 100% gamedir
const char *files[] = { "gameinfo.txt", "liblist.gam" };
int i;
for( i = 0; i < sizeof( files ) / sizeof( files[0] ); i++ )
for( int i = 0; i < sizeof( files ) / sizeof( files[0] ); i++ )
{
char buf[MAX_SYSPATH];
@@ -633,8 +631,8 @@ qboolean FS_ParseGameInfo( const char *gamedir, gameinfo_t *GameInfo, qboolean r
char liblist_path[MAX_SYSPATH];
char gameinfo_path[MAX_SYSPATH];
char gamedir_path[MAX_SYSPATH];
time_t liblist_mtime = -1;
time_t gameinfo_mtime = -1;
time_t liblist_mtime;
time_t gameinfo_mtime;
if( rodir )
Q_snprintf( gamedir_path, sizeof( gamedir_path ), "%s/%s", fs_rodir, gamedir );

View File

@@ -62,11 +62,9 @@ Look for a file in the search paths and open it in read-only mode
*/
file_t *FS_OpenReadFile( const char *filename, const char *mode, qboolean gamedironly )
{
searchpath_t *search;
char netpath[MAX_SYSPATH];
int pack_ind;
search = FS_FindFile( filename, &pack_ind, netpath, sizeof( netpath ), gamedironly ? FS_GAMEDIRONLY_SEARCH_FLAGS : 0 );
searchpath_t *search = FS_FindFile( filename, &pack_ind, netpath, sizeof( netpath ), gamedironly ? FS_GAMEDIRONLY_SEARCH_FLAGS : 0 );
// not found?
if( search == NULL )
@@ -636,11 +634,11 @@ FS_LoadFileFromArchive
*/
byte *FS_LoadFileFromArchive( searchpath_t *sp, const char *path, int pack_ind, fs_offset_t *filesizeptr, const qboolean sys_malloc )
{
void *( *pfnAlloc )( size_t ) = sys_malloc ? malloc : FS_CustomAlloc;
void ( *pfnFree )( void * ) = sys_malloc ? free : FS_CustomFree;
fs_offset_t filesize;
file_t *file;
byte *buf;
void *( *pfnAlloc )( size_t ) = sys_malloc ? malloc : FS_CustomAlloc;
void ( *pfnFree )( void * ) = sys_malloc ? free : FS_CustomFree;
// custom load file function for compressed files
if( sp->pfnLoadFile )
@@ -679,9 +677,9 @@ Always appends a 0 byte.
*/
static byte *FS_LoadFile_( const char *path, fs_offset_t *filesizeptr, const qboolean gamedironly, const qboolean custom_alloc )
{
searchpath_t *search;
char netpath[MAX_SYSPATH];
int pack_ind;
searchpath_t *search;
// some mappers used leading '/' or '\' in path to models or sounds
if( path[0] == '/' || path[0] == '\\' )
@@ -720,17 +718,15 @@ CRC32_File
qboolean CRC32_File( dword *crcvalue, const char *filename )
{
char buffer[1024];
int num_bytes;
file_t *f;
file_t *f = FS_Open( filename, "rb", false );
f = FS_Open( filename, "rb", false );
if( !f ) return false;
CRC32_Init( crcvalue );
while( 1 )
{
num_bytes = FS_Read( f, buffer, sizeof( buffer ));
int num_bytes = FS_Read( f, buffer, sizeof( buffer ));
if( num_bytes > 0 )
CRC32_ProcessBuffer( crcvalue, buffer, num_bytes );
@@ -750,10 +746,10 @@ MD5_HashFile
*/
qboolean MD5_HashFile( byte digest[16], const char *pszFileName, uint seed[4] )
{
file_t *file;
file_t *file = FS_Open( pszFileName, "rb", false );
MD5Context_t MD5_Hash = { 0 };
if(( file = FS_Open( pszFileName, "rb", false )) == NULL )
if( !file )
return false;
MD5Init( &MD5_Hash );
@@ -787,11 +783,9 @@ FS_LoadDirectFile
*/
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr )
{
file_t *file;
byte *buf = NULL;
fs_offset_t filesize = 0;
file = FS_SysOpen( path, "rb" );
file_t *file = FS_SysOpen( path, "rb" );
fs_offset_t filesize;
byte *buf;
if( !file )
return NULL;
@@ -819,9 +813,7 @@ The filename will be prefixed by the current game directory
*/
qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len )
{
file_t *file;
file = FS_Open( filename, "wb", false );
file_t *file = FS_Open( filename, "wb", false );
if( !file )
{
@@ -875,10 +867,8 @@ return false for file in pack
*/
qboolean FS_GetFullDiskPath( char *buffer, size_t size, const char *name, qboolean gamedironly )
{
searchpath_t *search;
char temp[MAX_SYSPATH];
search = FS_FindFile( name, NULL, temp, sizeof( temp ), gamedironly ? FS_GAMEDIRONLY_SEARCH_FLAGS : 0 );
searchpath_t *search = FS_FindFile( name, NULL, temp, sizeof( temp ), gamedironly ? FS_GAMEDIRONLY_SEARCH_FLAGS : 0 );
if( search && search->type == SEARCHPATH_PLAIN )
{
@@ -899,9 +889,7 @@ return size of file in bytes
fs_offset_t FS_FileSize( const char *filename, qboolean gamedironly )
{
int length = -1; // in case file was missed
file_t *fp;
fp = FS_Open( filename, "rb", gamedironly );
file_t *fp = FS_Open( filename, "rb", gamedironly );
if( fp )
{
@@ -936,11 +924,10 @@ return time of creation file in seconds
*/
int FS_FileTime( const char *filename, qboolean gamedironly )
{
searchpath_t *search;
char netpath[MAX_SYSPATH];
int pack_ind;
searchpath_t *search = FS_FindFile( filename, &pack_ind, netpath, sizeof( netpath ), gamedironly ? FS_GAMEDIRONLY_SEARCH_FLAGS : 0 );
search = FS_FindFile( filename, &pack_ind, netpath, sizeof( netpath ), gamedironly ? FS_GAMEDIRONLY_SEARCH_FLAGS : 0 );
if( !search )
return -1; // doesn't exist

View File

@@ -98,17 +98,15 @@ of the list so they override previous pack files.
static pack_t *FS_LoadPackPAK( const char *packfile, int *error )
{
dpackheader_t header;
file_t *packhandle;
int numpackfiles;
pack_t *pack;
fs_size_t c;
int i;
// TODO: use FS_Open to allow PK3 to be included into other archives
// Currently, it doesn't work with rodir due to FS_FindFile logic
// when it will use FS_Open, check that FS_CheckForQuakePak correctly
// detects Quake gamedirs in RoDir
packhandle = FS_SysOpen( packfile, "rb" );
file_t *packhandle = FS_SysOpen( packfile, "rb" );
if( packhandle == NULL )
{
@@ -170,7 +168,7 @@ static pack_t *FS_LoadPackPAK( const char *packfile, int *error )
return NULL;
}
for( i = 0; i < numpackfiles; i++ )
for( int i = 0; i < numpackfiles; i++ )
{
pack->files[i].filepos = LittleLong( pack->files[i].filepos );
pack->files[i].filelen = LittleLong( pack->files[i].filelen );
@@ -203,9 +201,7 @@ Open a packed file using its package file descriptor
*/
static file_t *FS_OpenFile_PAK( searchpath_t *search, const char *filename, const char *mode, int pack_ind )
{
dpackfile_t *pfile;
pfile = &search->pack->files[pack_ind];
dpackfile_t *pfile = &search->pack->files[pack_ind];
return FS_OpenHandle( search, search->pack->handle->handle, pfile->filepos, pfile->filelen );
}
@@ -218,17 +214,14 @@ FS_FindFile_PAK
*/
static int FS_FindFile_PAK( searchpath_t *search, const char *path, char *fixedname, size_t len )
{
int left, right, middle;
// look for the file (binary search)
left = 0;
right = search->pack->numfiles - 1;
int left = 0;
int right = search->pack->numfiles - 1;
while( left <= right )
{
int diff;
middle = (left + right) / 2;
diff = Q_stricmp( search->pack->files[middle].name, path );
int middle = (left + right) / 2;
int diff = Q_stricmp( search->pack->files[middle].name, path );
// Found it
if( !diff )
@@ -256,16 +249,18 @@ FS_Search_PAK
static void FS_Search_PAK( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
{
string temp;
const char *slash, *backslash, *colon, *separator;
int j, i;
for( i = 0; i < search->pack->numfiles; i++ )
for( int i = 0; i < search->pack->numfiles; i++ )
{
Q_strncpy( temp, search->pack->files[i].name, sizeof( temp ));
while( temp[0] )
{
const char *slash, *backslash, *colon, *separator;
if( matchpattern( temp, pattern, true ))
{
int j;
for( j = 0; j < list->numstrings; j++ )
{
if( !Q_strcmp( list->strings[j], temp ))
@@ -348,10 +343,8 @@ plain directories.
searchpath_t *FS_AddPak_Fullpath( const char *pakfile, int flags )
{
searchpath_t *search;
pack_t *pak;
int errorcode = PAK_LOAD_COULDNT_OPEN;
pak = FS_LoadPackPAK( pakfile, &errorcode );
pack_t *pak = FS_LoadPackPAK( pakfile, &errorcode );
if( !pak )
{
@@ -389,14 +382,12 @@ and find progs.dat in it
qboolean FS_CheckForQuakePak( const char *pakfile, const char *files[], size_t num_files )
{
qboolean is_quake = false;
pack_t *pak;
int i;
pack_t *pak = FS_LoadPackPAK( pakfile, NULL );
pak = FS_LoadPackPAK( pakfile, NULL );
if( !pak )
return false;
for( i = 0; i < num_files; i++ )
for( int i = 0; i < num_files; i++ )
{
int j;

View File

@@ -95,10 +95,9 @@ static searchpath_t *FS_AddArchive_Fullpath( const fs_archive_t *archive, const
if( !archive )
{
int i;
const char *ext = COM_FileExtension( file );
for( i = 0; i < sizeof( g_archives ) / sizeof( g_archives[0] ); i++ )
for( int i = 0; i < sizeof( g_archives ) / sizeof( g_archives[0] ); i++ )
{
if( !Q_stricmp( g_archives[i].ext, ext ))
{
@@ -140,7 +139,6 @@ static searchpath_t *FS_AddArchive_Fullpath( const fs_archive_t *archive, const
if( archive->load_wads && !FBitSet( flags, FS_SKIP_ARCHIVED_WADS ))
{
stringlist_t list;
int i;
stringlistinit( &list );
search->pfnSearch( search, &list, "*.wad", true );
@@ -150,7 +148,7 @@ static searchpath_t *FS_AddArchive_Fullpath( const fs_archive_t *archive, const
ClearBits( flags, FS_EXEC_PATH );
SetBits( flags, FS_NOWRITE_PATH );
for( i = 0; i < list.numstrings; i++ )
for( int i = 0; i < list.numstrings; i++ )
{
searchpath_t *wad;
char fullpath[MAX_SYSPATH];
@@ -192,18 +190,16 @@ void FS_AddGameDirectory( const char *dir, uint flags )
{
stringlist_t list;
searchpath_t *search;
int j;
stringlistinit( &list );
listdirectory( &list, dir, false );
stringlistsort( &list );
for( j = 0; j < sizeof( g_archives ) / sizeof( g_archives[0] ); j++ )
for( int j = 0; j < sizeof( g_archives ) / sizeof( g_archives[0] ); j++ )
{
char fullpath[MAX_SYSPATH];
int i;
for( i = 0; i < list.numstrings; i++ )
for( int i = 0; i < list.numstrings; i++ )
{
if( Q_stricmp( COM_FileExtension( list.strings[i] ), g_archives[j].ext ))
continue;
@@ -234,10 +230,7 @@ FS_ClearSearchPath
*/
void FS_ClearSearchPath( void )
{
searchpath_t *cur, **prev;
int i;
prev = &fs_searchpaths;
searchpath_t *cur, **prev = &fs_searchpaths;
while( true )
{
@@ -258,7 +251,7 @@ void FS_ClearSearchPath( void )
Mem_Free( cur );
}
for( i = 0; i < FI.numgames; i++ )
for( int i = 0; i < FI.numgames; i++ )
{
if( FI.games[i] )
FI.games[i]->added = false;
@@ -547,9 +540,9 @@ static qboolean FS_CheckForCrypt( const char *dllname )
static int FS_StripIdiotRelativePath( const char *dllname, const char *gamefolder )
{
string idiot_relpath;
int len;
int len = Q_snprintf( idiot_relpath, sizeof( idiot_relpath ), "../%s/", gamefolder );
if(( len = Q_snprintf( idiot_relpath, sizeof( idiot_relpath ), "../%s/", gamefolder )) >= 4 )
if( len >= 4 )
{
if( !Q_strnicmp( dllname, idiot_relpath, len ))
return len;
@@ -567,13 +560,12 @@ static int FS_StripIdiotRelativePath( const char *dllname, const char *gamefolde
static void FS_ValidateDirectories( const char *path, qboolean *has_base_dir, qboolean *has_game_dir )
{
stringlist_t dirs;
int i;
stringlistinit( &dirs );
listdirectory( &dirs, path, true );
stringlistsort( &dirs );
for( i = 0; i < dirs.numstrings; i++ )
for( int i = 0; i < dirs.numstrings; i++ )
{
if( !FS_SysFolderExists( dirs.strings[i] ))
continue;
@@ -599,7 +591,7 @@ FS_Init
qboolean FS_InitStdio( qboolean unused_set_to_true, const char *rootdir, const char *basedir, const char *gamedir, const char *rodir )
{
stringlist_t dirs;
int i, rodir_num_games;
int rodir_num_games;
char buf[MAX_SYSPATH];
FS_InitMemory();
@@ -663,7 +655,7 @@ qboolean FS_InitStdio( qboolean unused_set_to_true, const char *rootdir, const c
listdirectory( &dirs, fs_rodir, true );
stringlistsort( &dirs );
for( i = 0; i < dirs.numstrings; i++ )
for( int i = 0; i < dirs.numstrings; i++ )
{
Q_snprintf( buf, sizeof( buf ), "%s/%s", fs_rodir, dirs.strings[i] );
if( !FS_SysFolderExists( buf ))
@@ -685,7 +677,7 @@ qboolean FS_InitStdio( qboolean unused_set_to_true, const char *rootdir, const c
listdirectory( &dirs, "./", true );
stringlistsort( &dirs );
for( i = 0; i < dirs.numstrings; i++ )
for( int i = 0; i < dirs.numstrings; i++ )
{
int j;
@@ -735,10 +727,8 @@ FS_Shutdown
*/
void FS_ShutdownStdio( void )
{
int i;
// release gamedirs
for( i = 0; i < FI.numgames; i++ )
for( int i = 0; i < FI.numgames; i++ )
{
if( FI.games[i] )
{
@@ -761,11 +751,9 @@ debug info
*/
void FS_Path_f( void )
{
searchpath_t *s;
Con_Printf( "Current search path:\n" );
for( s = fs_searchpaths; s; s = s->next )
for( searchpath_t *s = fs_searchpaths; s; s = s->next )
{
string fl;
string info;
@@ -970,9 +958,7 @@ Converts full path to the relative path considering current searchpaths
*/
qboolean FS_FullPathToRelativePath( char *dst, const char *src, size_t size )
{
searchpath_t *sp;
for( sp = fs_searchpaths; sp; sp = sp->next )
for( searchpath_t *sp = fs_searchpaths; sp; sp = sp->next )
{
size_t splen = Q_strlen( sp->filename );
@@ -997,8 +983,7 @@ Allocate and fill a search structure with information on matching filenames.
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
{
search_t *search = NULL;
searchpath_t *searchpath;
int i, numfiles, numchars;
int numfiles, numchars;
stringlist_t resultlist;
if( pattern[0] == '.' || pattern[0] == ':' || pattern[0] == '/' || pattern[0] == '\\' )
@@ -1007,7 +992,7 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
stringlistinit( &resultlist );
// search through the path, one element at a time
for( searchpath = fs_searchpaths; searchpath; searchpath = searchpath->next )
for( searchpath_t *searchpath = fs_searchpaths; searchpath; searchpath = searchpath->next )
{
if( gamedironly && !FBitSet( searchpath->flags, FS_GAMEDIRONLY_SEARCH_FLAGS ))
continue;
@@ -1021,7 +1006,7 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
numfiles = resultlist.numstrings;
numchars = 0;
for( i = 0; i < resultlist.numstrings; i++ )
for( int i = 0; i < resultlist.numstrings; i++ )
numchars += (int)Q_strlen( resultlist.strings[i]) + 1;
search = Mem_Calloc( fs_mempool, sizeof(search_t) + numchars + numfiles * sizeof( char* ));
search->filenames = (char **)((char *)search + sizeof( search_t ));
@@ -1029,7 +1014,7 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
search->numfilenames = (int)numfiles;
numfiles = numchars = 0;
for( i = 0; i < resultlist.numstrings; i++ )
for( int i = 0; i < resultlist.numstrings; i++ )
{
size_t textlen;
@@ -1048,12 +1033,10 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
qboolean FS_IsArchiveExtensionSupported( const char *ext, uint flags )
{
int i;
if( ext == NULL )
return false;
for( i = 0; i < sizeof( g_archives ) / sizeof( g_archives[0] ); i++ )
for( int i = 0; i < sizeof( g_archives ) / sizeof( g_archives[0] ); i++ )
{
if( FBitSet( flags, IAES_ONLY_REAL_ARCHIVES ) && !g_archives[i].real_archive )
continue;

View File

@@ -84,9 +84,7 @@ void stringlistinit( stringlist_t *list )
void stringlistfreecontents( stringlist_t *list )
{
int i;
for( i = 0; i < list->numstrings; i++ )
for( int i = 0; i < list->numstrings; i++ )
{
if( list->strings[i] )
Mem_Free( list->strings[i] );
@@ -122,17 +120,14 @@ void stringlistappend( stringlist_t *list, const char *text )
void stringlistsort( stringlist_t *list )
{
char *temp;
int i, j;
// this is a selection sort (finds the best entry for each slot)
for( i = 0; i < list->numstrings - 1; i++ )
for( int i = 0; i < list->numstrings - 1; i++ )
{
for( j = i + 1; j < list->numstrings; j++ )
for( int j = i + 1; j < list->numstrings; j++ )
{
if( Q_strcmp( list->strings[i], list->strings[j] ) > 0 )
{
temp = list->strings[i];
char *temp = list->strings[i];
list->strings[i] = list->strings[j];
list->strings[j] = temp;
}
@@ -143,12 +138,9 @@ void stringlistsort( stringlist_t *list )
// convert names to lowercase because dos doesn't care, but pattern matching code often does
MAYBE_UNUSED static void listlowercase( stringlist_t *list )
{
char *c;
int i;
for( i = 0; i < list->numstrings; i++ )
for( int i = 0; i < list->numstrings; i++ )
{
for( c = list->strings[i]; *c; c++ )
for( char *c = list->strings[i]; *c; c++ )
*c = Q_tolower( *c );
}
}
@@ -231,14 +223,12 @@ Only used for FS_Open.
*/
void FS_CreatePath( char *path )
{
char *ofs, save;
for( ofs = path + 1; *ofs; ofs++ )
for( char *ofs = path + 1; *ofs; ofs++ )
{
if( *ofs == '/' || *ofs == '\\' )
{
// create the directory
save = *ofs;
char save = *ofs;
*ofs = 0;
#if XASH_WIN32
_mkdir( path ); // use _wmkdir maybe?

View File

@@ -95,13 +95,12 @@ Extracts file type from extension
static signed char W_TypeFromExt( const char *lumpname )
{
const char *ext = COM_FileExtension( lumpname );
int i;
// we not known about filetype, so match only by filename
if( !Q_strcmp( ext, "*" ) || COM_StringEmpty( ext ))
return TYP_ANY;
for( i = 0; i < sizeof( wad_types ) / sizeof( wad_types[0] ); i++ )
for( int i = 0; i < sizeof( wad_types ) / sizeof( wad_types[0] ); i++ )
{
if( !Q_stricmp( ext, wad_types[i].ext ))
return wad_types[i].type;
@@ -119,13 +118,11 @@ Convert type to extension
*/
static const char *W_ExtFromType( signed char lumptype )
{
int i;
// we not known aboyt filetype, so match only by filename
if( lumptype == TYP_NONE || lumptype == TYP_ANY )
return "";
for( i = 0; i < sizeof( wad_types ) / sizeof( wad_types[0] ); i++ )
for( int i = 0; i < sizeof( wad_types ) / sizeof( wad_types[0] ); i++ )
{
if( lumptype == wad_types[i].type )
return wad_types[i].ext;
@@ -186,12 +183,11 @@ and sort LAT in alpha-bethical order
*/
static dlumpinfo_t *W_AddFileToWad( const char *wadfile, const char *name, wfile_t *wad, dlumpinfo_t *newlump )
{
int left, right;
dlumpinfo_t *plump;
// look for the slot we should put that file into (binary search)
left = 0;
right = wad->numlumps - 1;
int left = 0;
int right = wad->numlumps - 1;
while( left <= right )
{
@@ -268,7 +264,7 @@ open the wad for reading & writing
static wfile_t *W_Open( const char *filename, int *error, uint flags )
{
wfile_t *wad = (wfile_t *)Mem_Calloc( fs_mempool, sizeof( wfile_t ));
int i, lumpcount;
int lumpcount;
dlumpinfo_t *srclumps;
size_t lat_size;
dwadinfo_t header;
@@ -355,7 +351,7 @@ static wfile_t *W_Open( const char *filename, int *error, uint flags )
return NULL;
}
for( i = 0; i < lumpcount; i++ )
for( int i = 0; i < lumpcount; i++ )
{
srclumps[i].filepos = LittleLong( srclumps[i].filepos );
srclumps[i].disksize = LittleLong( srclumps[i].disksize );
@@ -367,7 +363,7 @@ static wfile_t *W_Open( const char *filename, int *error, uint flags )
wad->numlumps = 0;
// sort lumps for binary search
for( i = 0; i < lumpcount; i++ )
for( int i = 0; i < lumpcount; i++ )
{
char name[16];
int k;
@@ -482,8 +478,6 @@ static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char
signed char type = W_TypeFromExt( pattern );
qboolean anywadname = true;
string wadfolder, temp;
int j, i;
const char *slash, *backslash, *colon, *separator;
char buf[MAX_VA_STRING];
// quick reject by filetype
@@ -513,7 +507,7 @@ static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char
if( !anywadname && Q_stricmp( wadname, temp2 ))
return;
for( i = 0; i < search->wad->numlumps; i++ )
for( int i = 0; i < search->wad->numlumps; i++ )
{
// if type not matching, we already have no chance ...
if( type != TYP_ANY && search->wad->lumps[i].type != type )
@@ -524,8 +518,12 @@ static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char
while( temp[0] )
{
const char *slash, *backslash, *colon, *separator;
if( matchpattern( temp, wadpattern, true ))
{
int j;
for( j = 0; j < list->numstrings; j++ )
{
if( !Q_strcmp( list->strings[j], temp ))
@@ -571,7 +569,7 @@ static byte *W_ReadLump( searchpath_t *search, const char *path, int pack_ind, f
{
const wfile_t *wad = search->wad;
const dlumpinfo_t *lump = &wad->lumps[pack_ind];
size_t oldpos, size = 0;
size_t oldpos, size;
byte *buf;
// assume error
@@ -620,10 +618,8 @@ FS_AddWad_Fullpath
searchpath_t *FS_AddWad_Fullpath( const char *wadfile, int flags )
{
searchpath_t *search;
wfile_t *wad;
int errorcode = WAD_LOAD_COULDNT_OPEN;
wad = W_Open( wadfile, &errorcode, flags );
wfile_t *wad = W_Open( wadfile, &errorcode, flags );
if( !wad )
{

View File

@@ -169,11 +169,11 @@ FS_LoadZip
*/
static zip_t *FS_LoadZip( const char *zipfile, int *error )
{
int numpackfiles = 0, i;
int numpackfiles = 0;
zip_cdf_header_t header_cdf;
zip_header_eocd_t header_eocd;
uint32_t signature;
fs_offset_t filepos = 0;
fs_offset_t filepos;
zipfile_t *info = NULL;
char filename_buffer[MAX_SYSPATH];
zip_t *zip = (zip_t *)Mem_Calloc( fs_mempool, sizeof( *zip ));
@@ -295,7 +295,7 @@ static zip_t *FS_LoadZip( const char *zipfile, int *error )
zip = (zip_t *)Mem_Realloc( fs_mempool, zip, sizeof( *zip ) + sizeof( *info ) * header_eocd.total_central_directory_record );
info = zip->files;
for( i = 0; i < header_eocd.total_central_directory_record; i++ )
for( int i = 0; i < header_eocd.total_central_directory_record; i++ )
{
c = FS_Read( zip->handle, &header_cdf, sizeof( header_cdf ));
@@ -373,7 +373,7 @@ static zip_t *FS_LoadZip( const char *zipfile, int *error )
}
// recalculate offsets
for( i = 0; i < numpackfiles; i++ )
for( int i = 0; i < numpackfiles; i++ )
{
zip_header_t header;
@@ -472,10 +472,8 @@ FS_LoadZIPFile
*/
static byte *FS_LoadZIPFile( searchpath_t *search, const char *path, int pack_ind, fs_offset_t *sizeptr, void *( *pfnAlloc )( size_t ), void ( *pfnFree )( void * ))
{
zipfile_t *file;
byte *compressed_buffer = NULL, *decompressed_buffer = NULL;
int zlib_result = 0;
z_stream decompress_stream;
zipfile_t *file = &search->zip->files[pack_ind];
byte *compressed_buffer = NULL, *decompressed_buffer;
size_t c;
#ifdef ENABLE_CRC_CHECK
dword test_crc, final_crc;
@@ -483,8 +481,6 @@ static byte *FS_LoadZIPFile( searchpath_t *search, const char *path, int pack_in
if( sizeptr ) *sizeptr = 0;
file = &search->zip->files[pack_ind];
if( FS_Seek( search->zip->handle, file->offset, SEEK_SET ) == -1 )
return NULL;
@@ -534,6 +530,9 @@ static byte *FS_LoadZIPFile( searchpath_t *search, const char *path, int pack_in
}
else if( file->flags == ZIP_COMPRESSION_DEFLATED )
{
z_stream decompress_stream;
int zlib_result;
compressed_buffer = (byte *)Mem_Malloc( fs_mempool, file->compressed_size + 1 );
c = FS_Read( search->zip->handle, compressed_buffer, file->compressed_size );
@@ -636,17 +635,14 @@ FS_FindFile_ZIP
*/
static int FS_FindFile_ZIP( searchpath_t *search, const char *path, char *fixedname, size_t len )
{
int left, right, middle;
// look for the file (binary search)
left = 0;
right = search->zip->numfiles - 1;
int left = 0;
int right = search->zip->numfiles - 1;
while( left <= right )
{
int diff;
middle = (left + right) / 2;
diff = Q_stricmp( search->zip->files[middle].name, path );
int middle = (left + right) / 2;
int diff = Q_stricmp( search->zip->files[middle].name, path );
// Found it
if( !diff )
@@ -674,16 +670,18 @@ FS_Search_ZIP
static void FS_Search_ZIP( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
{
string temp;
const char *slash, *backslash, *colon, *separator;
int j, i;
for( i = 0; i < search->zip->numfiles; i++ )
for( int i = 0; i < search->zip->numfiles; i++ )
{
Q_strncpy( temp, search->zip->files[i].name, sizeof( temp ));
while( temp[0] )
{
const char *slash, *backslash, *colon, *separator;
if( matchpattern( temp, pattern, true ))
{
int j;
for( j = 0; j < list->numstrings; j++ )
{
if( !Q_strcmp( list->strings[j], temp ))
@@ -720,10 +718,8 @@ FS_AddZip_Fullpath
searchpath_t *FS_AddZip_Fullpath( const char *zipfile, int flags )
{
searchpath_t *search;
zip_t *zip;
int errorcode = ZIP_LOAD_COULDNT_OPEN;
zip = FS_LoadZip( zipfile, &errorcode );
zip_t *zip = FS_LoadZip( zipfile, &errorcode );
if( !zip )
{