aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c
index d01499d..0f0c166 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1,4 +1,26 @@
+/*
+
+ pow! - the pow!erful package manager
+
+ Copyright (C) 2026 forever2k38
+
+ 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/>.
+
+*/
+
#include "config.h"
+#include "log.h"
#include "lauxlib.h"
#include "lualib.h"
@@ -27,13 +49,13 @@ int pow_open_config(pow_config *cfg, char *path) {
err = lua_pcall(L, 0, 1, 0);
if (err) {
- printf("%s\n", lua_tostring(L, -1));
+ pow_log_error("%s\n", lua_tostring(L, -1));
return 1;
}
if (!lua_istable(L, -1)) {
- printf("bad config. you must return a table.\n");
+ pow_log_error("bad config. you must return a table.\n");
return 1;
}
@@ -42,7 +64,7 @@ int pow_open_config(pow_config *cfg, char *path) {
// and push repos to -1
if (lua_istable(L, -1)) {
- size_t repo_count = lua_rawlen(L, -1);
+ size_t repo_count = lua_objlen(L, -1);
for (size_t i = 1; i <= repo_count; i++) {
lua_rawgeti(L, -1, i);
@@ -53,7 +75,7 @@ int pow_open_config(pow_config *cfg, char *path) {
if (!repo) {
lua_pop(L, 1);
- printf("malloc for repo failed, what the fuck? something really bad "
+ pow_log_error("malloc for repo failed, what the fuck? something really bad "
"happened i guess\n");
return 1;
@@ -72,7 +94,7 @@ int pow_open_config(pow_config *cfg, char *path) {
free(repo);
- printf(
+ pow_log_error(
"malloc for path failed, what the fuck? something really bad "
"happened i guess\n");
@@ -81,7 +103,7 @@ int pow_open_config(pow_config *cfg, char *path) {
repo->path = path_dup;
} else {
- printf("invalid (or non existent) path for repo\n");
+ pow_log_error("invalid (or non existent) path for repo");
lua_pop(L, 1);
lua_pop(L, 1);
@@ -95,7 +117,7 @@ int pow_open_config(pow_config *cfg, char *path) {
realloc(cfg->repos, (cfg->repos_count + 1) * sizeof(*repos));
if (!repos) {
- printf("failed realloc! bad things coming\n");
+ pow_log_error("failed realloc! bad things coming\n");
lua_pop(L, 1);
lua_pop(L, 1);
@@ -115,6 +137,22 @@ int pow_open_config(pow_config *cfg, char *path) {
lua_pop(L, 1);
}
+
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "makeopts");
+
+ if (!lua_isstring(L, -1)) {
+ pow_log_info("no makeopts specified");
+ } else {
+ cfg->makeopts = strdup(lua_tostring(L, -1));
+
+ if (!cfg->makeopts) {
+ pow_log_error("failed to strdup makeopts");
+
+ return 1;
+ }
+ }
}
return 0;
@@ -127,6 +165,7 @@ int pow_close_config(pow_config *cfg) {
}
free(cfg->repos);
+ free(cfg->makeopts);
lua_close(cfg->L);