emulator_options: introduced recursive variable substitution
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 17 Jun 2015 05:49:20 +0000 (14:49 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Fri, 8 Jan 2016 10:32:07 +0000 (19:32 +0900)
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>
tizen/src/emulator_options.c

index 8cb62e6b2008a88f0d7f44792041a4129f02638a..0cda59b4c33c202c0f09f9d9f6c0e5e775827f55 100644 (file)
@@ -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;