Handle empty values for the directory

This is considered to mean the current directory.
As an intended side-effect, the output in verbose mode is slightly
nicer.
This commit is contained in:
Pierre Pronchery 2018-09-21 14:17:47 +03:00
parent 4190e6dfd4
commit 92a5a95ebc
4 changed files with 29 additions and 16 deletions

View File

@ -464,8 +464,11 @@ static int _project_load(ConfigurePrefs * prefs, String const * directory,
String * path;
String const * subdirs = NULL;
if((path = string_new_append(directory, "/", PROJECT_CONF, NULL))
== NULL)
if(directory == NULL || string_length(directory) == 0)
path = string_new_append(PROJECT_CONF, NULL);
else
path = string_new_append(directory, "/", PROJECT_CONF, NULL);
if(path == NULL)
return configure_error(1, "%s", error_get(NULL));
if((config = config_new()) == NULL)
{
@ -523,10 +526,15 @@ static int _project_load_subdirs_subdir(ConfigurePrefs * prefs,
int ret;
String * p;
if((p = string_new_append(directory, "/", subdir, NULL)) == NULL)
return error_print(PROGNAME);
if(directory == NULL || string_length(directory) == 0)
ret = _project_load(prefs, subdir, ca);
else if((p = string_new_append(directory, "/", subdir, NULL)) == NULL)
ret = error_print(PROGNAME);
else
{
ret = _project_load(prefs, p, ca);
string_delete(p);
}
return ret;
}

View File

@ -185,7 +185,7 @@ int main(int argc, char * argv[])
ret = configure_error(2, "%s", error_get(NULL));
else if(optind == argc)
{
if((ret = configure_project(configure, ".")) != 0)
if((ret = configure_project(configure, NULL)) != 0)
configure_error(2, "%s", error_get(NULL));
}
else

View File

@ -103,8 +103,11 @@ int makefile(Configure * configure, String const * directory, configArray * ca,
String * filename;
int ret = 0;
if((filename = string_new_append(directory, "/", MAKEFILE, NULL))
== NULL)
if(directory == NULL || string_length(directory) == 0)
filename = string_new(MAKEFILE);
else
filename = string_new_append(directory, "/", MAKEFILE, NULL);
if(filename == NULL)
return -1;
makefile.configure = configure;
makefile.fp = NULL;
@ -114,8 +117,7 @@ int makefile(Configure * configure, String const * directory, configArray * ca,
else
{
if(_makefile_is_flag_set(&makefile, PREFS_v))
printf("%s%s/%s", "Creating ", directory,
MAKEFILE "\n");
printf("%s%s\n", "Creating ", filename);
ret |= _makefile_write(&makefile, ca, from, to);
if(makefile.fp != NULL)
fclose(makefile.fp);

View File

@ -111,17 +111,20 @@ static int _settings_do(Configure * configure, String const * directory,
}
if(configure_is_flag_set(configure, PREFS_n))
return 0;
if((filename = string_new_append(directory, "/config.", extension,
NULL)) == NULL)
if(directory == NULL || string_length(directory) == 0)
filename = string_new_append("config.", extension, NULL);
else
filename = string_new_append(directory, "/config.", extension,
NULL);
if(filename == NULL)
return 1;
if(configure_is_flag_set(configure, PREFS_v))
printf("%s%s\n", "Creating ", filename);
if((fp = fopen(filename, "w")) == NULL)
configure_error(0, "%s: %s", filename, strerror(errno));
string_delete(filename);
if(fp == NULL)
return 1;
if(configure_is_flag_set(configure, PREFS_v))
printf("%s%s/%s%s\n", "Creating ", directory, "config.",
extension);
switch(i)
{
case ST_H: