mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-03 06:20:57 +00:00
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
This commit is contained in:
parent
d0093d0b80
commit
456e77d036
2 changed files with 31 additions and 23 deletions
|
@ -52,13 +52,12 @@ void CFG_ReadCvars (const char **vars, int num_vars)
|
||||||
do {
|
do {
|
||||||
i = 0;
|
i = 0;
|
||||||
memset (buff, 0, sizeof(buff));
|
memset (buff, 0, sizeof(buff));
|
||||||
if (FS_fgets(buff, sizeof(buff), cfg_file))
|
|
||||||
{
|
|
||||||
// we expect a line in the format that Cvar_WriteVariables
|
// we expect a line in the format that Cvar_WriteVariables
|
||||||
// writes to the config file. although I'm trying to be as
|
// writes to the config file. although I'm trying to be as
|
||||||
// much cautious as possible, if the user screws it up by
|
// much cautious as possible, if the user screws it up by
|
||||||
// editing it, it's his fault.
|
// editing it, it's his fault.
|
||||||
|
if (FS_fgets(buff, sizeof(buff), cfg_file))
|
||||||
|
{
|
||||||
// remove end-of-line characters
|
// remove end-of-line characters
|
||||||
while (buff[i])
|
while (buff[i])
|
||||||
{
|
{
|
||||||
|
@ -109,11 +108,20 @@ void CFG_ReadCvars (const char **vars, int num_vars)
|
||||||
if (j == num_vars)
|
if (j == num_vars)
|
||||||
break;
|
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)
|
void CFG_ReadCvarOverrides (const char **vars, int num_vars)
|
||||||
{
|
{
|
||||||
char buff[64];
|
char buff[64];
|
||||||
|
@ -148,20 +156,20 @@ void CFG_CloseConfig (void)
|
||||||
|
|
||||||
int CFG_OpenConfig (const char *cfg_name)
|
int CFG_OpenConfig (const char *cfg_name)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *f;
|
||||||
long length;
|
long length;
|
||||||
qboolean pak;
|
qboolean pak;
|
||||||
|
|
||||||
CFG_CloseConfig ();
|
CFG_CloseConfig ();
|
||||||
|
|
||||||
length = (long) COM_FOpenFile (cfg_name, &file, NULL);
|
length = (long) COM_FOpenFile (cfg_name, &f, NULL);
|
||||||
pak = file_from_pak;
|
pak = file_from_pak;
|
||||||
if (length == -1)
|
if (length == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
cfg_file = (fshandle_t *) Z_Malloc(sizeof(fshandle_t));
|
cfg_file = (fshandle_t *) Z_Malloc(sizeof(fshandle_t));
|
||||||
cfg_file->file = file;
|
cfg_file->file = f;
|
||||||
cfg_file->start = ftell(file);
|
cfg_file->start = ftell(f);
|
||||||
cfg_file->pos = 0;
|
cfg_file->pos = 0;
|
||||||
cfg_file->length = length;
|
cfg_file->length = length;
|
||||||
cfg_file->pak = pak;
|
cfg_file->pak = pak;
|
||||||
|
|
|
@ -27,21 +27,21 @@
|
||||||
#define __CFGFILE_H
|
#define __CFGFILE_H
|
||||||
|
|
||||||
int CFG_OpenConfig (const char *cfg_name);
|
int CFG_OpenConfig (const char *cfg_name);
|
||||||
// opens the given config file and keeps it open
|
// opens the given config file. only one open config file is
|
||||||
// until CFG_CloseConfig is called
|
// kept: previosly opened one, if any, will be closed.
|
||||||
|
|
||||||
void CFG_CloseConfig (void);
|
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);
|
void CFG_ReadCvars (const char **vars, int num_vars);
|
||||||
// reads the values of cvars in the given list
|
// reads the values of cvars in the given list from the opened
|
||||||
// from the currently open config file
|
// config file.
|
||||||
|
|
||||||
void CFG_ReadCvarOverrides (const char **vars, int num_vars);
|
void CFG_ReadCvarOverrides (const char **vars, int num_vars);
|
||||||
// reads the "+" command line override values of cvars
|
// convenience function, reading the "+" command line override
|
||||||
// in the given list. doesn't care about the config file.
|
// values of cvars in the given list. doesn't do anything with
|
||||||
// call this after CFG_ReadCvars() and before locking your
|
// the config file. call this after CFG_ReadCvars() and before
|
||||||
// cvars.
|
// locking your cvars.
|
||||||
|
|
||||||
#endif /* __CFGFILE_H */
|
#endif /* __CFGFILE_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue