diff options
| author | forever2k38 <forever2k38@noreply.codeberg.org> | 2026-08-31 01:44:47 +0200 |
|---|---|---|
| committer | forever2k38 <forever2k38@noreply.codeberg.org> | 2026-08-31 01:44:47 +0200 |
| commit | b09a640e1dd7b30ff05093e14190da99bb3cac32 (patch) | |
| tree | b94e413ac91f671c360324263ede968bbeab364f /src/config.c | |
| parent | 3fb1ed5677f46db2a423244bb49e265e9ad67f74 (diff) | |
feat: repos array
Diffstat (limited to 'src/config.c')
| -rw-r--r-- | src/config.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c index 54a505a..dd44129 100644 --- a/src/config.c +++ b/src/config.c @@ -2,6 +2,8 @@ #include "lauxlib.h" #include "lualib.h" +#include "stdlib.h" +#include "string.h" int pow_open_config(pow_config *cfg, char *path) { int err; @@ -46,14 +48,70 @@ int pow_open_config(pow_config *cfg, char *path) { lua_rawgeti(L, -1, i); if (lua_istable(L, -1)) { + pow_repo *repo = malloc(sizeof(pow_repo)); + + if (!repo) { + lua_pop(L, 1); + + printf("malloc for repo failed, what the fuck? something really bad " + "happened i guess\n"); + + return 1; + } + lua_getfield(L, -1, "path"); if (lua_isstring(L, -1)) { const char *path = lua_tostring(L, -1); + const char *path_dup = strdup(path); + + if (!path_dup) { + lua_pop(L, 1); + lua_pop(L, 1); + + free(repo); + + printf( + "malloc for path failed, what the fuck? something really bad " + "happened i guess\n"); + + return 1; + } + + repo->path = path_dup; + printf("%s\n", path); + } else { + printf("invalid (or non existent) path for repo\n"); + + lua_pop(L, 1); + lua_pop(L, 1); + + free(repo); + + continue; } + pow_repo **repos = + realloc(cfg->repos, (cfg->repos_count + 1) * sizeof(*repos)); + + if (!repos) { + printf("failed realloc! bad things coming\n"); + + lua_pop(L, 1); + lua_pop(L, 1); + + free(repo->path); + free(repo); + + return 1; + } + + repos[cfg->repos_count++] = repo; + + cfg->repos = repos; + lua_pop(L, 1); } @@ -63,3 +121,15 @@ int pow_open_config(pow_config *cfg, char *path) { return 0; } + +int pow_close_config(pow_config *cfg) { + for (size_t i = 0; i < cfg->repos_count; i++) { + free(cfg->repos[i]->path); + free(cfg->repos[i]); + } + + free(cfg->repos); + lua_close(cfg->L); + + return 0; +} |
