}
}
-static char *substitute_variables(char *src)
+static char *substitute_variables(char *src, bool recursive)
{
int i = 0;
int start_index = -1;
// search stored variables
value = get_variable(name);
- // if there is no name in stored variables,
- // try to search environment variables
if(!value) {
+ // if there is no name in stored variables,
+ // try to search environment variables
value = getenv(name);
}
+ if (recursive) {
+ value = substitute_variables(value, true);
+ }
+
if(!value) {
fprintf(stderr, "[%s] is not set."
" Please input value using commandline argument"
{
gchar **splitted = g_strsplit(token, "=", 2);
if (splitted[0] && splitted[1]) {
- char *value = substitute_variables(splitted[1]);
- set_variable(g_strdup(splitted[0]), value,
- false);
+ // FIXME: we override previous value if already exist.
+ // We should warn to users.
+ set_variable(splitted[0], splitted[1], true);
}
g_strfreev(splitted);
}
}
+ // assemble variables
+ struct variable *var = NULL;
+ QTAILQ_FOREACH(var, &variables, entry) {
+ set_variable(var->name, substitute_variables(var->value, true), true);
+ }
+
fclose(file);
return true;
}
}
// substitute variables
- argv[(*argc)++] = substitute_variables(str);
+ argv[(*argc)++] = substitute_variables(str, false);
}
return true;