From 456e77d036e56fc3f89752e88fd1effdd78b374b Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 27 Dec 2011 19:40:14 +0000 Subject: [PATCH] cfgfile.c (CFG_ReadCvars): Also check for ferror(). Use FS_rewind() instead of FS_fseek(). From Sander van Dijk. cfgfile.c, cfgfile.h: synced with uhexen2 versions. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@564 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/cfgfile.c | 36 ++++++++++++++++++++++-------------- Quake/cfgfile.h | 18 +++++++++--------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Quake/cfgfile.c b/Quake/cfgfile.c index 29b2a638..dbf9b4e0 100644 --- a/Quake/cfgfile.c +++ b/Quake/cfgfile.c @@ -52,13 +52,12 @@ void CFG_ReadCvars (const char **vars, int num_vars) do { i = 0; memset (buff, 0, sizeof(buff)); + // we expect a line in the format that Cvar_WriteVariables + // writes to the config file. although I'm trying to be as + // much cautious as possible, if the user screws it up by + // editing it, it's his fault. if (FS_fgets(buff, sizeof(buff), cfg_file)) { - // we expect a line in the format that Cvar_WriteVariables - // writes to the config file. although I'm trying to be as - // much cautious as possible, if the user screws it up by - // editing it, it's his fault. - // remove end-of-line characters while (buff[i]) { @@ -99,7 +98,7 @@ void CFG_ReadCvars (const char **vars, int num_vars) tmp = strchr(buff, '\"'); if (tmp) { - Cvar_Set (vars[i], tmp+1); + Cvar_Set (vars[i], tmp + 1); j++; break; } @@ -109,11 +108,20 @@ void CFG_ReadCvars (const char **vars, int num_vars) if (j == num_vars) break; - } while (!FS_feof(cfg_file)); + } while (!FS_feof(cfg_file) && !FS_ferror(cfg_file)); - FS_fseek (cfg_file, 0, SEEK_SET); + FS_rewind (cfg_file); } +/* +=================== +CFG_ReadCvarOverrides + +convenience function, reading the "+" command line override +values of cvars in the given list. doesn't do anything with +the config file. +=================== +*/ void CFG_ReadCvarOverrides (const char **vars, int num_vars) { char buff[64]; @@ -148,20 +156,20 @@ void CFG_CloseConfig (void) int CFG_OpenConfig (const char *cfg_name) { - FILE *file; - long length; - qboolean pak; + FILE *f; + long length; + qboolean pak; CFG_CloseConfig (); - length = (long) COM_FOpenFile (cfg_name, &file, NULL); + length = (long) COM_FOpenFile (cfg_name, &f, NULL); pak = file_from_pak; if (length == -1) return -1; cfg_file = (fshandle_t *) Z_Malloc(sizeof(fshandle_t)); - cfg_file->file = file; - cfg_file->start = ftell(file); + cfg_file->file = f; + cfg_file->start = ftell(f); cfg_file->pos = 0; cfg_file->length = length; cfg_file->pak = pak; diff --git a/Quake/cfgfile.h b/Quake/cfgfile.h index 5ad09d9d..09d2298a 100644 --- a/Quake/cfgfile.h +++ b/Quake/cfgfile.h @@ -27,21 +27,21 @@ #define __CFGFILE_H int CFG_OpenConfig (const char *cfg_name); -// opens the given config file and keeps it open -// until CFG_CloseConfig is called +// opens the given config file. only one open config file is +// kept: previosly opened one, if any, will be closed. void CFG_CloseConfig (void); -// closes the currently open config file +// closes the currently open config file. void CFG_ReadCvars (const char **vars, int num_vars); -// reads the values of cvars in the given list -// from the currently open config file +// reads the values of cvars in the given list from the opened +// config file. void CFG_ReadCvarOverrides (const char **vars, int num_vars); -// reads the "+" command line override values of cvars -// in the given list. doesn't care about the config file. -// call this after CFG_ReadCvars() and before locking your -// cvars. +// convenience function, reading the "+" command line override +// values of cvars in the given list. doesn't do anything with +// the config file. call this after CFG_ReadCvars() and before +// locking your cvars. #endif /* __CFGFILE_H */