aboutsummaryrefslogtreecommitdiff
path: root/src/create_pkg.c
diff options
context:
space:
mode:
authordacctal <dacctal@symlinx.net>2026-06-07 05:58:15 +0000
committerdacctal <dacctal@symlinx.net>2026-06-07 05:58:15 +0000
commitea6745dd7ad75c85d0ea4471e9f3357532fb0eb0 (patch)
tree1b5a01898a845f579981303edb0709f9cc95a2f2 /src/create_pkg.c
parentab3f27fd2fb32a52f76146970823525f044a325c (diff)
tiny fixes & .editorconfig (thx indium)0.1.1
Diffstat (limited to 'src/create_pkg.c')
-rw-r--r--src/create_pkg.c103
1 files changed, 51 insertions, 52 deletions
diff --git a/src/create_pkg.c b/src/create_pkg.c
index 056a3ad..36e9d10 100644
--- a/src/create_pkg.c
+++ b/src/create_pkg.c
@@ -9,66 +9,65 @@
#include "vars.h"
Pkg create_pkg(const char *arg, const char *target) {
- Pkg pkg = {0};
- pkg.target = target;
- pkg.ver = "HEAD";
- pkg.is_local = false;
+ Pkg pkg = {0};
+ pkg.target = target;
+ pkg.ver = "HEAD";
+ pkg.is_local = false;
- cache_repos();
- for (int i = 0; i < cached_repos_count; i++) {
- if (strcmp(cached_repos[i].source_key, arg) == 0) {
- pkg.ver = cached_repos[i].version;
- }
+ for (int i = 0; i < cached_repos_count; i++) {
+ if (strcmp(cached_repos[i].source_key, arg) == 0) {
+ pkg.ver = cached_repos[i].version;
}
+ }
- 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';
- }
+ char *new_arg = strdup(arg);
+ if (!new_arg) exit(EXIT_FAILURE);
+ char *argver = strchr(new_arg, '@');
+ if (argver) {
+ pkg.ver = argver + 1;
+ *argver = '\0';
+ }
- init_lua_state();
- cache_repos();
+ bool is_in_repos = false;
+ for (size_t i = 0; i < cached_repos_count; i++) {
+ if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
+ is_in_repos = true;
+ break;
+ }
+ }
- bool is_in_repos = false;
+ 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.url);
+ pkg.is_local = true;
+ } else if (is_in_repos) {
for (size_t i = 0; i < cached_repos_count; i++) {
- if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
- is_in_repos = true;
- break;
- }
+ if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
+ pkg.url = strdup(cached_repos[i].source_value);
+ break;
+ }
}
+ pkg.name = strdup(new_arg);
+ } else {
+ printf("%s'%s' is not a valid package\n", print_error, new_arg);
+ exit(EXIT_FAILURE);
+ }
- 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(new_arg, cached_repos[i].source_key) == 0) {
- pkg.url = strdup(cached_repos[i].source_value);
- break;
- }
- }
- pkg.name = strdup(new_arg);
- } else {
- printf("%s'%s' is not a valid package\n", print_error, new_arg);
- exit(EXIT_FAILURE);
- }
+ if (strlen(pkg.name) > 4 && strncmp(pkg.name + strlen(pkg.name) - 4, ".git", 4) == 0) {
+ pkg.name[strlen(pkg.name) - 4] = '\0';
+ }
- 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);
- snprintf(pkg.src, MAX_PATH_LEN, "%s", src_dir);
- }
+ 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);
+ snprintf(pkg.src, MAX_PATH_LEN, "%s", src_dir);
+ }
- return pkg;
+ return pkg;
} \ No newline at end of file