Added some error checking at loading time
This commit is contained in:
parent
d87486a333
commit
ff2a5d4c7f
@ -110,24 +110,25 @@ static int _load_subdirs(Prefs * prefs, char const * directory,
|
|||||||
static int _configure_load(Prefs * prefs, String const * directory,
|
static int _configure_load(Prefs * prefs, String const * directory,
|
||||||
configArray * ca)
|
configArray * ca)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
Config * config;
|
Config * config;
|
||||||
String * path;
|
String * path;
|
||||||
String * subdirs;
|
String * subdirs = NULL;
|
||||||
|
|
||||||
if((path = string_new(directory)) == NULL)
|
if((path = string_new(directory)) == NULL)
|
||||||
return _configure_error(directory, 2);
|
return _configure_error(directory, 1);
|
||||||
if(string_append(&path, "/") != 0
|
if(string_append(&path, "/") != 0
|
||||||
|| string_append(&path, PROJECT_CONF) != 0
|
|| string_append(&path, PROJECT_CONF) != 0
|
||||||
|| (config = config_new()) == NULL)
|
|| (config = config_new()) == NULL)
|
||||||
{
|
{
|
||||||
string_delete(path);
|
string_delete(path);
|
||||||
return _configure_error(directory, 2);
|
return _configure_error(directory, 1);
|
||||||
}
|
}
|
||||||
config_set(config, "", "directory", directory);
|
config_set(config, "", "directory", directory);
|
||||||
if(*prefs & PREFS_v)
|
if(*prefs & PREFS_v)
|
||||||
fprintf(stderr, "%s%s%s", "Loading project file ", path, "\n");
|
printf("%s%s%s", "Loading project file ", path, "\n");
|
||||||
if(config_load(config, path) != 0)
|
if(config_load(config, path) != 0)
|
||||||
_configure_error(directory, 2);
|
ret = _configure_error(path, 1);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
array_append(ca, &config);
|
array_append(ca, &config);
|
||||||
@ -135,7 +136,7 @@ static int _configure_load(Prefs * prefs, String const * directory,
|
|||||||
}
|
}
|
||||||
string_delete(path);
|
string_delete(path);
|
||||||
if(subdirs == NULL)
|
if(subdirs == NULL)
|
||||||
return 0;
|
return ret;
|
||||||
return _load_subdirs(prefs, directory, ca, subdirs);
|
return _load_subdirs(prefs, directory, ca, subdirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,25 +145,26 @@ static int _load_subdirs_subdir(Prefs * prefs, char const * directory,
|
|||||||
static int _load_subdirs(Prefs * prefs, char const * directory,
|
static int _load_subdirs(Prefs * prefs, char const * directory,
|
||||||
configArray * ca, String * subdirs)
|
configArray * ca, String * subdirs)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
String * subdir;
|
String * subdir;
|
||||||
|
|
||||||
subdir = subdirs;
|
subdir = subdirs;
|
||||||
for(i = 0;; i++)
|
for(i = 0; ret == 0; i++)
|
||||||
{
|
{
|
||||||
if(subdir[i] != ',' && subdir[i] != '\0')
|
if(subdir[i] != ',' && subdir[i] != '\0')
|
||||||
continue;
|
continue;
|
||||||
c = subdir[i];
|
c = subdir[i];
|
||||||
subdir[i] = '\0';
|
subdir[i] = '\0';
|
||||||
_load_subdirs_subdir(prefs, directory, ca, subdir);
|
ret = _load_subdirs_subdir(prefs, directory, ca, subdir);
|
||||||
if(c == '\0')
|
if(c == '\0')
|
||||||
break;
|
break;
|
||||||
subdir[i] = c;
|
subdir[i] = c;
|
||||||
subdir+=i+1;
|
subdir+=i+1;
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -170,14 +172,15 @@ static int _load_subdirs_subdir(Prefs * prefs, char const * directory,
|
|||||||
configArray * ca, char const * subdir)
|
configArray * ca, char const * subdir)
|
||||||
/* FIXME error checking */
|
/* FIXME error checking */
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
String * p;
|
String * p;
|
||||||
|
|
||||||
p = string_new(directory);
|
p = string_new(directory);
|
||||||
string_append(&p, "/");
|
string_append(&p, "/");
|
||||||
string_append(&p, subdir);
|
string_append(&p, subdir);
|
||||||
_configure_load(prefs, p, ca);
|
ret = _configure_load(prefs, p, ca);
|
||||||
string_delete(p);
|
string_delete(p);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user