diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/add_repo.h | 28 | ||||
| -rw-r--r-- | include/banned.h | 67 | ||||
| -rw-r--r-- | include/build.h | 28 | ||||
| -rw-r--r-- | include/cli.h (renamed from include/debug.h) | 11 | ||||
| -rw-r--r-- | include/common.h (renamed from include/globs.h) | 39 | ||||
| -rw-r--r-- | include/fetch.h | 28 | ||||
| -rw-r--r-- | include/files.h | 34 | ||||
| -rw-r--r-- | include/help.h | 8 | ||||
| -rw-r--r-- | include/is_updated.h | 28 | ||||
| -rw-r--r-- | include/lua_state.h | 16 | ||||
| -rw-r--r-- | include/parse_args.h | 26 | ||||
| -rw-r--r-- | include/pkg.h | 37 | ||||
| -rw-r--r-- | include/pkgit_lua.h | 77 | ||||
| -rw-r--r-- | include/search.h | 27 | ||||
| -rw-r--r-- | include/state.h (renamed from include/check.h) | 37 | ||||
| -rw-r--r-- | include/str.h | 14 |
16 files changed, 91 insertions, 414 deletions
diff --git a/include/add_repo.h b/include/add_repo.h deleted file mode 100644 index 48a73fa..0000000 --- a/include/add_repo.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_ADD_H -#define PKGIT_ADD_H - -#include "pkg.h" - -void add_repo(package_t *pkg); - -#endif diff --git a/include/banned.h b/include/banned.h deleted file mode 100644 index 3ea7dd4..0000000 --- a/include/banned.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_BANNED_H -#define PKGIT_BANNED_H - -/* - * This header lists functions that have been banned from our code base, - * because they're too easy to misuse (and even if used correctly, - * complicate audits). Including this header turns them into compile-time - * errors. - */ - -#define BANNED(func) sorry_##func##_is_a_banned_function - -#undef strcpy -#define strcpy(x,y) BANNED(strcpy) -#undef strcat -#define strcat(x,y) BANNED(strcat) -#undef strncpy -#define strncpy(x,y,n) BANNED(strncpy) -#undef strncat -#define strncat(x,y,n) BANNED(strncat) -#undef strtok -#define strtok(x,y) BANNED(strtok) -#undef strtok_r -#define strtok_r(x,y,z) BANNED(strtok_r) - -#undef sprintf -#undef vsprintf -#define sprintf(...) BANNED(sprintf) -#define vsprintf(...) BANNED(vsprintf) - -#undef gmtime -#define gmtime(t) BANNED(gmtime) -#undef localtime -#define localtime(t) BANNED(localtime) -#undef ctime -#define ctime(t) BANNED(ctime) -#undef ctime_r -#define ctime_r(t, buf) BANNED(ctime_r) -#undef asctime -#define asctime(t) BANNED(asctime) -#undef asctime_r -#define asctime_r(t, buf) BANNED(asctime_r) - -#undef mktemp -#define mktemp(x) BANNED(mktemp) - -#endif /* BANNED_H */ diff --git a/include/build.h b/include/build.h deleted file mode 100644 index 7dcb53a..0000000 --- a/include/build.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_BUILD_H -#define PKGIT_BUILD_H - -#include "pkg.h" - -bool build(package_t *pkg); - -#endif diff --git a/include/debug.h b/include/cli.h index e74a099..602fa6d 100644 --- a/include/debug.h +++ b/include/cli.h @@ -18,10 +18,15 @@ */ +#ifndef PKGIT_CLI_H +#define PKGIT_CLI_H -#ifndef PKGIT_DEBUG_H -#define PKGIT_DEBUG_H +typedef enum { + CLI_FAIL = 0, + CLI_SUCCESS = 1, + CLI_HELP_CALLED = 2, +} cli_result_t; -void debug_print_inst_dirs(void); +cli_result_t cli(int argc, char **argv); #endif diff --git a/include/globs.h b/include/common.h index 20c10f5..a77718b 100644 --- a/include/globs.h +++ b/include/common.h @@ -1,28 +1,24 @@ /* 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 <https://www.gnu.org/licenses/>. */ -#ifndef PKGIT_GLOBALS_H -#define PKGIT_GLOBALS_H - -#include <stdlib.h> - -#include "str.h" +#ifndef PKGIT_COMMON_H +#define PKGIT_COMMON_H #define VERSION "1.2.0" #define RED "\x1b[0;31m" @@ -68,7 +64,7 @@ panic("allocation of `%s` failed", #ptr); \ } while (0) -#define panic(...) \ +#define panic(...) \ do { \ char *tmp = strrchr(__FILE__, '/'); \ eprintf(BOLD RED "panic:" COLOR_RESET " line %d, func \"%s\" in file " \ @@ -106,25 +102,4 @@ #define MAX_DIRS 100 #define MAX_PATH_LEN 1024 -typedef struct { - bool verbose, force; -} cli_flags_t; - -typedef struct { - str dir, name, content, repos; - bool is_root_config; -} config_t; - -typedef struct { - str prefix, bin, lib, include, src; -} install_dirs_t; - -extern cli_flags_t flags; -extern config_t cfg; -extern install_dirs_t inst_dirs; -extern str new_arg_str; - -void init_vars(void); -void free_vars(void); - #endif diff --git a/include/fetch.h b/include/fetch.h deleted file mode 100644 index d392098..0000000 --- a/include/fetch.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_FETCH_H -#define PKGIT_FETCH_H - -#include "pkg.h" - -bool fetch(package_t *pkg); - -#endif diff --git a/include/files.h b/include/files.h deleted file mode 100644 index 9a17c88..0000000 --- a/include/files.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_FILES_H -#define PKGIT_FILES_H - -#include <stdbool.h> - -#include "str.h" - -bool file_exists(const char *path); -bool is_directory(const char *path); -str cmd_out(const char *cmd); -void cpdir(const char *src_path, const char *dst_path); -int remove_tree(const char *path); - -#endif diff --git a/include/help.h b/include/help.h index c194be4..28fb539 100644 --- a/include/help.h +++ b/include/help.h @@ -18,9 +18,9 @@ */ -#ifndef HELP_H -#define HELP_H +#ifndef PKGIT_HELP_H +#define PKGIT_HELP_H -void help(void); +void print_help(void); -#endif
\ No newline at end of file +#endif diff --git a/include/is_updated.h b/include/is_updated.h deleted file mode 100644 index 16f998f..0000000 --- a/include/is_updated.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_IS_UPDATED_H -#define PKGIT_IS_UPDATED_H - -#include <stdbool.h> -#include "str.h" -bool is_updated(str *src); - -#endif diff --git a/include/lua_state.h b/include/lua_state.h new file mode 100644 index 0000000..49f35e4 --- /dev/null +++ b/include/lua_state.h @@ -0,0 +1,16 @@ +#ifndef PKGIT_LUA_STATE_H +#define PKGIT_LUA_STATE_H + +#include <lauxlib.h> +#include <lua.h> +#include <lualib.h> +#include <stdbool.h> + +extern lua_State *L; +extern bool L_is_loaded; + +bool init_lua_state(void); +bool init_lua_config(void); +void free_lua_state(void); + +#endif diff --git a/include/parse_args.h b/include/parse_args.h deleted file mode 100644 index d68c37f..0000000 --- a/include/parse_args.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_CLA_PARSE_H -#define PKGIT_CLA_PARSE_H - -void parse_args(int argc, char **argv); - -#endif
\ No newline at end of file diff --git a/include/pkg.h b/include/pkg.h index 5ad88b2..47d1918 100644 --- a/include/pkg.h +++ b/include/pkg.h @@ -1,33 +1,24 @@ -/* - 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 <https://www.gnu.org/licenses/>. -*/ - #ifndef PKGIT_PKG_H #define PKGIT_PKG_H #include "str.h" -typedef struct { - str name, url, version, target, src; +struct package_t; +typedef bool (*package_hook_cb_t)(struct package_t *self); +typedef str (*package_version_cb_t)(struct package_t *self); + +typedef struct package_t { + str name, version, url, src; + unsigned int dep_count; bool is_local; + package_hook_cb_t setup, build, install, rem, on_update, fetch_sources; + package_version_cb_t fetch_latest_version; } package_t; -package_t pkg_create(str *arg); -void pkg_free(package_t *pkg); +bool setup(package_t *self), build(package_t *self), + install(package_t *self), rem(package_t *self), + on_update(package_t *self), + fetch_sources(package_t *self); +str fetch_latest_version(package_t *self); #endif diff --git a/include/pkgit_lua.h b/include/pkgit_lua.h deleted file mode 100644 index a9a6adf..0000000 --- a/include/pkgit_lua.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_LUA_H -#define PKGIT_LUA_H - -#include <lua.h> -#include <lauxlib.h> -#include <lualib.h> -#include <stdbool.h> - -#include "pkg.h" - -extern lua_State *L; -extern lua_State *B; -extern bool config_loaded; -extern bool bldit_loaded; - -// init -void push_lua_path(lua_State *L, const char *new_path); -void init_lua_state(void); -void init_bldit_state(void); -void free_lua_state(void); -void free_bldit_state(void); -lua_State *get_lua_state(void); -lua_State *get_bldit_state(void); - -// gobal vars -void init_install_directories(void); -void init_prefix_directory(void); - -// helpers -void lua_isnt_type(char* variable, char* type); -void bldit_isnt_type(char* variable, char* type); -bool lua_try_function(lua_State *L, char *lua_file, char *fname); -bool lua_try_table(lua_State *L, char *lua_file, char *tname); -bool pkg_exists(str *name); -str pkg_get_url(str *name); -str bldit_getver(void); -str bldit_pkg_getver(void); -bool is_bldit_usable(void); - -// install -void install_dependencies(lua_State *L); -void pkg_install(package_t *pkg); - -// remove -bool repo_uninstall(package_t *pkg); -bool bldit_uninstall(package_t *pkg); -bool config_uninstall(package_t *pkg); -void pkg_remove(package_t *pkg); - -// update -void pkg_update(package_t *pkg); -void all_update(void); - -// declare -void declare(void); - -#endif diff --git a/include/search.h b/include/search.h deleted file mode 100644 index 233537b..0000000 --- a/include/search.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - - 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 <https://www.gnu.org/licenses/>. - -*/ - -#ifndef PKGIT_SEARCH_H -#define PKGIT_SEARCH_H - -void list_installed(void); -void search(char* arg); - -#endif diff --git a/include/check.h b/include/state.h index c43385b..9075270 100644 --- a/include/check.h +++ b/include/state.h @@ -1,24 +1,45 @@ /* - + 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 <https://www.gnu.org/licenses/>. */ -#ifndef PKGIT_CHECK_H -#define PKGIT_CHECK_H -void check(void); -#endif +#include <stdbool.h> + +#include "str.h" + +typedef struct { + bool force, quiet; +} cli_flags_t; + +typedef struct inst_dirs_t { + str prefix, src, bin, lib, include; +} inst_dirs_t; + +typedef struct config_t { + inst_dirs_t inst_dirs; + str dir, init_path, autogenerated_path; + bool is_root; +} user_config_t; + +typedef struct { + str prefix, bin, lib, include, src; +} install_dirs_t; + +extern cli_flags_t flags; +extern user_config_t config; +extern install_dirs_t inst_dirs; diff --git a/include/str.h b/include/str.h index 3a4aefb..0e8ae59 100644 --- a/include/str.h +++ b/include/str.h @@ -74,6 +74,12 @@ str str_new_with_capacity(size_t cap); str str_from_cstr(const char *s); /** + * Adopts an existing heap-allocated C string, reusing its buffer in the + * resultant str. + */ +str str_adopt(char *s); + +/** * Equivalent to str_from_cstr */ str mstr(const char *s); @@ -182,6 +188,12 @@ void str_append_cstr(str *src, const char *new_cstr); void str_append_str_slc(str *src, const str_slc new_slc); /** + * Appends a new formatted section of the string, with the same calling + * style as str_append into an existing string buffer. + */ +void str_append_format(str *dest, const char *format, ...); + +/** * Removes the last character from src, returning it. */ char str_pop_last(str *src); @@ -444,7 +456,7 @@ str_slc str_slc_from_cstr(const char *s); /** * Equivalent to str_slc_from_cstr. */ -str_slc mstrslc(const char *s); +str_slc mslc(const char *s); str str_slc_concat(const str_slc lhs, const str_slc rhs); |
