diff options
-rw-r--r-- | source/cl_main.c | 7 | ||||
-rw-r--r-- | source/cmd.c | 12 | ||||
-rw-r--r-- | source/com_local.h | 6 | ||||
-rw-r--r-- | source/cvar.c | 68 | ||||
-rw-r--r-- | source/files.c | 70 |
5 files changed, 134 insertions, 29 deletions
diff --git a/source/cl_main.c b/source/cl_main.c index b25d103..d09fac2 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -857,7 +857,7 @@ static void CL_ParsePrintMessage( void ) { Com_Printf( "%s", string ); Q_strncpyz( cls.messageString, string, sizeof( cls.messageString ) ); cls.state = ca_challenging; - cls.connectCount = 0; + //cls.connectCount = 0; return; } @@ -1220,7 +1220,7 @@ static void CL_ConnectionlessPacket( void ) { cls.challenge = atoi( Cmd_Argv( 1 ) ); cls.state = ca_connecting; cls.connect_time = -9999; - cls.connectCount = 0; + //cls.connectCount = 0; // parse additional parameters j = Cmd_Argc(); @@ -2002,7 +2002,8 @@ static qboolean CL_WriteConfig( const char *path ) { FS_FPrintf( f, "// generated by q2pro, do not modify\n" ); Key_WriteBindings( f ); - Cvar_WriteVariables( f ); + Cvar_WriteVariables( f, CVAR_ARCHIVE, qfalse ); + Cmd_WriteAliases( f ); FS_FCloseFile( f ); diff --git a/source/cmd.c b/source/cmd.c index e4526d3..ce3fc20 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -377,6 +377,16 @@ static void Cmd_UnAlias_f( void ) { Z_Free( a ); } +#ifndef DEDICATED_ONLY +void Cmd_WriteAliases( fileHandle_t f ) { + cmdalias_t *a; + + LIST_FOR_EACH( cmdalias_t, a, &cmd_alias, listEntry ) { + FS_FPrintf( f, "alias \"%s\" \"%s\"\n", a->name, a->value ); + } +} +#endif + /* ============================================================================= @@ -774,7 +784,7 @@ void Cmd_PrintHelp( const cmd_option_t *opt ) { } else { Q_strncpyz( buffer, opt->lo, sizeof( buffer ) ); } - Com_Printf( "-%c | --%-16.16s : %s\n", opt->sh[0], buffer, opt->help ); + Com_Printf( "-%c | --%-16.16s | %s\n", opt->sh[0], buffer, opt->help ); opt++; } Com_Printf( "\n" ); diff --git a/source/com_local.h b/source/com_local.h index 584a21a..d4b0943 100644 --- a/source/com_local.h +++ b/source/com_local.h @@ -178,6 +178,8 @@ void Cmd_Shift( void ); void Cmd_Alias_f( void ); +void Cmd_WriteAliases( fileHandle_t f ); + void Cmd_FillAPI( cmdAPI_t *api ); @@ -255,9 +257,9 @@ void Cvar_Command( cvar_t *v ); // command. Returns qtrue if the command was a variable reference that // was handled. (print or change) -void Cvar_WriteVariables( fileHandle_t f ); +void Cvar_WriteVariables( fileHandle_t f, int mask, qboolean modified ); // appends lines containing "set variable value" for all variables -// with the archive flag set to qtrue. +// with matching flags void Cvar_Init (void); diff --git a/source/cvar.c b/source/cvar.c index 1bdea97..818f9ec 100644 --- a/source/cvar.c +++ b/source/cvar.c @@ -224,7 +224,7 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) { var->flags |= CVAR_DEFAULTS_MIXED; } } -#if 0 +#if 1 if( ( var->flags & CVAR_LATCHED ) && !( flags & CVAR_LATCHED ) ) { if( var->latched_string ) { Z_Free( var->latched_string ); @@ -709,7 +709,7 @@ Appends lines containing "set variable value" for all variables with the archive flag set to true. ============ */ -void Cvar_WriteVariables( fileHandle_t f ) { +void Cvar_WriteVariables( fileHandle_t f, int mask, qboolean modified ) { cvar_t *var; char *string; @@ -717,13 +717,15 @@ void Cvar_WriteVariables( fileHandle_t f ) { if( var->flags & CVAR_PRIVATE ) { continue; } - if( var->flags & CVAR_ARCHIVE ) { + if( var->flags & mask ) { if( ( var->flags & CVAR_LATCHED ) && var->latched_string ) { string = var->latched_string; } else { string = var->string; } - FS_FPrintf( f, "set %s \"%s\"\n", var->name, string ); + if( !modified || strcmp( string, var->default_string ) ) { + FS_FPrintf( f, "set %s \"%s\"\n", var->name, string ); + } } } } @@ -738,22 +740,35 @@ Cvar_List_f */ static void Cvar_List_f( void ) { static const cmd_option_t options[] = { - { "v", "verbose", "display flags of each cvar" }, + { "a", "archive", "list archived cvars" }, + { "c", "cheat", "list cheat protected cvars" }, { "h", "help", "display this help message" }, - { "f:string", "filter", "filter cvars by wildcard" }, + { "l", "latched", "list latched cvars" }, + { "m", "modified", "list modified cvars" }, + { "n", "noset", "list command line cvars" }, + { "r", "rom", "list read-only cvars" }, + { "s", "serverinfo", "list serverinfo cvars" }, + { "t", "custom", "list user-created cvars" }, + { "u", "userinfo", "list userinfo cvars" }, + { "v", "verbose", "display flags of each cvar" }, + { "w:string", "wildcard", "list cvars matching wildcard" }, { NULL } }; cvar_t *var; int i, total; - qboolean verbose = qfalse; + qboolean verbose = qfalse, modified = qfalse, latched = qfalse; + int mask = 0; char *wildcard = NULL; char buffer[6]; int c; while( ( c = Cmd_ParseOptions( options ) ) != -1 ) { switch( c ) { - case 'f': - wildcard = cmd_optarg; + case 'a': + mask |= CVAR_ARCHIVE; + break; + case 'c': + mask |= CVAR_CHEAT; break; case 'h': Cmd_PrintUsage( options, NULL ); @@ -771,9 +786,33 @@ static void Cvar_List_f( void ) { "G: latched (requires game map restart)\n" "?: created by user\n" ); return; + case 'l': + latched = qtrue; + break; + case 'm': + modified = qtrue; + break; + case 'n': + mask |= CVAR_NOSET; + break; + case 'r': + mask |= CVAR_ROM; + break; + case 's': + mask |= CVAR_SERVERINFO; + break; + case 't': + mask |= CVAR_USER_CREATED; + break; + case 'u': + mask |= CVAR_USERINFO; + break; case 'v': verbose = qtrue; break; + case 'w': + wildcard = cmd_optarg; + break; default: return; } @@ -782,9 +821,20 @@ static void Cvar_List_f( void ) { buffer[sizeof( buffer ) - 1] = 0; i = 0; for( var = cvar_vars, total = 0; var; var = var->next, total++ ) { + if( latched && !var->latched_string ) { + continue; + } + if( mask && !( var->flags & mask ) ) { + continue; + } if( wildcard && !Com_WildCmp( wildcard, var->name, qtrue ) ) { continue; } + if( modified && ( !strcmp( var->latched_string ? var->latched_string : + var->string, var->default_string ) || ( var->flags & CVAR_ROM ) ) ) + { + continue; + } if( verbose ) { memset( buffer, ' ', sizeof( buffer ) - 1 ); diff --git a/source/files.c b/source/files.c index 3ba6aed..039e5c1 100644 --- a/source/files.c +++ b/source/files.c @@ -23,6 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <zlib.h> #include "unzip.h" #endif +#ifdef __unix__ +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#endif +#include <errno.h> /* ============================================================================= @@ -462,6 +468,9 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) { char *modeStr; fsFileType_t type; uint32 mode; +#ifdef __unix__ + struct stat st; +#endif #ifdef _WIN32 // allow writing into basedir on Windows @@ -499,11 +508,24 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) { fp = fopen( file->fullpath, modeStr ); if( !fp ) { - FS_DPrintf( "%s: %s: fopen(%s) failed\n", - __func__, file->fullpath, modeStr ); + FS_DPrintf( "%s: %s: fopen(%s): %s\n", + __func__, file->fullpath, modeStr, strerror( errno ) ); return -1; } +#ifdef __unix__ + if( fstat( fileno( fp ), &st ) == -1 ) { + FS_DPrintf( "%s: %s: stat: %s\n", + __func__, file->fullpath, strerror( errno ) ); + return -1; + } + if( !S_ISREG( st.st_mode ) ) { + FS_DPrintf( "%s: %s: not a file\n", + __func__, file->fullpath ); + return -1; + } +#endif + type = FS_REAL; #if USE_ZLIB if( !( file->mode & FS_FLAG_RAW ) ) { @@ -511,8 +533,8 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) { if( !FS_strcmp( ext, ".gz" ) ) { zfp = gzdopen( fileno( fp ), modeStr ); if( !zfp ) { - FS_DPrintf( "%s: %s: gzopen(%s) failed\n", - __func__, file->fullpath, modeStr ); + FS_DPrintf( "%s: %s: gzdopen(%s): %s\n", + __func__, file->fullpath, modeStr, strerror( errno ) ); fclose( fp ); return -1; } @@ -570,7 +592,12 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique ) char *ext; #endif fsFileType_t type; - int pos, length; + int length; +#ifdef __unix__ + struct stat st; +#else + int pos; +#endif fs_fileFromPak = qfalse; fs_count_read++; @@ -668,6 +695,26 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique ) continue; } +#ifdef __unix__ + if( fstat( fileno( fp ), &st ) == -1 ) { + FS_DPrintf( "%s: %s: stat: %s\n", + __func__, file->fullpath, strerror( errno ) ); + continue; + } + if( !S_ISREG( st.st_mode ) ) { + FS_DPrintf( "%s: %s: not a file\n", + __func__, file->fullpath ); + continue; + } + + length = st.st_size; +#else + pos = ftell( fp ); + fseek( fp, 0, SEEK_END ); + length = ftell( fp ); + fseek( fp, pos, SEEK_SET ); +#endif + type = FS_REAL; #if USE_ZLIB if( !( file->mode & FS_FLAG_RAW ) ) { @@ -675,8 +722,8 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique ) if( !strcmp( ext, ".gz" ) ) { zfp = gzdopen( fileno( fp ), "rb" ); if( !zfp ) { - FS_DPrintf( "%s: %s: gzopen(rb) failed\n", - __func__, file->fullpath ); + FS_DPrintf( "%s: %s: gzdopen(rb): %s\n", + __func__, file->fullpath, strerror( errno ) ); fclose( fp ); return -1; } @@ -690,12 +737,6 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique ) file->fp = fp; file->type = type; file->unique = qtrue; - - pos = ftell( fp ); - fseek( fp, 0, SEEK_END ); - length = ftell( fp ); - fseek( fp, pos, SEEK_SET ); - file->length = length; return length; @@ -862,7 +903,8 @@ static char *FS_ExpandLinks( const char *filename ) { return ( char * )filename; } memcpy( buffer, l->target, l->targetLength ); - strcpy( buffer + l->targetLength, filename + l->nameLength ); + memcpy( buffer + l->targetLength, filename + l->nameLength, + length - l->nameLength + 1 ); FS_DPrintf( "%s: %s --> %s\n", __func__, filename, buffer ); return buffer; } |