diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/.clangd | 4 | ||||
| -rw-r--r-- | src/files.c | 7 | ||||
| -rw-r--r-- | src/lua_state.c | 23 | ||||
| -rw-r--r-- | src/remove.c | 31 | ||||
| -rw-r--r-- | src/resolve_deps.c | 42 |
5 files changed, 66 insertions, 41 deletions
diff --git a/src/.clangd b/src/.clangd new file mode 100644 index 0000000..5022e8f --- /dev/null +++ b/src/.clangd @@ -0,0 +1,4 @@ +CompileFlags: + Add: [-I/usr/include/luajit-2.1, -I../include] +--- +UseTab: Always diff --git a/src/files.c b/src/files.c new file mode 100644 index 0000000..86d9be4 --- /dev/null +++ b/src/files.c @@ -0,0 +1,7 @@ +#include <string.h> + +const char *get_filename_ext(const char *filename) { + const char *dot = strrchr(filename, '.'); + if(!dot || dot == filename) return ""; + return dot + 1; +} diff --git a/src/lua_state.c b/src/lua_state.c index c5ba738..7ff8758 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -24,38 +24,29 @@ void push_lua_path(lua_State *L, const char *new_path) { } void init_lua_state() { - if (L != NULL) - return; - + 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("%scannot run configuration script: %s\n", print_error, lua_tostring(L, -1)); return; } - if (file_exists(repo_file)) { if (luaL_loadfile(L, repo_file) || lua_pcall(L, 0, 0, 0)) { printf("%scannot 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; - + if (B != NULL) return; B = luaL_newstate(); luaL_openlibs(B); - if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { printf("%scannot run bldit script: %s\n", print_warning, lua_tostring(B, -1)); return; @@ -71,29 +62,23 @@ void free_lua_state() { config_loaded = false; } -lua_State* get_lua_state() { - return L; -} +lua_State* get_lua_state() { return L; } void cache_install_directories() { if (!config_loaded || !lua_istable(L, -1)) { lua_getglobal(L, "install_directories"); } - if (!lua_istable(L, -1)) { printf("%slua variable '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); @@ -106,9 +91,7 @@ bool repo_build(const char *repository) { lua_pop(L, 1); return false; } - printf("%slua variable 'repositories' used successfully.\n", print_pkgit); - lua_getfield(L, -1, repository); if (!lua_istable(L, -1)) { printf("%s'repositories' lua variable '%s' is not a table.\n", print_warning, repository); diff --git a/src/remove.c b/src/remove.c new file mode 100644 index 0000000..ac8e8f9 --- /dev/null +++ b/src/remove.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <dirent.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include "files.h" +#include "vars.h" + +//void remove_pkg(Pkg pkg) { +// char* src_code = pkg.src; +// struct dirent* dirent_ptr; +// DIR* dir_ptr; +// +// if ((dir_ptr = opendir(src_code)) == NULL) { +// fprintf(stderr, "%scould not open %s\n", print_pkgit, src_code); +// } +// +// while ((dirent_ptr = readdir(dir_ptr)) != NULL) { +// struct stat stat_buf; +// FILE* file_ptr = fopen(dirent_ptr->d_name, "r"); +// if (!file_ptr) { continue; } +// if (strcmp(get_filename_ext(dirent_ptr->d_name), ".so") == 0) { +// remove(strcat(install_directories[], dirent_ptr->d_name)); +// } else if (!access(dir_entry.path().c_str(), X_OK) && !is_directory(dir_entry.path())) { +// std::filesystem::remove(install_directories["bin"]+"/"+dir_entry.path().filename().string()); +// } else if (dir_entry.path().extension() == ".h") { +// std::filesystem::remove(install_directories["include"]+"/"+dir_entry.path().filename().string()); +// } +// } +//} diff --git a/src/resolve_deps.c b/src/resolve_deps.c index e4d50f6..89668ce 100644 --- a/src/resolve_deps.c +++ b/src/resolve_deps.c @@ -4,25 +4,25 @@ #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("67! "); - } - printf("\n"); - fflush(stdout); - usleep(300000); - if (i < 15) { - printf("\033[3A"); - } - } - printf("\n"); - printf("Dependencies resolved! 1 pregnancy found.\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("67! "); +// } +// printf("\n"); +// fflush(stdout); +// usleep(300000); +// if (i < 15) { +// printf("\033[3A"); +// } +// } +// printf("\n"); +// printf("Dependencies resolved! 1 pregnancy found.\n"); } |
