Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add --setenv command line options to tesh
[simgrid.git] / tools / tesh / tesh.c
index 1e2034c..0cf2c06 100644 (file)
@@ -221,6 +221,20 @@ int main(int argc, char *argv[])
       memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
       argc -= 2;
       i -= 2;
       memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
       argc -= 2;
       i -= 2;
+    } else if (!strcmp(argv[i], "--setenv" )) {
+      if (i == argc - 1) {
+        ERROR0("--setenv argument requires an argument");
+        exit(1);
+      }
+      char *eq = strchr(argv[i+1], '=');
+      xbt_assert1(eq,"The argument of --setenv must contain a '=' (got %s instead)",argv[i+1]);
+      char *key = bprintf("%.*s", (int) (eq - argv[i+1]), argv[i+1]);
+      xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
+      free(key);
+      VERB1("setenv %s", argv[i+1]);
+      memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
+      argc -= 2;
+      i -= 2;
     }
   }
 
     }
   }