From eaef169d7563ea5b426c7a51c9afea9177d92b72 Mon Sep 17 00:00:00 2001 From: dacctal Date: Sun, 28 Jun 2026 03:00:32 +0000 Subject: added reason why i don't self host videos --- src/add_repo.c | 20 + src/build.c | 20 + src/cla_parse.c | 20 + src/cmd_out.c | 20 + src/create_pkg.c | 20 + src/declare.c | 20 + src/fetch_git.c | 20 + src/fetch_pwd.c | 20 + src/fetch_src.c | 20 + src/files.c | 20 + src/help.c | 20 + src/install_pkg.c | 20 + src/is_updated.c | 21 + src/list_pkgs.c | 20 + src/lua_build.c | 20 + src/lua_state.c | 1377 +++++++++++++++++++++-------------------- src/main.c | 34 +- src/name_from_url.c | 45 +- src/remove_pkg.c | 164 ++--- src/resolve_deps.c | 58 +- src/search.c | 39 +- src/set_install_directories.c | 113 ++-- src/setup_dirs.c | 35 +- src/setup_pkgit.c | 25 +- src/update_all.c | 58 +- src/update_pkg.c | 40 +- src/vars.c | 223 ++++--- 27 files changed, 1525 insertions(+), 987 deletions(-) (limited to 'src') diff --git a/src/add_repo.c b/src/add_repo.c index 71c3dda..11752b6 100644 --- a/src/add_repo.c +++ b/src/add_repo.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/build.c b/src/build.c index 5e96f52..66b9484 100644 --- a/src/build.c +++ b/src/build.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/cla_parse.c b/src/cla_parse.c index 3ca79ca..f2e7b2e 100644 --- a/src/cla_parse.c +++ b/src/cla_parse.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include diff --git a/src/cmd_out.c b/src/cmd_out.c index b800149..269d6f2 100644 --- a/src/cmd_out.c +++ b/src/cmd_out.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/create_pkg.c b/src/create_pkg.c index cb35ad0..6aae657 100644 --- a/src/create_pkg.c +++ b/src/create_pkg.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/declare.c b/src/declare.c index d01468a..07bf68d 100644 --- a/src/declare.c +++ b/src/declare.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/fetch_git.c b/src/fetch_git.c index f47b881..7116e9e 100644 --- a/src/fetch_git.c +++ b/src/fetch_git.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/fetch_pwd.c b/src/fetch_pwd.c index 7e2f2e4..e04bb31 100644 --- a/src/fetch_pwd.c +++ b/src/fetch_pwd.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/fetch_src.c b/src/fetch_src.c index 8646b1d..d3698db 100644 --- a/src/fetch_src.c +++ b/src/fetch_src.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/files.c b/src/files.c index 38e87be..0cd301d 100644 --- a/src/files.c +++ b/src/files.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/help.c b/src/help.c index 659caad..d7e01a0 100644 --- a/src/help.c +++ b/src/help.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include "help.h" diff --git a/src/install_pkg.c b/src/install_pkg.c index 32a84cd..80c6fd9 100644 --- a/src/install_pkg.c +++ b/src/install_pkg.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/is_updated.c b/src/is_updated.c index 124677a..3e1dd43 100644 --- a/src/is_updated.c +++ b/src/is_updated.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include @@ -24,6 +44,7 @@ bool is_updated(const char *src) { bool is_bldit_usable() { char* bldit_version = bldit_getver(); + if (!bldit_version) return false; if (strcmp(bldit_version, version) == 0) return true; bool prev_pass = false; for (size_t i = 0; i < strlen(bldit_version); i++) { diff --git a/src/list_pkgs.c b/src/list_pkgs.c index 6d4ba3f..ccc0e8a 100644 --- a/src/list_pkgs.c +++ b/src/list_pkgs.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include diff --git a/src/lua_build.c b/src/lua_build.c index 7a289fd..520117c 100644 --- a/src/lua_build.c +++ b/src/lua_build.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include diff --git a/src/lua_state.c b/src/lua_state.c index ed3f1cc..39dd089 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include @@ -17,754 +37,747 @@ static lua_State *B = NULL; static bool bldit_loaded = false; void push_lua_path(lua_State *L, const char *new_path) { - lua_getglobal(L, "package"); - lua_getfield(L, -1, "path"); - const char *current_path = lua_tostring(L, -1); - if (!current_path) - current_path = ""; - lua_pop(L, 1); - lua_pushfstring(L, "%s;%s", current_path, new_path); - lua_setfield(L, -2, "path"); - lua_pop(L, 1); + lua_getglobal(L, "package"); + lua_getfield(L, -1, "path"); + const char *current_path = lua_tostring(L, -1); + if (!current_path) current_path = ""; + lua_pop(L, 1); + lua_pushfstring(L, "%s;%s", current_path, new_path); + lua_setfield(L, -2, "path"); + lua_pop(L, 1); } void init_lua_state() { - if (L != NULL) - return; - L = luaL_newstate(); - luaL_openlibs(L); - char lua_path[MAX_PATH_LEN + 20]; - snprintf(lua_path, sizeof(lua_path), "%s/?.lua", config_dir); - push_lua_path(L, lua_path); - if (luaL_loadfile(L, config_file) || lua_pcall(L, 0, 0, 0)) { - printf( - "%s cannot run configuration script: %s\n", - print_error, lua_tostring(L, -1) - ); - printf("%s to generate a configuration file, head into the", print_pkgit); - printf(" root directory of the pkgit source and run `make defconfig`\n"); - exit(EXIT_FAILURE); - } - if (file_exists(repo_file)) { - if (luaL_loadfile(L, repo_file) || lua_pcall(L, 0, 0, 0)) { - printf( - "%s cannot load repository file: %s\n", - print_error, lua_tostring(L, -1) - ); - lua_pop(L, 1); - } - } - config_loaded = true; + if (L != NULL) return; + L = luaL_newstate(); + luaL_openlibs(L); + char lua_path[MAX_PATH_LEN + 20]; + snprintf(lua_path, sizeof(lua_path), "%s/?.lua", config_dir); + push_lua_path(L, lua_path); + if (luaL_loadfile(L, config_file) || lua_pcall(L, 0, 0, 0)) { + printf( + "%s cannot run configuration script: %s\n", + print_error, lua_tostring(L, -1) + ); + printf( + "%s to generate a configuration file, head into the", + print_pkgit + ); + printf( + " root directory of the pkgit source and run `make defconfig`\n" + ); + exit(EXIT_FAILURE); + } + if (file_exists(repo_file)) { + if (luaL_loadfile(L, repo_file) || lua_pcall(L, 0, 0, 0)) { + printf( + "%s cannot load repository file: %s\n", + print_error, lua_tostring(L, -1) + ); + lua_pop(L, 1); + } + } + config_loaded = true; } void init_bldit() { - if (B != NULL) - return; - B = luaL_newstate(); - luaL_openlibs(B); - if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { - if (is_verbose) printf( - "%s cannot run bldit script: %s\n", - print_warning, lua_tostring(B, -1) - ); - return; - } - bldit_loaded = true; + if (B != NULL) return; + B = luaL_newstate(); + luaL_openlibs(B); + if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { + if (is_verbose) printf( + "%s cannot run bldit script: %s\n", + print_warning, lua_tostring(B, -1) + ); + return; + } + bldit_loaded = true; } void free_lua_state() { - if (L != NULL) { - lua_close(L); - L = NULL; - } - config_loaded = false; + if (L != NULL) { + lua_close(L); + L = NULL; + } + config_loaded = false; } lua_State *get_lua_state() { return L; } void cache_prefix_directory() { - lua_getglobal(L, "prefix"); - if (!lua_isstring(L, -1)) { - printf( - "%s init.lua: 'prefix' is not a string.\n", - print_error - ); - return; - } - snprintf(prefix_dir, MAX_PATH_LEN, "%s", lua_tostring(L, -1)); - lua_pop(L, 1); + lua_getglobal(L, "prefix"); + if (!lua_isstring(L, -1)) { + printf( + "%s init.lua: 'prefix' is not a string.\n", + print_error + ); + return; + } + snprintf(prefix_dir, MAX_PATH_LEN, "%s", lua_tostring(L, -1)); + lua_pop(L, 1); } void cache_install_directories() { - if (!config_loaded || !lua_istable(L, -1)) { - lua_getglobal(L, "install_directories"); - } - if (!lua_istable(L, -1)) { - printf( - "%s init.lua: 'install_directories' is not a table.\n", - print_error - ); - return; - } - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - const char *key = lua_tostring(L, -2); - const char *value = lua_tostring(L, -1); - if (key && value) { - map_put(&cached_install_directories, strdup(key), strdup(value)); - } - lua_pop(L, 1); - } - lua_pop(L, 1); + if (!config_loaded || !lua_istable(L, -1)) { + lua_getglobal(L, "install_directories"); + } + if (!lua_istable(L, -1)) { + printf( + "%s init.lua: 'install_directories' is not a table.\n", + print_error + ); + return; + } + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + const char *key = lua_tostring(L, -2); + const char *value = lua_tostring(L, -1); + if (key && value) { + map_put(&cached_install_directories, strdup(key), strdup(value)); + } + lua_pop(L, 1); + } + lua_pop(L, 1); } void install_dependencies(lua_State *L) { - while (lua_next(L, -2) != 0) { - const char *depname = lua_tostring(L, -2); - if (depname && lua_istable(L, -1)) { - lua_getfield(L, -1, "url"); - const char *dep_url = lua_tostring(L, -1); - lua_pop(L, 1); - lua_getfield(L, -1, "version"); - const char *dep_version = lua_tostring(L, -1); - lua_pop(L, 1); - Pkg pkg = create_pkg(dep_url); - pkg.ver = strdup(dep_version); - const int top = lua_gettop(L); - char cwd[PATH_MAX]; - if (getcwd(cwd, sizeof(cwd)) != NULL) { - install_pkg(pkg); - chdir(cwd); - } - lua_settop(L, top); - } - lua_pop(L, 1); - } + while (lua_next(L, -2) != 0) { + const char *depname = lua_tostring(L, -2); + if (depname && lua_istable(L, -1)) { + lua_getfield(L, -1, "url"); + const char *dep_url = lua_tostring(L, -1); + lua_pop(L, 1); + lua_getfield(L, -1, "version"); + const char *dep_version = lua_tostring(L, -1); + lua_pop(L, 1); + Pkg pkg = create_pkg(dep_url); + pkg.ver = strdup(dep_version); + const int top = lua_gettop(L); + char cwd[PATH_MAX]; + if (getcwd(cwd, sizeof(cwd)) != NULL) { + install_pkg(pkg); + chdir(cwd); + } + lua_settop(L, top); + } + lua_pop(L, 1); + } } bool target_loop_build( - lua_State *L, const char* lua_file, const char *target + lua_State *L, const char* lua_file, const char *target ) { - lua_getfield(L, -1, target); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s' is not a table.\n", - print_warning, lua_file, target - ); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, "dependencies"); - if (lua_istable(L, -1)) { - lua_pushnil(L); - install_dependencies(L); - } - lua_pop(L, 1); - lua_getfield(L, -1, "build"); - if (!lua_isfunction(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s.build' is not a function.\n", - print_warning, lua_file, target - ); - lua_pop(L, 3); - return false; - } - if (lua_pcall(L, 0, 1, 0) != LUA_OK) { - printf( - "%s %s: 'targets.%s.build' function borked: %s\n", - print_error, lua_file, target, lua_tostring(L, -1) - ); - lua_pop(L, 3); - return false; - } - if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { - printf( - "%s %s: 'targets.%s.build' failed: %s\n", - print_error, lua_file, target, lua_tostring(L, -1) - ); - lua_pop(L, 3); - return false; - } - lua_pop(L, 3); - return true; + lua_getfield(L, -1, target); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s' is not a table.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, "dependencies"); + if (lua_istable(L, -1)) { + lua_pushnil(L); + install_dependencies(L); + } + lua_pop(L, 1); + lua_getfield(L, -1, "build"); + if (!lua_isfunction(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s.build' is not a function.\n", + print_warning, lua_file, target + ); + lua_pop(L, 3); + return false; + } + if (lua_pcall(L, 0, 1, 0) != LUA_OK) { + printf( + "%s %s: 'targets.%s.build' function borked: %s\n", + print_error, lua_file, target, lua_tostring(L, -1) + ); + lua_pop(L, 3); + return false; + } + if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { + printf( + "%s %s: 'targets.%s.build' failed: %s\n", + print_error, lua_file, target, lua_tostring(L, -1) + ); + lua_pop(L, 3); + return false; + } + lua_pop(L, 3); + return true; } -bool target_loop_install(lua_State *L, const char* lua_file, const char *target) { - lua_getfield(L, -1, target); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s' is not a table.\n", - print_warning, lua_file, target - ); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, "pre_install"); - if (!lua_isfunction(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s.pre_install' is not a function.\n", - print_warning, lua_file, target - ); - } else if (lua_pcall(L, 0, 1, 0) != LUA_OK) { - if (is_verbose) printf( - "%s %s: 'targets.%s.pre_install' function borked: %s\n", - print_warning, lua_file, target, lua_tostring(L, -1) - ); - if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { - printf( - "%s %s: 'targets.%s.pre_install' failed: %d\n", - print_error, lua_file, target, (int)lua_tonumber(L, -1) - ); - return false; - } - } - lua_pop(L, 1); - lua_getfield(L, -1, "install"); - if (!lua_isfunction(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s.install' is not a function.\n", - print_warning, lua_file, target - ); - lua_pop(L, 1); - return false; - } - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s %s: 'targets.%s.install' function borked: %s\n", - print_warning, lua_file, target, lua_tostring(L, -1) - ); - lua_pop(L, 1); - return false; - } - if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { - printf( - "%s %s: 'targets.%s.install' failed: %d\n", - print_error, lua_file, target, (int)lua_tonumber(L, -1) - ); - lua_pop(L, 1); - return false; - } - lua_pop(L, 1); - lua_getfield(L, -1, "post_install"); - if (!lua_isfunction(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s.post_install' is not a function.\n", - print_warning, lua_file, target - ); - } else if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s %s: 'targets.%s.post_install' function borked: %s\n", - print_warning, lua_file, target, lua_tostring(L, -1) - ); - if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { - printf( - "%s %s: 'targets.%s.post_install' failed: %s\n", - print_error, lua_file, target, lua_tostring(L, -1) - ); - } - } - lua_pop(L, 1); - return true; +bool target_loop_install( + lua_State *L, const char* lua_file, + const char *target +) { + lua_getfield(L, -1, target); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s' is not a table.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, "pre_install"); + if (!lua_isfunction(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s.pre_install' is not a function.\n", + print_warning, lua_file, target + ); + } else if (lua_pcall(L, 0, 1, 0) != LUA_OK) { + if (is_verbose) printf( + "%s %s: 'targets.%s.pre_install' function borked: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) + ); + if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { + printf( + "%s %s: 'targets.%s.pre_install' failed: %d\n", + print_error, lua_file, target, (int)lua_tonumber(L, -1) + ); + return false; + } + } + lua_pop(L, 1); + lua_getfield(L, -1, "install"); + if (!lua_isfunction(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s.install' is not a function.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); + return false; + } + if (lua_pcall(L, 0, 0, 0) != LUA_OK) { + if (is_verbose) printf( + "%s %s: 'targets.%s.install' function borked: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) + ); + lua_pop(L, 1); + return false; + } + if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { + printf( + "%s %s: 'targets.%s.install' failed: %d\n", + print_error, lua_file, target, (int)lua_tonumber(L, -1) + ); + lua_pop(L, 1); + return false; + } + lua_pop(L, 1); + lua_getfield(L, -1, "post_install"); + if (!lua_isfunction(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s.post_install' is not a function.\n", + print_warning, lua_file, target + ); + } else if (lua_pcall(L, 0, 0, 0) != LUA_OK) { + if (is_verbose) printf( + "%s %s: 'targets.%s.post_install' function borked: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) + ); + if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { + printf( + "%s %s: 'targets.%s.post_install' failed: %s\n", + print_error, lua_file, target, lua_tostring(L, -1) + ); + } + } + lua_pop(L, 1); + return true; } bool target_loop_uninstall(lua_State *L, const char *lua_file, const char *target) { - lua_getfield(L, -1, target); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s' is not a table.\n", - print_warning, lua_file, target - ); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, "uninstall"); - if (!lua_isfunction(L, -1)) { - if (is_verbose) printf( - "%s %s: 'targets.%s.uninstall' is not a function.\n", - print_warning, lua_file, target - ); - lua_pop(L, 1); - return false; - } - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s %s: 'targets.%s.uninstall' function borked: %s\n", - print_warning, lua_file, target, lua_tostring(L, -1) - ); - lua_pop(L, 1); - return false; - } - if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { - printf( - "%s %s: 'targets.%s.uninstall' failed: %s\n", - print_error, lua_file, target, lua_tostring(L, -1) - ); - lua_pop(L, 1); - return false; - } - lua_pop(L, 1); - return true; + lua_getfield(L, -1, target); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s' is not a table.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, "uninstall"); + if (!lua_isfunction(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s.uninstall' is not a function.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); + return false; + } + if (lua_pcall(L, 0, 0, 0) != LUA_OK) { + if (is_verbose) printf( + "%s %s: 'targets.%s.uninstall' function borked: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) + ); + lua_pop(L, 1); + return false; + } + if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) { + printf( + "%s %s: 'targets.%s.uninstall' failed: %s\n", + print_error, lua_file, target, lua_tostring(L, -1) + ); + lua_pop(L, 1); + return false; + } + lua_pop(L, 1); + return true; } bool repo_build(const char *repository, const char *target) { - lua_getglobal(L, "repositories"); - if (!config_loaded || !lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories' is not a table.\n", - print_warning - ); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, repository); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories.%s' is not a table.\n", - print_warning, repository - ); - lua_pop(L, 2); - return false; - } - - lua_getfield(L, -1, "dependencies"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories.%s.dependencies' is not a table.\n", - print_warning, repository - ); - } else { - lua_pushnil(L); - install_dependencies(L); - } - lua_pop(L, 1); - - lua_getfield(L, -1, "targets"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories.%s.targets' is not a table.\n", - print_warning, repository - ); - return false; - } - bool target_loop_success = target_loop_build(L, "init.lua", target); - lua_pop(L, 3); - return target_loop_success; + lua_getglobal(L, "repositories"); + if (!config_loaded || !lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories' is not a table.\n", + print_warning + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, repository); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s' is not a table.\n", + print_warning, repository + ); + lua_pop(L, 2); + return false; + } + + lua_getfield(L, -1, "dependencies"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s.dependencies' is not a table.\n", + print_warning, repository + ); + } else { + lua_pushnil(L); + install_dependencies(L); + } + lua_pop(L, 1); + + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s.targets' is not a table.\n", + print_warning, repository + ); + return false; + } + bool target_loop_success = target_loop_build(L, "init.lua", target); + lua_pop(L, 3); + return target_loop_success; } bool repo_install(const char *repository, const char* target) { - lua_getglobal(L, "repositories"); - if (!config_loaded || !lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories' is not a table.\n", - print_warning - ); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, repository); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories.%s' is not a table.\n", - print_warning, repository - ); - lua_pop(L, 2); - return false; - } - - lua_getfield(L, -1, "targets"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories.%s.targets' is not a table.\n", - print_warning, repository - ); - return false; - } - bool target_loop_success = target_loop_install(L, "init.lua", target); - lua_pop(L, 3); - return target_loop_success; + lua_getglobal(L, "repositories"); + if (!config_loaded || !lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories' is not a table.\n", + print_warning + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, repository); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s' is not a table.\n", + print_warning, repository + ); + lua_pop(L, 2); + return false; + } + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s.targets' is not a table.\n", + print_warning, repository + ); + return false; + } + bool target_loop_success = target_loop_install(L, "init.lua", target); + lua_pop(L, 3); + return target_loop_success; } bool repo_uninstall(const char *repository, const char *target) { - lua_getglobal(L, "repositories"); - if (!config_loaded || !lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories' is not a table.\n", - print_warning - ); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, repository); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories.%s' is not a table.\n", - print_warning, repository - ); - lua_pop(L, 2); - return false; - } - - lua_getfield(L, -1, "targets"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'repositories.%s.targets' is not a table.\n", - print_warning, repository - ); - return false; - } - bool target_loop_success = target_loop_uninstall(L, "init.lua", target); - lua_pop(L, 2); - return target_loop_success; + lua_getglobal(L, "repositories"); + if (!config_loaded || !lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories' is not a table.\n", + print_warning + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, repository); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s' is not a table.\n", + print_warning, repository + ); + lua_pop(L, 2); + return false; + } + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s.targets' is not a table.\n", + print_warning, repository + ); + return false; + } + bool target_loop_success = target_loop_uninstall(L, "init.lua", target); + lua_pop(L, 2); + return target_loop_success; } char* bldit_getver() { - init_bldit(); - lua_getglobal(B, "bldit_version"); - if (!lua_isstring(B, -1)) { - if (is_verbose) - printf("%s bldit.lua: 'bldit_version' is not a string.\n", print_warning); - return NULL; - } - const char* bldit_version = lua_tostring(B, -1); - return strdup(bldit_version); + init_bldit(); + lua_getglobal(B, "bldit_version"); + if (!lua_isstring(B, -1)) { + if (is_verbose) printf( + "%s bldit.lua: 'bldit_version' is not a string.\n", + print_warning + ); + lua_pop(B, 1); + return NULL; + } + const char* bldit_version = lua_tostring(B, -1); + lua_pop(B, 1); + return strdup(bldit_version); } char* bldit_pkg_getver() { - init_bldit(); - lua_getglobal(B, "package_version"); - if (!lua_isstring(B, -1)) { - if (is_verbose) - printf("%s bldit.lua: 'package_version' is not a string.\n", print_warning); - return NULL; - } - const char* package_version = lua_tostring(B, -1); - return strdup(package_version); + init_bldit(); + lua_getglobal(B, "package_version"); + if (!lua_isstring(B, -1)) { + if (is_verbose) printf( + "%s bldit.lua: 'package_version' is not a string.\n", + print_warning + ); + lua_pop(B, 1); + return NULL; + } + const char* package_version = lua_tostring(B, -1); + lua_pop(B, 1); + return strdup(package_version); } bool bldit(const char *target) { - lua_State *B = luaL_newstate(); - luaL_openlibs(B); - - if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { - if (is_verbose) printf( - "%s cannot run bldit script: %s\n", - print_warning, lua_tostring(B, -1) - ); - lua_close(B); - return false; - } - - if (!is_bldit_usable()) { - printf( - "%s bldit version is newer than the installed pkgit version\n", - print_error - ); - printf( - "%s consider updating pkgit\n", - print_pkgit - ); - if (!is_forced) return false; - } - - lua_pushfstring(B, "%s", prefix_dir); - lua_setglobal(B, "prefix"); - lua_pop(B, 1); - - lua_getglobal(B, "dependencies"); - if (!lua_istable(B, -1)) { - if (is_verbose) printf("%s bldit.lua: 'dependencies' is not a table.\n", print_warning); - } else { - lua_pushnil(B); - install_dependencies(B); - } - lua_pop(B, 1); - - lua_getglobal(B, "targets"); - if (!lua_istable(B, -1)) { - if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning); - lua_close(B); - return false; - } - - bool target_loop_success = target_loop_build(B, "bldit.lua", target); - lua_pop(B, 2); - lua_close(B); - return target_loop_success; + lua_State *B = luaL_newstate(); + luaL_openlibs(B); + if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { + if (is_verbose) printf( + "%s cannot run bldit script: %s\n", + print_warning, lua_tostring(B, -1) + ); + lua_close(B); + return false; + } + if (!is_bldit_usable()) { + printf( + "%s bldit version is newer than the installed pkgit version\n", + print_error + ); + printf( + "%s consider updating pkgit\n", + print_pkgit + ); + if (!is_forced) return false; + } + lua_pushfstring(B, "%s", prefix_dir); + lua_setglobal(B, "prefix"); + lua_pop(B, 1); + lua_getglobal(B, "dependencies"); + if (!lua_istable(B, -1)) { + if (is_verbose) printf( + "%s bldit.lua: 'dependencies' is not a table.\n", print_warning + ); + } else { + lua_pushnil(B); + install_dependencies(B); + } + lua_pop(B, 1); + lua_getglobal(B, "targets"); + if (!lua_istable(B, -1)) { + if (is_verbose) printf( + "%s bldit.lua: 'targets' is not a table.\n", print_warning + ); + lua_close(B); + return false; + } + bool target_loop_success = target_loop_build(B, "bldit.lua", target); + lua_pop(B, 2); + lua_close(B); + return target_loop_success; } bool bldit_install(const char *target) { - lua_State *B = luaL_newstate(); - luaL_openlibs(B); - - if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { - if (is_verbose) printf( - "%s cannot run bldit script: %s\n", - print_warning, lua_tostring(B, -1) - ); - lua_close(B); - return false; - } - - if (!is_bldit_usable()) { - printf( - "%s bldit version is newer than the installed pkgit version\n", - print_error - ); - printf( - "%s consider updating pkgit\n", - print_pkgit - ); - if (!is_forced) return false; - } - - lua_pushfstring(B, "%s", prefix_dir); - lua_setglobal(B, "prefix"); - lua_pop(B, 1); - - lua_getglobal(B, "targets"); - if (!lua_istable(B, -1)) { - if (is_verbose) printf( - "%s bldit.lua: 'targets' is not a table.\n", - print_warning - ); - lua_pop(B, 1); - lua_close(B); - return false; - } - - bool target_loop_success = target_loop_install(B, "bldit.lua", target); - lua_pop(B, 1); - lua_close(B); - return target_loop_success; + lua_State *B = luaL_newstate(); + luaL_openlibs(B); + if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { + if (is_verbose) printf( + "%s cannot run bldit script: %s\n", + print_warning, lua_tostring(B, -1) + ); + lua_close(B); + return false; + } + if (!is_bldit_usable()) { + printf( + "%s bldit version is newer than the installed pkgit version\n", + print_error + ); + printf( + "%s consider updating pkgit\n", + print_pkgit + ); + if (!is_forced) return false; + } + lua_pushfstring(B, "%s", prefix_dir); + lua_setglobal(B, "prefix"); + lua_pop(B, 1); + lua_getglobal(B, "targets"); + if (!lua_istable(B, -1)) { + if (is_verbose) printf( + "%s bldit.lua: 'targets' is not a table.\n", + print_warning + ); + lua_pop(B, 1); + lua_close(B); + return false; + } + bool target_loop_success = target_loop_install(B, "bldit.lua", target); + lua_pop(B, 1); + lua_close(B); + return target_loop_success; } bool bldit_uninstall(const char *target) { - lua_State *B = luaL_newstate(); - luaL_openlibs(B); - - if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { - if (is_verbose) printf( - "%s cannot run bldit script: %s\n", - print_warning, lua_tostring(B, -1) - ); - lua_close(B); - return false; - } - - if (!is_bldit_usable()) { - printf( - "%s bldit version is newer than the installed pkgit version\n", - print_error - ); - printf( - "%s consider updating pkgit\n", - print_pkgit - ); - if (!is_forced) return false; - } - - lua_pushfstring(B, "%s", prefix_dir); - lua_setglobal(B, "prefix"); - lua_pop(B, 1); - - lua_getglobal(B, "targets"); - if (!lua_istable(B, -1)) { - if (is_verbose) printf( - "%s bldit.lua: 'targets' is not a table.\n", - print_warning - ); - lua_close(B); - return false; - } - - lua_getfield(B, -1, target); - if (!lua_istable(B, -1)) { - if (is_verbose) printf( - "%s bldit.lua: 'targets.%s' is not a table.\n", - print_warning, target - ); - lua_pop(B, 2); - lua_close(B); - return false; - } - - lua_getglobal(B, "targets"); - if (!lua_istable(B, -1)) { - if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning); - lua_close(B); - return false; - } - bool target_loop_success = target_loop_uninstall(B, "bldit.lua", target); - lua_pop(B, 1); - lua_close(B); - return target_loop_success; + lua_State *B = luaL_newstate(); + luaL_openlibs(B); + if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { + if (is_verbose) printf( + "%s cannot run bldit script: %s\n", + print_warning, lua_tostring(B, -1) + ); + lua_close(B); + return false; + } + if (!is_bldit_usable()) { + printf( + "%s bldit version is newer than the installed pkgit version\n", + print_error + ); + printf( + "%s consider updating pkgit\n", + print_pkgit + ); + if (!is_forced) return false; + } + lua_pushfstring(B, "%s", prefix_dir); + lua_setglobal(B, "prefix"); + lua_pop(B, 1); + lua_getglobal(B, "targets"); + if (!lua_istable(B, -1)) { + if (is_verbose) printf( + "%s bldit.lua: 'targets' is not a table.\n", + print_warning + ); + lua_close(B); + return false; + } + lua_getfield(B, -1, target); + if (!lua_istable(B, -1)) { + if (is_verbose) printf( + "%s bldit.lua: 'targets.%s' is not a table.\n", + print_warning, target + ); + lua_pop(B, 2); + lua_close(B); + return false; + } + lua_getglobal(B, "targets"); + if (!lua_istable(B, -1)) { + if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning); + lua_close(B); + return false; + } + bool target_loop_success = target_loop_uninstall(B, "bldit.lua", target); + lua_pop(B, 1); + lua_close(B); + return target_loop_success; } void cache_repos() { - cached_repos_count = 0; - lua_getglobal(L, "repositories"); - if (!config_loaded || !lua_istable(L, -1)) { - printf( - "%s init.lua: 'repositories' is not a table.\n", - print_error - ); - lua_pop(L, 1); - return; - } - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - const char *repo_name = lua_tostring(L, -2); - if (!repo_name || !lua_istable(L, -1)) { - printf("%s init.lua: 'repositories.%s' is not a table\n", print_error, repo_name); - lua_pop(L, 1); - continue; - } - Repo *repo = &cached_repos[cached_repos_count]; - repo->source_key = strdup(repo_name); - lua_getfield(L, -1, "url"); - const char *url = lua_tostring(L, -1); - repo->source_value = url ? strdup(url) : strdup(""); - lua_pop(L, 1); - lua_getfield(L, -1, "version"); - const char *version = lua_tostring(L, -1); - repo->version = version ? strdup(version) : strdup("HEAD"); - lua_pop(L, 1); - lua_pop(L, 1); - cached_repos_count++; - } - lua_pop(L, 1); + cached_repos_count = 0; + lua_getglobal(L, "repositories"); + if (!config_loaded || !lua_istable(L, -1)) { + printf( + "%s init.lua: 'repositories' is not a table.\n", + print_error + ); + lua_pop(L, 1); + return; + } + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + const char *repo_name = lua_tostring(L, -2); + if (!repo_name || !lua_istable(L, -1)) { + printf("%s init.lua: 'repositories.%s' is not a table\n", print_error, repo_name); + lua_pop(L, 1); + continue; + } + Repo *repo = &cached_repos[cached_repos_count]; + repo->source_key = strdup(repo_name); + lua_getfield(L, -1, "url"); + const char *url = lua_tostring(L, -1); + repo->source_value = url ? strdup(url) : strdup(""); + lua_pop(L, 1); + lua_getfield(L, -1, "version"); + const char *version = lua_tostring(L, -1); + repo->version = version ? strdup(version) : strdup("HEAD"); + lua_pop(L, 1); + lua_pop(L, 1); + cached_repos_count++; + } + lua_pop(L, 1); } void cache_build_systems() { - if (!config_loaded) { - lua_getglobal(L, "build_systems"); - } else if (!lua_istable(L, -1)) { - lua_getglobal(L, "build_systems"); - } - - if (!lua_istable(L, -1)) { - printf("%s init.lua: 'build_systems' is not a table.\n", print_error); - return; - } - - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - const char *key = lua_tostring(L, -2); - if (lua_isfunction(L, -1) == 0) { - printf("%s init.lua: 'build_systems.%s' is not a function\n", print_error, key); - lua_pop(L, 1); - continue; - } - - map_put(&cached_build_systems, strdup(key), ""); - lua_pop(L, 1); - } - lua_pop(L, 1); + if (!config_loaded) { + lua_getglobal(L, "build_systems"); + } else if (!lua_istable(L, -1)) { + lua_getglobal(L, "build_systems"); + } + if (!lua_istable(L, -1)) { + printf("%s init.lua: 'build_systems' is not a table.\n", print_error); + return; + } + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + const char *key = lua_tostring(L, -2); + if (lua_isfunction(L, -1) == 0) { + printf("%s init.lua: 'build_systems.%s' is not a function\n", print_error, key); + lua_pop(L, 1); + continue; + } + map_put(&cached_build_systems, strdup(key), ""); + lua_pop(L, 1); + } + lua_pop(L, 1); } bool config_build(const char *path, const char *target) { - lua_getglobal(L, "build_systems"); - if (!config_loaded || !lua_istable(L, -1)) { - lua_pop(L, 1); - return false; - } - bool target_loop_success = false; - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - const char *key = lua_tostring(L, -2); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - continue; - } - char file_path[MAX_PATH_LEN]; - snprintf(file_path, sizeof(file_path), "%s/%s", path, key); - if (access(file_path, F_OK) != 0) { - lua_pop(L, 1); - continue; - } - lua_getfield(L, -1, "targets"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf("%s init.lua: 'targets' is not a table.\n", print_warning); - lua_pop(L, 1); - continue; - } - target_loop_success = target_loop_build(L, "init.lua", target); - lua_pop(L, 1); - } - lua_pop(L, 1); - return target_loop_success; + lua_getglobal(L, "build_systems"); + if (!config_loaded || !lua_istable(L, -1)) { + lua_pop(L, 1); + return false; + } + bool target_loop_success = false; + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + const char *key = lua_tostring(L, -2); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + continue; + } + char file_path[MAX_PATH_LEN]; + snprintf(file_path, sizeof(file_path), "%s/%s", path, key); + if (access(file_path, F_OK) != 0) { + lua_pop(L, 1); + continue; + } + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf("%s init.lua: 'targets' is not a table.\n", print_warning); + lua_pop(L, 1); + continue; + } + target_loop_success = target_loop_build(L, "init.lua", target); + lua_pop(L, 1); + } + lua_pop(L, 1); + return target_loop_success; } bool config_install(const char *path, const char *target) { - lua_getglobal(L, "build_systems"); - if (!config_loaded || !lua_istable(L, -1)) { - lua_pop(L, 1); - return false; - } - lua_pushnil(L); - bool target_loop_success = false; - while (lua_next(L, -2) != 0) { - const char *key = lua_tostring(L, -2); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - continue; - } - char file_path[MAX_PATH_LEN]; - snprintf(file_path, sizeof(file_path), "%s/%s", path, key); - if (access(file_path, F_OK) != 0) { - lua_pop(L, 1); - continue; - } - - lua_getfield(L, -1, "targets"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'build_systems.%s.targets' is not a table.\n", - print_warning, key - ); - lua_close(L); - return false; - } - target_loop_success = target_loop_install(L, "init.lua", target); - lua_pop(L, 2); - } - lua_pop(L, 1); - return target_loop_success; + lua_getglobal(L, "build_systems"); + if (!config_loaded || !lua_istable(L, -1)) { + lua_pop(L, 1); + return false; + } + lua_pushnil(L); + bool target_loop_success = false; + while (lua_next(L, -2) != 0) { + const char *key = lua_tostring(L, -2); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + continue; + } + char file_path[MAX_PATH_LEN]; + snprintf(file_path, sizeof(file_path), "%s/%s", path, key); + if (access(file_path, F_OK) != 0) { + lua_pop(L, 1); + continue; + } + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'build_systems.%s.targets' is not a table.\n", + print_warning, key + ); + lua_close(L); + return false; + } + target_loop_success = target_loop_install(L, "init.lua", target); + lua_pop(L, 2); + } + lua_pop(L, 1); + return target_loop_success; } bool config_uninstall(const char *path, const char *target) { - lua_getglobal(L, "build_systems"); - if (!config_loaded || !lua_istable(L, -1)) { - lua_pop(L, 1); - return false; - } - bool target_loop_success = false; - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - const char *key = lua_tostring(L, -2); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - continue; - } - char file_path[MAX_PATH_LEN]; - snprintf(file_path, sizeof(file_path), "%s/%s", path, key); - if (access(file_path, F_OK) != 0) { - lua_pop(L, 1); - continue; - } - - lua_getfield(L, -1, "targets"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s init.lua: 'build_systems.%s.targets' is not a table.\n", - print_warning, key - ); - lua_close(L); - return false; - } - target_loop_success = target_loop_uninstall(L, "init.lua", target); - lua_pop(L, 2); - } - lua_pop(L, 1); - return target_loop_success; + lua_getglobal(L, "build_systems"); + if (!config_loaded || !lua_istable(L, -1)) { + lua_pop(L, 1); + return false; + } + bool target_loop_success = false; + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + const char *key = lua_tostring(L, -2); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + continue; + } + char file_path[MAX_PATH_LEN]; + snprintf(file_path, sizeof(file_path), "%s/%s", path, key); + if (access(file_path, F_OK) != 0) { + lua_pop(L, 1); + continue; + } + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'build_systems.%s.targets' is not a table.\n", + print_warning, key + ); + lua_close(L); + return false; + } + target_loop_success = target_loop_uninstall(L, "init.lua", target); + lua_pop(L, 2); + } + lua_pop(L, 1); + return target_loop_success; } diff --git a/src/main.c b/src/main.c index 9010d3e..6265db1 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,22 @@ -#include +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ #include "cla_parse.h" #include "lua_state.h" @@ -6,11 +24,11 @@ #include "vars.h" int main(int argc, char *argv[]) { - init_vars(); - init_lua_state(); - setup_pkgit(); - cache_repos(); - cla_parse(argc, argv); - free_lua_state(); - return 0; + init_vars(); + init_lua_state(); + setup_pkgit(); + cache_repos(); + cla_parse(argc, argv); + free_lua_state(); + return 0; } \ No newline at end of file diff --git a/src/name_from_url.c b/src/name_from_url.c index 0140e1a..d7d892e 100644 --- a/src/name_from_url.c +++ b/src/name_from_url.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include @@ -5,19 +25,14 @@ #include "name_from_url.h" char* name_from_url(const char *url) { - size_t len = strlen(url); - char* after_git = strdup(url); - const char *end = after_git + len; - while (end > after_git && *(end-1) == '/') { - end--; - } - const char *last_slash = end; - while (last_slash > after_git && *(last_slash-1) != '/') { - last_slash--; - } - if (last_slash < end) { - return strndup(last_slash, end - last_slash); - } else { - return strndup(after_git, end - after_git); - } + size_t len = strlen(url); + char* after_git = strdup(url); + const char *end = after_git + len; + while (end > after_git && *(end-1) == '/') + end--; + const char *last_slash = end; + while (last_slash > after_git && *(last_slash-1) != '/') + last_slash--; + if (last_slash < end) return strndup(last_slash, end - last_slash); + else return strndup(after_git, end - after_git); } diff --git a/src/remove_pkg.c b/src/remove_pkg.c index ac723b3..71d2f2f 100644 --- a/src/remove_pkg.c +++ b/src/remove_pkg.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include @@ -10,85 +30,89 @@ #include "vars.h" static int remove_installed( - const char *src_path, const struct stat *sb, - int typeflag, struct FTW *ftwbuf + const char *src_path, const struct stat *sb, + int typeflag, struct FTW *ftwbuf ) { - (void)sb; - (void)ftwbuf; + (void)sb; + (void)ftwbuf; - if (typeflag == FTW_F) { - const char *filename = src_path + ftwbuf->base; - const char *ext = strrchr(filename, '.'); - if (!ext) - ext = ""; + if (typeflag == FTW_F) { + const char *filename = src_path + ftwbuf->base; + const char *ext = strrchr(filename, '.'); + if (!ext) + ext = ""; - if (strncmp(ext, ".so", 3) == 0) { - char dest[MAX_PATH_LEN]; - snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("lib"), filename); - if (file_exists(dest)) - remove(dest); - } else if (access(src_path, X_OK) == 0) { - if (strcmp(ext, ".sample") != 0 && strcmp(filename, "bldit") != 0 && - strcmp(filename, "build.sh") != 0 && - strcmp(filename, "compile.sh") != 0) { - char dest[MAX_PATH_LEN]; - snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("bin"), filename); - if (file_exists(dest)) - remove(dest); - } - } else if (strcmp(ext, ".h") == 0) { - char dest[MAX_PATH_LEN]; - snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("include"), - filename); - if (file_exists(dest)) - remove(dest); - } - } - - return 0; + if (strncmp(ext, ".so", 3) == 0) { + char dest[MAX_PATH_LEN]; + snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("lib"), filename); + if (file_exists(dest)) + remove(dest); + } else if (access(src_path, X_OK) == 0) { + if ( + strcmp(ext, ".sample") != 0 && + strcmp(filename, "bldit") != 0 && + strcmp(filename, "build.sh") != 0 && + strcmp(filename, "compile.sh") != 0 + ) { + char dest[MAX_PATH_LEN]; + snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("bin"), filename); + if (file_exists(dest)) + remove(dest); + } + } else if (strcmp(ext, ".h") == 0) { + char dest[MAX_PATH_LEN]; + snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("include"), + filename); + if (file_exists(dest)) + remove(dest); + } + } + return 0; } -static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, - struct FTW *ftwbuf) { - (void)sb; - (void)ftwbuf; - if (typeflag == FTW_F || typeflag == FTW_SL) { - unlink(fpath); - } else if (typeflag == FTW_DP) { - rmdir(fpath); - } - return 0; +static int remove_tree( + const char *fpath, const struct stat *sb, + int typeflag, struct FTW *ftwbuf +) { + (void)sb; + (void)ftwbuf; + if (typeflag == FTW_F || typeflag == FTW_SL) { + unlink(fpath); + } else if (typeflag == FTW_DP) { + rmdir(fpath); + } + return 0; } void remove_pkg(Pkg pkg) { - if (!is_directory(pkg.src)) { - printf("%s %s is not installed!\n", print_pkgit, pkg.name); - return; - } - chdir(pkg.src); + if (!is_directory(pkg.src)) { + printf("%s %s is not installed!\n", print_pkgit, pkg.name); + return; + } + chdir(pkg.src); - bool uninstall_available = false; - if (!uninstall_available) if (repo_uninstall(pkg.name, pkg.target)) - uninstall_available = true; - if (!uninstall_available) if (bldit_uninstall(pkg.target)) - uninstall_available = true; - if (!uninstall_available) if (config_uninstall(pkg.src, pkg.target)) - uninstall_available = true; + bool uninstall_available = false; + if (!uninstall_available) if (repo_uninstall(pkg.name, pkg.target)) + uninstall_available = true; + if (!uninstall_available) if (bldit_uninstall(pkg.target)) + uninstall_available = true; + if (!uninstall_available) if (config_uninstall(pkg.src, pkg.target)) + uninstall_available = true; - if (!uninstall_available) printf( - "%s no uninstall function availible for package: %s\n", - print_error, pkg.name - ); + if (!uninstall_available) printf( + "%s no uninstall function availible for package: %s\n", + print_error, pkg.name + ); - nftw(pkg.src, remove_installed, 64, FTW_PHYS); - const char *last_slash = strrchr(pkg.src, '/'); - char target[MAX_PATH_LEN]; - if (last_slash && last_slash != pkg.src) { - size_t parent_len = last_slash - pkg.src; - snprintf(target, sizeof(target), "%.*s", (int)parent_len, pkg.src); - } else { - snprintf(target, sizeof(target), "%s", pkg.src); - } - nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS); - printf("%s removed %s\n", print_success, pkg.name); + nftw(pkg.src, remove_installed, 64, FTW_PHYS); + const char *last_slash = strrchr(pkg.src, '/'); + char target[MAX_PATH_LEN]; + if (last_slash && last_slash != pkg.src) { + size_t parent_len = last_slash - pkg.src; + snprintf(target, sizeof(target), "%.*s", (int)parent_len, pkg.src); + } else { + snprintf(target, sizeof(target), "%s", pkg.src); + } + nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS); + printf("%s removed %s\n", print_success, pkg.name); } \ No newline at end of file diff --git a/src/resolve_deps.c b/src/resolve_deps.c index ed728d4..32118f0 100644 --- a/src/resolve_deps.c +++ b/src/resolve_deps.c @@ -1,28 +1,44 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include "resolve_deps.h" void resolve_deps(void) { - const char *frame_top = " (c _c)"; - const char *frame1_bot = "_/ \\-"; - const char *frame2_bot = "-/ \\_"; - - printf("\033[2J\033[H"); - printf("Unfortunately due to budget issues, we could not afford a progress bar. Enjoy this instead:\n\n"); - - for (int i = 0; i < 16; i++) { - printf("%s\n%s\n", frame_top, i % 2 == 0 ? frame1_bot : frame2_bot); - for (int j = 0; j <= i; j++) { - printf("."); - } - printf("\n"); - fflush(stdout); - sleep(1); - if (i < 15) { - printf("\033[3A"); - } - } - printf("\n"); - printf("Dependencies resolved! (this does nothing)\n"); + const char *frame_top = " (c _c)"; + const char *frame1_bot = "_/ \\-"; + const char *frame2_bot = "-/ \\_"; + + printf("\033[2J\033[H"); + printf("Unfortunately due to budget issues, we could not afford a progress bar. Enjoy this instead:\n\n"); + + for (int i = 0; i < 16; i++) { + printf("%s\n%s\n", frame_top, i % 2 == 0 ? frame1_bot : frame2_bot); + for (int j = 0; j <= i; j++) printf("."); + printf("\n"); + fflush(stdout); + sleep(1); + if (i < 15) printf("\033[3A"); + } + printf("\n"); + printf("Dependencies resolved! (this does nothing)\n"); } diff --git a/src/search.c b/src/search.c index 72fe350..19f9963 100644 --- a/src/search.c +++ b/src/search.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include @@ -5,14 +25,13 @@ #include "search.h" void search(const char* arg) { - if (!arg) { - for (size_t i = 0; i < cached_repos_count; i++) { - printf("%s\n", cached_repos[i].source_key); - } - return; - } - for (size_t i = 0; i < cached_repos_count; i++) { - if (!strstr(cached_repos[i].source_key, arg)) continue; - printf("%s\n", cached_repos[i].source_key); - } + if (!arg) { + for (size_t i = 0; i < cached_repos_count; i++) + printf("%s\n", cached_repos[i].source_key); + return; + } + for (size_t i = 0; i < cached_repos_count; i++) { + if (!strstr(cached_repos[i].source_key, arg)) continue; + printf("%s\n", cached_repos[i].source_key); + } } diff --git a/src/set_install_directories.c b/src/set_install_directories.c index b99e227..7a4b59e 100644 --- a/src/set_install_directories.c +++ b/src/set_install_directories.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include @@ -7,62 +27,57 @@ #include "vars.h" void set_install_directories() { - lua_State *L = get_lua_state(); - cache_prefix_directory(); - lua_getglobal(L, "install_directories"); - if (!lua_istable(L, -1)) { - printf( - "%slua variable 'install_directories' is not a table.\n", - print_error - ); - } - - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - const char *key = lua_tostring(L, -2); - const char *value = lua_tostring(L, -1); - if (key && value) { - map_put(&cached_install_directories, strdup(key), strdup(value)); - } - lua_pop(L, 1); - } + lua_State *L = get_lua_state(); + cache_prefix_directory(); + lua_getglobal(L, "install_directories"); + if (!lua_istable(L, -1)) { + printf( + "%slua variable 'install_directories' is not a table.\n", + print_error + ); + } + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + const char *key = lua_tostring(L, -2); + const char *value = lua_tostring(L, -1); + if (key && value) { + map_put(&cached_install_directories, strdup(key), strdup(value)); + } + lua_pop(L, 1); + } } void map_init(Map *map) { - map->items = NULL; - map->size = 0; - map->capacity = 0; + map->items = NULL; + map->size = 0; + map->capacity = 0; } void map_put(Map *map, char *key, char *value) { - for (size_t i = 0; i < map->size; i++) { - if (strcmp(map->items[i].key, key) == 0) { - free(map->items[i].value); - map->items[i].value = value; - free(key); - return; - } - } - - if (map->size >= map->capacity) { - size_t new_capacity = map->capacity == 0 ? 8 : map->capacity * 2; - MapItem *new_items = realloc(map->items, new_capacity * sizeof(MapItem)); - if (!new_items) - return; - map->items = new_items; - map->capacity = new_capacity; - } - - map->items[map->size].key = key; - map->items[map->size].value = value; - map->size++; + for (size_t i = 0; i < map->size; i++) { + if (strcmp(map->items[i].key, key) == 0) { + free(map->items[i].value); + map->items[i].value = value; + free(key); + return; + } + } + if (map->size >= map->capacity) { + size_t new_capacity = map->capacity == 0 ? 8 : map->capacity * 2; + MapItem *new_items = realloc(map->items, new_capacity * sizeof(MapItem)); + if (!new_items) return; + map->items = new_items; + map->capacity = new_capacity; + } + map->items[map->size].key = key; + map->items[map->size].value = value; + map->size++; } char *map_get(Map *map, const char *key) { - for (size_t i = 0; i < map->size; i++) { - if (strcmp(map->items[i].key, key) == 0) { - return map->items[i].value; - } - } - return NULL; + for (size_t i = 0; i < map->size; i++) { + if (strcmp(map->items[i].key, key) != 0) continue; + return map->items[i].value; + } + return NULL; } \ No newline at end of file diff --git a/src/setup_dirs.c b/src/setup_dirs.c index ee2196d..02442c3 100644 --- a/src/setup_dirs.c +++ b/src/setup_dirs.c @@ -1,4 +1,23 @@ -#include +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include @@ -6,12 +25,10 @@ #include "vars.h" void setup_dirs() { - mkdir_p(config_dir); - for (int i = 0; i < 5; i++) { - if (install_directories[i] && strlen(install_directories[i]) > 0) { - if (!file_exists(install_directories[i])) { - mkdir_p(install_directories[i]); - } - } - } + mkdir_p(config_dir); + for (int i = 0; i < 5; i++) { + if (install_directories[i] && strlen(install_directories[i]) <= 0) continue; + if (file_exists(install_directories[i])) continue; + mkdir_p(install_directories[i]); + } } \ No newline at end of file diff --git a/src/setup_pkgit.c b/src/setup_pkgit.c index fdcdb56..31e3fd2 100644 --- a/src/setup_pkgit.c +++ b/src/setup_pkgit.c @@ -1,10 +1,29 @@ -#include +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include "set_install_directories.h" #include "setup_dirs.h" void setup_pkgit() { - set_install_directories(); - setup_dirs(); + set_install_directories(); + setup_dirs(); } \ No newline at end of file diff --git a/src/update_all.c b/src/update_all.c index 8a7d57f..79b653c 100644 --- a/src/update_all.c +++ b/src/update_all.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include @@ -13,20 +33,26 @@ #include "vars.h" void update_all() { - init_lua_state(); - cache_repos(); - struct dirent* dirent_ptr; - DIR* dir_ptr; - if ((dir_ptr = opendir(get_install_dir("src"))) == NULL) { - fprintf(stderr, "%s could not open %s\n", print_pkgit, get_install_dir("src")); - } - while ((dirent_ptr = readdir(dir_ptr)) != NULL) { - if (strcmp(dirent_ptr->d_name, "..") == 0 || strcmp(dirent_ptr->d_name, ".") == 0) continue; - for (size_t i = 0; i < cached_repos_count; i++) { - if (strcmp(dirent_ptr->d_name, cached_repos[i].source_key) != 0) continue; - Pkg pkg = create_pkg(cached_repos[i].source_value); - update_pkg(pkg); - } - } - closedir(dir_ptr); + init_lua_state(); + cache_repos(); + struct dirent* dirent_ptr; + DIR* dir_ptr; + if ((dir_ptr = opendir(get_install_dir("src"))) == NULL) { + fprintf( + stderr, "%s could not open %s\n", + print_pkgit, get_install_dir("src") + ); + } + while ((dirent_ptr = readdir(dir_ptr)) != NULL) { + if ( + strcmp(dirent_ptr->d_name, "..") == 0 || + strcmp(dirent_ptr->d_name, ".") == 0 + ) continue; + for (size_t i = 0; i < cached_repos_count; i++) { + if (strcmp(dirent_ptr->d_name, cached_repos[i].source_key) != 0) continue; + Pkg pkg = create_pkg(cached_repos[i].source_value); + update_pkg(pkg); + } + } + closedir(dir_ptr); } \ No newline at end of file diff --git a/src/update_pkg.c b/src/update_pkg.c index 52c4c9e..ea6a20d 100644 --- a/src/update_pkg.c +++ b/src/update_pkg.c @@ -1,17 +1,43 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include "update_pkg.h" -#include "is_updated.h" #include "install_pkg.h" +#include "is_updated.h" #include "lua_state.h" void update_pkg(Pkg pkg) { - if (is_updated(pkg.src)) { - printf("%s %s%s%s is already up to date.\n", print_skipped, green, pkg.name, color_reset); - return; - } - printf("%s Updating package: %s%s%s\n", print_pkgit, green, pkg.name, color_reset); - install_pkg(pkg); + if (is_updated(pkg.src)) { + printf( + "%s %s%s%s is already up to date.\n", + print_skipped, green, pkg.name, color_reset + ); + return; + } + printf( + "%s Updating package: %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); + install_pkg(pkg); } \ No newline at end of file diff --git a/src/vars.c b/src/vars.c index 2691777..ba83559 100644 --- a/src/vars.c +++ b/src/vars.c @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + #include #include #include @@ -37,21 +57,24 @@ Map cached_build_systems = {0}; char home_config_buf[MAX_PATH_LEN] = {0}; char *home_config() { - snprintf(home_config_buf, MAX_PATH_LEN, "%s/.config/pkgit/init.lua", - home_dir); - return home_config_buf; + snprintf( + home_config_buf, MAX_PATH_LEN, + "%s/.config/pkgit/init.lua", + home_dir + ); + return home_config_buf; } const char *get_install_dir(const char *key) { - for (size_t i = 0; i < cached_install_directories.size; i++) { - if (strcmp(cached_install_directories.items[i].key, key) == 0) { - return cached_install_directories.items[i].value; - } - } - return ""; + for (size_t i = 0; i < cached_install_directories.size; i++) { + if (strcmp(cached_install_directories.items[i].key, key) == 0) { + return cached_install_directories.items[i].value; + } + } + return ""; } -const char *version = "1.0.0"; +const char *version = "1.1.3"; const char *red = "\e[0;31m"; const char *green = "\e[0;32m"; @@ -92,100 +115,106 @@ const char *print_warning; const char *print_error; int mkdir_p(const char *path) { - char tmp[MAX_PATH_LEN]; - char *p = NULL; - size_t len; - - snprintf(tmp, sizeof(tmp), "%s", path); - len = strlen(tmp); - if (tmp[len - 1] == '/') { - tmp[len - 1] = 0; - } - - for (p = tmp + 1; *p; p++) { - if (*p == '/') { - *p = 0; - if (mkdir(tmp, 0755) != 0 && errno != EEXIST) { - return -1; - } - *p = '/'; - } - } - - if (mkdir(tmp, 0755) != 0 && errno != EEXIST) { - return -1; - } - - return 0; + char tmp[MAX_PATH_LEN]; + char *p = NULL; + size_t len; + snprintf(tmp, sizeof(tmp), "%s", path); + len = strlen(tmp); + if (tmp[len - 1] == '/') { + tmp[len - 1] = 0; + } + for (p = tmp + 1; *p; p++) { + if (*p == '/') { + *p = 0; + if (mkdir(tmp, 0755) != 0 && errno != EEXIST) { + return -1; + } + *p = '/'; + } + } + if (mkdir(tmp, 0755) != 0 && errno != EEXIST) { + return -1; + } + return 0; } bool file_exists(const char *path) { - struct stat buffer; - return (stat(path, &buffer) == 0); + struct stat buffer; + return (stat(path, &buffer) == 0); } bool is_directory(const char *path) { - struct stat statbuf; - if (stat(path, &statbuf) != 0) { - return false; - } - return S_ISDIR(statbuf.st_mode); + struct stat statbuf; + if (stat(path, &statbuf) != 0) { + return false; + } + return S_ISDIR(statbuf.st_mode); } void init_vars() { - char *home = getenv("HOME"); - if (home) { - snprintf(home_dir, MAX_PATH_LEN, "%s", home); - } else { - snprintf(home_dir, MAX_PATH_LEN, "/root"); - } - - is_root_config = file_exists(root_config); - - if (is_root_config) { - snprintf(config_dir, MAX_PATH_LEN, "/etc/pkgit"); - } else { - snprintf(config_dir, MAX_PATH_LEN, "%s/.config/pkgit", home_dir); - } - - snprintf(config_file, MAX_PATH_LEN, "%s/init.lua", config_dir); - snprintf(repo_file, MAX_PATH_LEN, "%s/repos.lua", config_dir); - - config_exists = file_exists(root_config) || file_exists(home_config()); - - snprintf(bin, MAX_PATH_LEN, "%s/.local/bin", home_dir); - snprintf(lib, MAX_PATH_LEN, "%s/.local/lib", home_dir); - snprintf(inc, MAX_PATH_LEN, "%s/.local/include", home_dir); - snprintf(src, MAX_PATH_LEN, "%s/.local/share/pkgit", home_dir); - - install_directories[0] = config_dir; - install_directories[1] = strdup(get_install_dir("bin")); - install_directories[2] = strdup(get_install_dir("lib")); - install_directories[3] = strdup(get_install_dir("inc")); - install_directories[4] = strdup(get_install_dir("src")); - - static char print_pkgit_buf[256]; - snprintf(print_pkgit_buf, sizeof(print_pkgit_buf), "%s[%s%s%s]%s", - bold_yellow, bold_magenta, "pkgit", bold_yellow, color_reset); - print_pkgit = print_pkgit_buf; - - static char print_success_buf[256]; - snprintf(print_success_buf, sizeof(print_success_buf), "%s%s [SUCCESS]%s", - print_pkgit, green, color_reset); - print_success = print_success_buf; - - static char print_skipped_buf[256]; - snprintf(print_skipped_buf, sizeof(print_skipped_buf), "%s%s [SKIP]%s", - print_pkgit, blue, color_reset); - print_skipped = print_skipped_buf; - - static char print_warning_buf[256]; - snprintf(print_warning_buf, sizeof(print_warning_buf), "%s%s [WARN]%s", - print_pkgit, yellow, color_reset); - print_warning = print_warning_buf; - - static char print_error_buf[256]; - snprintf(print_error_buf, sizeof(print_error_buf), "%s%s [ERROR]%s", - print_pkgit, red, color_reset); - print_error = print_error_buf; + char *home = getenv("HOME"); + if (home) snprintf(home_dir, MAX_PATH_LEN, "%s", home); + else snprintf(home_dir, MAX_PATH_LEN, "/root"); + + is_root_config = file_exists(root_config); + + if (is_root_config) snprintf(config_dir, MAX_PATH_LEN, "/etc/pkgit"); + else snprintf(config_dir, MAX_PATH_LEN, "%s/.config/pkgit", home_dir); + + snprintf(config_file, MAX_PATH_LEN, "%s/init.lua", config_dir); + snprintf(repo_file, MAX_PATH_LEN, "%s/repos.lua", config_dir); + + config_exists = file_exists(root_config) || file_exists(home_config()); + + snprintf(bin, MAX_PATH_LEN, "%s/.local/bin", home_dir); + snprintf(lib, MAX_PATH_LEN, "%s/.local/lib", home_dir); + snprintf(inc, MAX_PATH_LEN, "%s/.local/include", home_dir); + snprintf(src, MAX_PATH_LEN, "%s/.local/share/pkgit", home_dir); + + install_directories[0] = config_dir; + install_directories[1] = strdup(get_install_dir("bin")); + install_directories[2] = strdup(get_install_dir("lib")); + install_directories[3] = strdup(get_install_dir("inc")); + install_directories[4] = strdup(get_install_dir("src")); + + static char print_pkgit_buf[256]; + snprintf( + print_pkgit_buf, sizeof(print_pkgit_buf), + "%s[%s%s%s]%s", + bold_yellow, bold_magenta, "pkgit", + bold_yellow, color_reset + ); + print_pkgit = print_pkgit_buf; + + static char print_success_buf[256]; + snprintf( + print_success_buf, sizeof(print_success_buf), + "%s%s [SUCCESS]%s", + print_pkgit, green, color_reset + ); + print_success = print_success_buf; + + static char print_skipped_buf[256]; + snprintf( + print_skipped_buf, sizeof(print_skipped_buf), + "%s%s [SKIP]%s", + print_pkgit, blue, color_reset + ); + print_skipped = print_skipped_buf; + + static char print_warning_buf[256]; + snprintf( + print_warning_buf, sizeof(print_warning_buf), + "%s%s [WARN]%s", + print_pkgit, yellow, color_reset + ); + print_warning = print_warning_buf; + + static char print_error_buf[256]; + snprintf( + print_error_buf, sizeof(print_error_buf), + "%s%s [ERROR]%s", + print_pkgit, red, color_reset + ); + print_error = print_error_buf; } -- cgit v1.2.3