diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-05-25 14:37:41 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-05-25 21:02:40 +0200 |
commit | c4f4b38a84ac2f762f9a3acfb2f22d6b0d971899 (patch) | |
tree | 6838cb55b8322343af52e96b024c9073109bad9c | |
parent | c706eb101934ec05a1aa0fa75ab79f8b1ba405e8 (diff) |
main: simplify REQUIRE_SEARCH_PATH initialization
Do not require parsing in C, pre-split string in cmake and pass it as
command separated string array down to CPP, so that it can be interpolated
directly into a char *path[] array.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | main.c | 20 |
2 files changed, 9 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d34d79e..e9923f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,8 @@ OPTION(UCI_SUPPORT "UCI plugin support" ON) OPTION(LEGACY_SUPPORT "Support deprecated syntax features" ON) SET(LIB_SEARCH_PATH "${CMAKE_INSTALL_PREFIX}/lib/ucode/*.so:${CMAKE_INSTALL_PREFIX}/share/ucode/*.uc:./*.so:./*.uc" CACHE STRING "Default library search path") -ADD_DEFINITIONS(-DLIB_SEARCH_PATH="${LIB_SEARCH_PATH}") +STRING(REPLACE ":" "\", \"" LIB_SEARCH_DEFINE "${LIB_SEARCH_PATH}") +ADD_DEFINITIONS(-DLIB_SEARCH_PATH="${LIB_SEARCH_DEFINE}") IF(NOT APPLE) SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,--gc-sections") @@ -57,26 +57,20 @@ print_usage(const char *app) static void globals_init(uc_vm *vm, uc_value_t *scope, int argc, char **argv) { - uc_value_t *arr = ucv_array_new(vm); - const char *p, *last; - int i; + const char *path[] = { LIB_SEARCH_PATH }; + uc_value_t *arr; + size_t i; - for (p = last = LIB_SEARCH_PATH;; p++) { - if (*p == ':' || *p == '\0') { - ucv_array_push(arr, ucv_string_new_length(last, p - last)); - - if (!*p) - break; + arr = ucv_array_new(vm); - last = p + 1; - } - } + for (i = 0; i < sizeof(path) / sizeof(path[0]); i++) + ucv_array_push(arr, ucv_string_new(path[i])); ucv_object_add(scope, "REQUIRE_SEARCH_PATH", arr); arr = ucv_array_new(vm); - for (i = 0; i < argc; i++) + for (i = 0; i < (size_t)argc; i++) ucv_array_push(arr, ucv_string_new(argv[i])); ucv_object_add(scope, "ARGV", arr); |