diff options
| author | dacctal <dacctal@symlinx.net> | 2026-05-25 06:39:29 +0000 |
|---|---|---|
| committer | dacctal <dacctal@symlinx.net> | 2026-05-25 06:39:29 +0000 |
| commit | 2dea5bc2ad4281042758f0e9bfe98fa96bc89412 (patch) | |
| tree | 325a53d3e82459b91a03e167fc8d32bc1c9f90ec /src/create_pkg.c | |
| parent | cb7e87a7889c8ee3f33db43dc2f5653385dc9e29 (diff) | |
declarative package management
Diffstat (limited to 'src/create_pkg.c')
| -rw-r--r-- | src/create_pkg.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/create_pkg.c b/src/create_pkg.c index eed9ef1..5bd91fa 100644 --- a/src/create_pkg.c +++ b/src/create_pkg.c @@ -14,40 +14,49 @@ Pkg create_pkg(const char *arg, const char *target) { pkg.ver = "HEAD"; pkg.is_local = false; + char* argver = strchr(arg, '@'); + char* new_arg = strdup(arg); + if (argver) { + argver += 1; + pkg.ver = argver; + int char_location = 0; + while (arg[char_location] != '@') { char_location++; } + new_arg[char_location] = '\0'; + } + init_lua_state(); cache_repos(); bool is_in_repos = false; for (size_t i = 0; i < cached_repos_count; i++) { - if (strcmp(arg, cached_repos[i].source_key) == 0) { + if (strcmp(new_arg, cached_repos[i].source_key) == 0) { is_in_repos = true; break; } } - if (strncmp(arg, "http", 4) == 0) { - pkg.url = strdup(arg); - pkg.name = name_from_url(arg); - } else if (strcmp(arg, ".") == 0) { + if (strncmp(new_arg, "http", 4) == 0) { + pkg.url = strdup(new_arg); + pkg.name = name_from_url(new_arg); + } else if (strcmp(new_arg, ".") == 0) { pkg.url = ""; getcwd(pkg.src, MAX_PATH_LEN); pkg.name = name_from_url(pkg.src); pkg.is_local = true; } else if (is_in_repos) { for (size_t i = 0; i < cached_repos_count; i++) { - if (strcmp(arg, cached_repos[i].source_key) == 0) { + if (strcmp(new_arg, cached_repos[i].source_key) == 0) { pkg.url = strdup(cached_repos[i].source_value); break; } } - pkg.name = strdup(arg); + pkg.name = strdup(new_arg); } else { - printf("%s'%s' is not a valid package\n", print_error, arg); - exit(1); + printf("%s'%s' is not a valid package\n", print_error, new_arg); + exit(EXIT_FAILURE); } cache_install_directories(); - if (!pkg.is_local) { char src_dir[MAX_PATH_LEN]; snprintf(src_dir, sizeof(src_dir), "%s/%s/%s", get_install_dir("src"), pkg.name, pkg.ver); |
