aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.c38
-rw-r--r--src/args.h14
-rw-r--r--src/config.c31
-rw-r--r--src/config.h11
-rw-r--r--src/main.c14
-rw-r--r--src/repo.c0
-rw-r--r--src/repo.h3
7 files changed, 108 insertions, 3 deletions
diff --git a/src/args.c b/src/args.c
new file mode 100644
index 0000000..424492c
--- /dev/null
+++ b/src/args.c
@@ -0,0 +1,38 @@
+#include "args.h"
+
+#include "stdbool.h"
+#include "stdio.h"
+#include "string.h"
+
+char *help = "pow! - the pow!erful package manager\n"
+ "Made with love by forever2k38\n"
+ "Source code at: https://codeberg.org/einfach/pow\n"
+ "Use outside of einfach is unsupported.\n"
+ "This software comes with no warranty.\n"
+ "\n"
+ "Usage: pow\n"
+ " --help Prints this help message\n"
+ " -c Specify config file path.\n";
+
+int pow_args_parse(int argc, char **argv, pow_args *args) {
+ int flags = 0;
+
+ for (int i = 0; i < argc; i++) {
+ char *arg = argv[i];
+
+ if (strcmp(arg, "--help") == 0) {
+ flags |= POW_FLAG_HELP;
+
+ continue;
+ }
+
+ if (strcmp(arg, "-c") == 0) {
+ }
+ }
+
+ args->flags = flags;
+
+ return 0;
+}
+
+void pow_args_print_help() { printf("%s", help); };
diff --git a/src/args.h b/src/args.h
new file mode 100644
index 0000000..79ea308
--- /dev/null
+++ b/src/args.h
@@ -0,0 +1,14 @@
+#include "stddef.h"
+
+#define DEFAULT_CONFIG_PATH "/etc/pow/opts.lua"
+
+#define POW_FLAG_HELP 1
+
+typedef struct {
+ int flags;
+
+ char *cfg_path;
+} pow_args;
+
+int pow_args_parse(int argc, char *argv[], pow_args *args);
+void pow_args_print_help();
diff --git a/src/config.c b/src/config.c
new file mode 100644
index 0000000..33d59b8
--- /dev/null
+++ b/src/config.c
@@ -0,0 +1,31 @@
+#include "config.h"
+
+#include "lauxlib.h"
+
+int open_config(pow_config *cfg, char *path) {
+ int err;
+
+ cfg->L = luaL_newstate();
+
+ if (!cfg->L) {
+ return 1;
+ }
+
+ lua_State *L = cfg->L; // just easier to access
+
+ err = luaL_loadfile(L, path);
+
+ if (err) {
+ return 1;
+ }
+
+ err = lua_pcall(L, 0, 0, 0);
+
+ if (err) {
+ printf("%s\n", lua_tostring(L, -1));
+
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/src/config.h b/src/config.h
new file mode 100644
index 0000000..9150a82
--- /dev/null
+++ b/src/config.h
@@ -0,0 +1,11 @@
+#include "repo.h"
+
+#include "lua.h"
+
+typedef struct {
+ pow_repo **repos;
+
+ lua_State *L;
+} pow_config;
+
+int open_config(pow_config *cfg, char *path);
diff --git a/src/main.c b/src/main.c
index 9cc3ae6..4de964d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,15 @@
-#include <stdio.h>
+#include "args.h"
-int main() {
- printf("hello world!");
+int main(int argc, char *argv[]) {
+ pow_args args = {0};
+
+ pow_args_parse(argc, argv, &args);
+
+ if (args.flags & POW_FLAG_HELP) {
+ pow_args_print_help();
+
+ return 0;
+ }
return 0;
}
diff --git a/src/repo.c b/src/repo.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/repo.c
diff --git a/src/repo.h b/src/repo.h
new file mode 100644
index 0000000..9787375
--- /dev/null
+++ b/src/repo.h
@@ -0,0 +1,3 @@
+typedef struct {
+ char *path;
+} pow_repo;