summaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-07-21 10:49:23 +0200
committerJo-Philipp Wich <jo@mein.io>2022-07-30 00:41:56 +0200
commit3c168b5184ebd217ea276bf374d28bbf937681fd (patch)
tree00da23f6c0500518c4bebc73e9b85566ef75f052 /main.c
parentd85bc716df9b97ac6093afa0bdf77c1b6b0cf6aa (diff)
vm, cli: move search path into global configuration structure
The upcoming compile-time module support will require the configured extension search path in the compiler as well, so move it to the already shared uc_parse_config_t structure and add the appropriate utility functions to initialize, append and free the search path vector. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'main.c')
-rw-r--r--main.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/main.c b/main.c
index d98b5d5..087efff 100644
--- a/main.c
+++ b/main.c
@@ -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);