- struct sigaction newact;
- memset(&newact,0, sizeof(newact));
- newact.sa_handler=SIG_IGN;
- sigaction(SIGPIPE,&newact,NULL);
-
- xbt_init(&argc,argv);
- rctx_init();
+ memset(&newact, 0, sizeof(newact));
+ newact.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &newact, NULL);
+
+ /* Get args */
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--cd")) {
+ if (i == argc - 1) {
+ ERROR0("--cd argument requires an argument");
+ exit(1);
+ }
+ if (chdir(argv[i + 1])) {
+ ERROR2("Cannot change directory to %s: %s", argv[i + 1],
+ strerror(errno));
+ exit(1);
+ }
+ INFO1("Change directory to %s", argv[i + 1]);
+ 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);
+ INFO2("setting environment variable '%s' to '%s'", key, eq+1);
+ free(key);
+ memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
+ argc -= 2;
+ i -= 2;
+ }
+ }