From: SeokYeon Hwang Date: Wed, 17 Jun 2015 05:49:20 +0000 (+0900) Subject: emulator_options: introduced recursive variable substitution X-Git-Tag: Tizen_Studio_1.3_Release_p2.3~41^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba3014b1c0211cf36065a05f2ddd92a21fd68f8b;p=sdk%2Femulator%2Fqemu.git emulator_options: introduced recursive variable substitution Users can write variable position-independently. Change-Id: I515843030f3d87bfea14a420133ffb1cdc4a1bac Signed-off-by: SeokYeon Hwang --- diff --git a/tizen/src/emulator_options.c b/tizen/src/emulator_options.c index 8e8c9d7cf9..e2eff580e9 100644 --- a/tizen/src/emulator_options.c +++ b/tizen/src/emulator_options.c @@ -133,7 +133,7 @@ static void reset_default_opts(void) } } -static char *substitute_variables(char *src) +static char *substitute_variables(char *src, bool recursive) { int i = 0; int start_index = -1; @@ -164,12 +164,16 @@ static char *substitute_variables(char *src) // 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" @@ -276,9 +280,9 @@ bool load_conf(const char * const conf) { 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); @@ -293,6 +297,12 @@ bool load_conf(const char * const conf) } } + // 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; } @@ -335,7 +345,7 @@ static bool assemble_args(int *argc, char **argv, } // substitute variables - argv[(*argc)++] = substitute_variables(str); + argv[(*argc)++] = substitute_variables(str, false); } return true;