diff --git a/tools/quake3/common/vfs.c b/tools/quake3/common/vfs.c index b2d070ba..feb3342a 100644 --- a/tools/quake3/common/vfs.c +++ b/tools/quake3/common/vfs.c @@ -238,7 +238,7 @@ void vfsInitDirectory( const char *path ){ // lists all .shader files -void vfsListShaderFiles( char* list, const size_t stride, int *num ){ +void vfsListShaderFiles( StrList* list, void pushStringCallback( StrList* list, const char* string ) ){ //char filename[PATH_MAX]; char *dirlist; GDir *dir; @@ -264,13 +264,7 @@ void vfsListShaderFiles( char* list, const size_t stride, int *num ){ continue; } - for ( k = 0; k < *num; k++ ){ - if ( !Q_stricmp( list + stride * k, dirlist ) ) - goto shISdouplicate; - } - strcpy( list + stride * ( *num ), dirlist ); - ( *num )++; -shISdouplicate: + pushStringCallback( list, dirlist ); g_free( dirlist ); } g_dir_close( dir ); @@ -291,14 +285,7 @@ shISdouplicate: //name + ext this time ext = strrchr( file->name, '/' ); ext++; - - for ( k = 0; k < *num; k++ ){ - if ( !Q_stricmp( list + stride * k, ext ) ) - goto shISdouplicate2; - } - strcpy( list + stride * ( *num ) , ext ); - ( *num )++; -shISdouplicate2: + pushStringCallback( list, ext ); continue; } } diff --git a/tools/quake3/common/vfs.h b/tools/quake3/common/vfs.h index f5d9952d..73e1477b 100644 --- a/tools/quake3/common/vfs.h +++ b/tools/quake3/common/vfs.h @@ -55,7 +55,8 @@ void vfsInitDirectory( const char *path ); void vfsShutdown(); int vfsGetFileCount( const char *filename ); int vfsLoadFile( const char *filename, void **buffer, int index ); -void vfsListShaderFiles( char* list, const size_t stride, int *num ); +typedef struct StrList_s StrList; +void vfsListShaderFiles( StrList* list, void pushStringCallback( StrList* list, const char* string ) ); qboolean vfsPackFile( const char *filename, const char *packname, const int compLevel ); qboolean vfsPackFile_Absolute_Path( const char *filepath, const char *filename, const char *packname, const int compLevel ); diff --git a/tools/quake3/q3map2/autopk3.c b/tools/quake3/q3map2/autopk3.c index 597da7e9..fa249b69 100644 --- a/tools/quake3/q3map2/autopk3.c +++ b/tools/quake3/q3map2/autopk3.c @@ -31,7 +31,7 @@ #include "autopk3.h" -typedef struct +typedef struct StrList_s { int n; int max; @@ -69,6 +69,11 @@ static inline int StrList_find( const StrList* list, const char* string ){ return 0; } +void pushStringCallback( StrList* list, const char* string ){ + if( !StrList_find( list, string ) ) + StrList_append( list, string ); +} + /* Check if newcoming texture is unique and not excluded @@ -324,7 +329,7 @@ int pk3BSPMain( int argc, char **argv ){ } } - vfsListShaderFiles( &pk3Shaderfiles->s[0][0], sizeof( pk3Shaderfiles->s[0] ), &pk3Shaderfiles->n ); + vfsListShaderFiles( pk3Shaderfiles, pushStringCallback ); if( dbg ){ Sys_Printf( "\n\tSchroider fileses.....%i\n", pk3Shaderfiles->n ); @@ -1125,7 +1130,7 @@ int repackBSPMain( int argc, char **argv ){ - vfsListShaderFiles( &pk3Shaderfiles->s[0][0], sizeof( pk3Shaderfiles->s[0] ), &pk3Shaderfiles->n ); + vfsListShaderFiles( pk3Shaderfiles, pushStringCallback ); if( dbg ){ Sys_Printf( "\n\tSchroider fileses.....%i\n", pk3Shaderfiles->n );