From 184bd50e2ea12b4bf40f4ae1b0d685f0bfa1c995 Mon Sep 17 00:00:00 2001 From: dacctal Date: Tue, 21 Jul 2026 21:32:27 +0000 Subject: started 2.0 refactor. Co-authored-by: ezntek --- include/add_repo.h | 28 ----------- include/banned.h | 67 -------------------------- include/build.h | 28 ----------- include/check.h | 24 ---------- include/cli.h | 32 +++++++++++++ include/common.h | 105 +++++++++++++++++++++++++++++++++++++++++ include/debug.h | 27 ----------- include/fetch.h | 28 ----------- include/files.h | 34 -------------- include/globs.h | 130 --------------------------------------------------- include/help.h | 8 ++-- include/is_updated.h | 28 ----------- include/lua_state.h | 16 +++++++ include/parse_args.h | 26 ----------- include/pkg.h | 37 ++++++--------- include/pkgit_lua.h | 77 ------------------------------ include/search.h | 27 ----------- include/state.h | 45 ++++++++++++++++++ include/str.h | 14 +++++- 19 files changed, 229 insertions(+), 552 deletions(-) delete mode 100644 include/add_repo.h delete mode 100644 include/banned.h delete mode 100644 include/build.h delete mode 100644 include/check.h create mode 100644 include/cli.h create mode 100644 include/common.h delete mode 100644 include/debug.h delete mode 100644 include/fetch.h delete mode 100644 include/files.h delete mode 100644 include/globs.h delete mode 100644 include/is_updated.h create mode 100644 include/lua_state.h delete mode 100644 include/parse_args.h delete mode 100644 include/pkgit_lua.h delete mode 100644 include/search.h create mode 100644 include/state.h (limited to 'include') 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 . - -*/ - -#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 . - -*/ - -#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 . - -*/ - -#ifndef PKGIT_BUILD_H -#define PKGIT_BUILD_H - -#include "pkg.h" - -bool build(package_t *pkg); - -#endif diff --git a/include/check.h b/include/check.h deleted file mode 100644 index c43385b..0000000 --- a/include/check.h +++ /dev/null @@ -1,24 +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 . - -*/ - -#ifndef PKGIT_CHECK_H -#define PKGIT_CHECK_H -void check(void); -#endif diff --git a/include/cli.h b/include/cli.h new file mode 100644 index 0000000..602fa6d --- /dev/null +++ b/include/cli.h @@ -0,0 +1,32 @@ +/* + + 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 . + +*/ + +#ifndef PKGIT_CLI_H +#define PKGIT_CLI_H + +typedef enum { + CLI_FAIL = 0, + CLI_SUCCESS = 1, + CLI_HELP_CALLED = 2, +} cli_result_t; + +cli_result_t cli(int argc, char **argv); + +#endif diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..a77718b --- /dev/null +++ b/include/common.h @@ -0,0 +1,105 @@ +/* + 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 . +*/ + +#ifndef PKGIT_COMMON_H +#define PKGIT_COMMON_H + +#define VERSION "1.2.0" +#define RED "\x1b[0;31m" +#define GREEN "\x1b[0;32m" +#define YELLOW "\x1b[0;33m" +#define BLUE "\x1b[0;34m" +#define MAGENTA "\x1b[0;35m" +#define CYAN "\x1b[0;36m" +#define GRAY "\x1b[0;37m" +#define BRIGHT_RED "\x1b[0;91m" +#define BRIGHT_GREEN "\x1b[0;92m" +#define BRIGHT_YELLOW "\x1b[0;93m" +#define BRIGHT_BLUE "\x1b[0;94m" +#define BRIGHT_MAGENTA "\x1b[0;95m" +#define BRIGHT_CYAN "\x1b[0;96m" +#define BRIGHT_GRAY "\x1b[0;97m" +#define BOLD "\x1b[1m" +#define BOLD_RED "\x1b[1;31m" +#define BOLD_GREEN "\x1b[1;32m" +#define BOLD_YELLOW "\x1b[1;33m" +#define BOLD_BLUE "\x1b[1;34m" +#define BOLD_MAGENTA "\x1b[1;35m" +#define BOLD_CYAN "\x1b[1;36m" +#define BOLD_GRAY "\x1b[1;37m" +#define BOLD_WHITE "\x1b[1;38m" +#define BOLD_BRIGHT_RED "\x1b[1;91m" +#define BOLD_BRIGHT_GREEN "\x1b[1;92m" +#define BOLD_BRIGHT_YELLOW "\x1b[1;93m" +#define BOLD_BRIGHT_BLUE "\x1b[1;94m" +#define BOLD_BRIGHT_MAGENTA "\x1b[1;95m" +#define BOLD_BRIGHT_CYAN "\x1b[1;96m" +#define BOLD_BRIGHT_GRAY "\x1b[1;97m" +#define ITALIC "\x1b[3m" +#define COLOR_RESET "\x1b[0m" + +#define LENGTH(lst) (sizeof(lst) / sizeof(*(lst))) + +#define eprintf(...) fprintf(stderr, __VA_ARGS__); + +#define check_alloc(ptr) \ + do { \ + if (ptr == NULL) \ + panic("allocation of `%s` failed", #ptr); \ + } while (0) + +#define panic(...) \ + do { \ + char *tmp = strrchr(__FILE__, '/'); \ + eprintf(BOLD RED "panic:" COLOR_RESET " line %d, func \"%s\" in file " \ + "\"%s\": ", \ + __LINE__, __func__, tmp ? tmp + 1 : __FILE__); \ + eprintf(__VA_ARGS__); \ + eprintf("\n"); \ + fflush(stderr); \ + abort(); \ + } while (0) + +#ifdef PKGIT_DEBUG +#define assert(expr) \ + do { \ + if (!(expr)) \ + panic("Assertion `%s` failed", #expr); \ + } while (0) +#else +#define assert(expr) (void)(expr) +#endif + +#ifdef unreachable +#undef unreachable +#endif +#define unreachable panic("reached unreachable code") + +#define PKGIT_PREFIX \ + BOLD_YELLOW "[" BOLD_MAGENTA "pkgit" BOLD_YELLOW "] " COLOR_RESET +#define PKGIT_PREFIX_SUCCESS PKGIT_PREFIX GREEN "[SUCCESS] " COLOR_RESET +#define PKGIT_PREFIX_INFO PKGIT_PREFIX BLUE "[INFO] " COLOR_RESET +#define PKGIT_PREFIX_WARNING PKGIT_PREFIX YELLOW "[WARNING] " COLOR_RESET +#define PKGIT_PREFIX_ERROR PKGIT_PREFIX RED "[ERROR] " COLOR_RESET + +#define MAX_REPOS 1000 +#define MAX_DIRS 100 +#define MAX_PATH_LEN 1024 + +#endif diff --git a/include/debug.h b/include/debug.h deleted file mode 100644 index e74a099..0000000 --- a/include/debug.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 . - -*/ - - -#ifndef PKGIT_DEBUG_H -#define PKGIT_DEBUG_H - -void debug_print_inst_dirs(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 . - -*/ - -#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 . - -*/ - -#ifndef PKGIT_FILES_H -#define PKGIT_FILES_H - -#include - -#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/globs.h b/include/globs.h deleted file mode 100644 index 20c10f5..0000000 --- a/include/globs.h +++ /dev/null @@ -1,130 +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 . -*/ - -#ifndef PKGIT_GLOBALS_H -#define PKGIT_GLOBALS_H - -#include - -#include "str.h" - -#define VERSION "1.2.0" -#define RED "\x1b[0;31m" -#define GREEN "\x1b[0;32m" -#define YELLOW "\x1b[0;33m" -#define BLUE "\x1b[0;34m" -#define MAGENTA "\x1b[0;35m" -#define CYAN "\x1b[0;36m" -#define GRAY "\x1b[0;37m" -#define BRIGHT_RED "\x1b[0;91m" -#define BRIGHT_GREEN "\x1b[0;92m" -#define BRIGHT_YELLOW "\x1b[0;93m" -#define BRIGHT_BLUE "\x1b[0;94m" -#define BRIGHT_MAGENTA "\x1b[0;95m" -#define BRIGHT_CYAN "\x1b[0;96m" -#define BRIGHT_GRAY "\x1b[0;97m" -#define BOLD "\x1b[1m" -#define BOLD_RED "\x1b[1;31m" -#define BOLD_GREEN "\x1b[1;32m" -#define BOLD_YELLOW "\x1b[1;33m" -#define BOLD_BLUE "\x1b[1;34m" -#define BOLD_MAGENTA "\x1b[1;35m" -#define BOLD_CYAN "\x1b[1;36m" -#define BOLD_GRAY "\x1b[1;37m" -#define BOLD_WHITE "\x1b[1;38m" -#define BOLD_BRIGHT_RED "\x1b[1;91m" -#define BOLD_BRIGHT_GREEN "\x1b[1;92m" -#define BOLD_BRIGHT_YELLOW "\x1b[1;93m" -#define BOLD_BRIGHT_BLUE "\x1b[1;94m" -#define BOLD_BRIGHT_MAGENTA "\x1b[1;95m" -#define BOLD_BRIGHT_CYAN "\x1b[1;96m" -#define BOLD_BRIGHT_GRAY "\x1b[1;97m" -#define ITALIC "\x1b[3m" -#define COLOR_RESET "\x1b[0m" - -#define LENGTH(lst) (sizeof(lst) / sizeof(*(lst))) - -#define eprintf(...) fprintf(stderr, __VA_ARGS__); - -#define check_alloc(ptr) \ - do { \ - if (ptr == NULL) \ - panic("allocation of `%s` failed", #ptr); \ - } while (0) - -#define panic(...) \ - do { \ - char *tmp = strrchr(__FILE__, '/'); \ - eprintf(BOLD RED "panic:" COLOR_RESET " line %d, func \"%s\" in file " \ - "\"%s\": ", \ - __LINE__, __func__, tmp ? tmp + 1 : __FILE__); \ - eprintf(__VA_ARGS__); \ - eprintf("\n"); \ - fflush(stderr); \ - abort(); \ - } while (0) - -#ifdef PKGIT_DEBUG -#define assert(expr) \ - do { \ - if (!(expr)) \ - panic("Assertion `%s` failed", #expr); \ - } while (0) -#else -#define assert(expr) (void)(expr) -#endif - -#ifdef unreachable -#undef unreachable -#endif -#define unreachable panic("reached unreachable code") - -#define PKGIT_PREFIX \ - BOLD_YELLOW "[" BOLD_MAGENTA "pkgit" BOLD_YELLOW "] " COLOR_RESET -#define PKGIT_PREFIX_SUCCESS PKGIT_PREFIX GREEN "[SUCCESS] " COLOR_RESET -#define PKGIT_PREFIX_INFO PKGIT_PREFIX BLUE "[INFO] " COLOR_RESET -#define PKGIT_PREFIX_WARNING PKGIT_PREFIX YELLOW "[WARNING] " COLOR_RESET -#define PKGIT_PREFIX_ERROR PKGIT_PREFIX RED "[ERROR] " COLOR_RESET - -#define MAX_REPOS 1000 -#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/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 . - -*/ - -#ifndef PKGIT_IS_UPDATED_H -#define PKGIT_IS_UPDATED_H - -#include -#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 +#include +#include +#include + +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 . - -*/ - -#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 . -*/ - #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 . - -*/ - -#ifndef PKGIT_LUA_H -#define PKGIT_LUA_H - -#include -#include -#include -#include - -#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 . - -*/ - -#ifndef PKGIT_SEARCH_H -#define PKGIT_SEARCH_H - -void list_installed(void); -void search(char* arg); - -#endif diff --git a/include/state.h b/include/state.h new file mode 100644 index 0000000..9075270 --- /dev/null +++ b/include/state.h @@ -0,0 +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 . + +*/ + +#include + +#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 @@ -73,6 +73,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 */ @@ -181,6 +187,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. */ @@ -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); -- cgit v1.2.3