aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--TODO.md2
-rw-r--r--include/files.h4
-rw-r--r--include/vars.h2
-rw-r--r--src/.clangd4
-rw-r--r--src/files.c7
-rw-r--r--src/lua_state.c23
-rw-r--r--src/remove.c31
-rw-r--r--src/resolve_deps.c42
9 files changed, 74 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index 91ed17a..192326e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,12 @@
.PHONY: default debug install defconfig clean
-CC = gcc
+CC ?= clang
RM = rm -f
PREFIX ?= /usr/local
OBJDIR = obj
SRCS = $(wildcard src/*.c)
OBJS = $(SRCS:src/%.c=$(OBJDIR)/%.o)
-CFLAGS += $(shell pkg-config --cflags luajit) -I./include -Wno-format-truncation
+CFLAGS += $(shell pkg-config --cflags luajit) -I./include -Wno-format-truncation -std=c99 -D_POSIX_C_SOURCE=200112L
default: pkgit
diff --git a/TODO.md b/TODO.md
index a4a14e1..fde0e06 100644
--- a/TODO.md
+++ b/TODO.md
@@ -8,7 +8,7 @@
- [x] CLA parsing
- [x] lua config primary(/etc) / secondary(.config) checks
- [x] lua variables for install paths
-- [ ] lua dependency listing
+- [x] lua dependency listing
- [ ] lua custom source fetching methods
- [ ] version management
- [ ] (maybe) diffs to change versions
diff --git a/include/files.h b/include/files.h
new file mode 100644
index 0000000..af00cbb
--- /dev/null
+++ b/include/files.h
@@ -0,0 +1,4 @@
+#ifndef FILES
+#define FILES
+const char *get_filename_ext(const char *filename);
+#endif
diff --git a/include/vars.h b/include/vars.h
index 7bb44d3..d635b07 100644
--- a/include/vars.h
+++ b/include/vars.h
@@ -64,7 +64,7 @@ extern char repo_file[MAX_PATH_LEN];
extern char bin[MAX_PATH_LEN];
extern char lib[MAX_PATH_LEN];
extern char inc[MAX_PATH_LEN];
-extern char pkgblds[MAX_PATH_LEN];
+extern char src[MAX_PATH_LEN];
extern char *install_directories[5];
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");
}