diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 60 |
1 files changed, 36 insertions, 24 deletions
@@ -387,14 +387,13 @@ parse_define_string(char *opt, uc_value_t *globals) } static void -parse_search_path(char *pattern, uc_value_t *globals) +parse_search_path(char *pattern, uc_parse_config_t *config) { - uc_value_t *rsp = ucv_object_get(globals, "REQUIRE_SEARCH_PATH", NULL); size_t len; char *p; if (strchr(pattern, '*')) { - ucv_array_push(rsp, ucv_string_new(pattern)); + uc_search_path_add(&config->module_search_path, pattern); return; } @@ -407,11 +406,11 @@ parse_search_path(char *pattern, uc_value_t *globals) pattern[--len] = 0; xasprintf(&p, "%s/*.so", pattern); - ucv_array_push(rsp, ucv_string_new(p)); + uc_search_path_add(&config->module_search_path, p); free(p); xasprintf(&p, "%s/*.uc", pattern); - ucv_array_push(rsp, ucv_string_new(p)); + uc_search_path_add(&config->module_search_path, p); free(p); } @@ -462,6 +461,7 @@ appname(const char *argv0) int main(int argc, char **argv) { + const char *optspec = "he:tST::RD:F:U:l:L:c::o:s"; char *interp = "/usr/bin/env ucode"; uc_source_t *source = NULL; FILE *precompile = NULL; @@ -480,6 +480,8 @@ main(int argc, char **argv) .raw_mode = true }; + uc_search_path_init(&config.module_search_path); + app = appname(argv[0]); if (argc == 1) { @@ -494,6 +496,31 @@ main(int argc, char **argv) stdin_unused = stdin; + /* parse options iteration 1: parse config related options */ + while ((opt = getopt(argc, argv, optspec)) != -1) + { + switch (opt) { + case 'L': + parse_search_path(optarg, &config); + break; + + case 'S': + config.strict_declarations = true; + break; + + case 'R': + config.raw_mode = true; + break; + + case 'T': + config.raw_mode = false; + parse_template_modeflags(optarg, &config); + break; + } + } + + optind = 1; + uc_vm_init(&vm, &config); /* load std functions into global scope */ @@ -504,8 +531,8 @@ main(int argc, char **argv) ucv_object_add(uc_vm_scope_get(&vm), "ARGV", ucv_get(o)); - /* parse options */ - while ((opt = getopt(argc, argv, "he:tST::RD:F:U:l:L:c::o:s")) != -1) + /* parse options iteration 2: process remaining options */ + while ((opt = getopt(argc, argv, optspec)) != -1) { switch (opt) { case 'h': @@ -520,19 +547,6 @@ main(int argc, char **argv) uc_vm_trace_set(&vm, 1); break; - case 'S': - config.strict_declarations = true; - break; - - case 'R': - config.raw_mode = true; - break; - - case 'T': - config.raw_mode = false; - parse_template_modeflags(optarg, &config); - break; - case 'D': if (!parse_define_string(optarg, uc_vm_scope_get(&vm))) { rv = 1; @@ -553,10 +567,6 @@ main(int argc, char **argv) ucv_object_delete(uc_vm_scope_get(&vm), optarg); break; - case 'L': - parse_search_path(optarg, uc_vm_scope_get(&vm)); - break; - case 'l': if (!parse_library_load(optarg, &vm)) { rv = 1; @@ -629,6 +639,8 @@ main(int argc, char **argv) rv = compile(&vm, source, precompile, strip, interp); out: + uc_search_path_free(&config.module_search_path); + uc_source_put(source); uc_vm_free(&vm); |