diff options
author | SeokYeon Hwang <syeon.hwang@samsung.com> | 2015-06-17 14:49:20 +0900 |
---|---|---|
committer | Sooyoung Ha <yoosah.ha@samsung.com> | 2016-01-08 19:32:07 +0900 |
commit | cf63c0cc3142c2e6359e147e071d485afe424ea4 (patch) | |
tree | fbc600af6da43f9b991c02e452da450991147299 | |
parent | a4525b85568a71610db00c6873bee1ebb241969a (diff) | |
download | qemu-cf63c0cc3142c2e6359e147e071d485afe424ea4.tar.gz qemu-cf63c0cc3142c2e6359e147e071d485afe424ea4.tar.bz2 qemu-cf63c0cc3142c2e6359e147e071d485afe424ea4.zip |
emulator_options: introduced recursive variable substitution
Users can write variable position-independently.
Change-Id: I515843030f3d87bfea14a420133ffb1cdc4a1bac
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
(cherry picked from commit ba3014b1c0211cf36065a05f2ddd92a21fd68f8b)
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
-rw-r--r-- | tizen/src/emulator_options.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/tizen/src/emulator_options.c b/tizen/src/emulator_options.c index 8cb62e6b20..0cda59b4c3 100644 --- a/tizen/src/emulator_options.c +++ b/tizen/src/emulator_options.c @@ -134,7 +134,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; @@ -174,12 +174,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" @@ -293,9 +297,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); @@ -310,6 +314,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; } @@ -352,7 +362,7 @@ static bool assemble_args(int *argc, char **argv, } // substitute variables - argv[(*argc)++] = substitute_variables(str); + argv[(*argc)++] = substitute_variables(str, false); } return true; |