aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.c46
-rw-r--r--src/args.h5
-rw-r--r--src/config.c2
-rw-r--r--src/main.c8
-rw-r--r--src/package.c0
-rw-r--r--src/package.h9
-rw-r--r--src/repo.c56
-rw-r--r--src/repo.h10
-rw-r--r--src/utils.c6
-rw-r--r--src/utils.h3
10 files changed, 142 insertions, 3 deletions
diff --git a/src/args.c b/src/args.c
index b353579..d5ea57e 100644
--- a/src/args.c
+++ b/src/args.c
@@ -3,6 +3,7 @@
#include "stdbool.h"
#include "stdio.h"
#include "string.h"
+#include "utils.h"
char *help = "▄▄▄▄▄▄▄▄▄▄▄ ▄\n"
"█ █ █ ▄ █\n"
@@ -22,6 +23,7 @@ int pow_args_parse(int argc, char **argv, pow_args *args) {
int flags = 0;
bool next_flag_config;
+ bool next_flag_package;
for (int i = 0; i < argc; i++) {
char *arg = argv[i];
@@ -40,6 +42,20 @@ int pow_args_parse(int argc, char **argv, pow_args *args) {
continue;
}
+ if (next_flag_package) {
+ if (!strncmp(arg, "-", sizeof("-") - 1)) {
+ printf("Missing package argument\n");
+
+ return 1;
+ }
+
+ args->package = arg;
+
+ next_flag_package = false;
+
+ continue;
+ }
+
if (strcmp(arg, "--help") == 0) {
flags |= POW_FLAG_HELP;
@@ -51,6 +67,36 @@ int pow_args_parse(int argc, char **argv, pow_args *args) {
continue;
}
+
+ if (string_has_prefix("-", arg)) {
+ size_t len = strlen(arg);
+
+ for (size_t j = 0; j < len; j++) {
+ char c = (char)arg[j];
+
+ switch (c) {
+ case 'S': {
+ if (flags & POW_FLAG_SYNC) {
+ printf("flag double defined, skipping\n");
+ }
+
+ flags |= POW_FLAG_SYNC;
+ next_flag_package = true;
+ };
+ case 'Q': {
+ if (flags & POW_FLAG_QUERY) {
+ printf("flag double defined, skipping\n");
+
+ flags |= POW_FLAG_QUERY;
+
+ next_flag_package = true;
+ }
+ }
+ }
+ }
+
+ continue;
+ }
}
if (next_flag_config) {
diff --git a/src/args.h b/src/args.h
index 79ea308..578eeb7 100644
--- a/src/args.h
+++ b/src/args.h
@@ -2,12 +2,15 @@
#define DEFAULT_CONFIG_PATH "/etc/pow/opts.lua"
-#define POW_FLAG_HELP 1
+#define POW_FLAG_HELP 0x01
+#define POW_FLAG_SYNC 0x02
+#define POW_FLAG_QUERY 0x04
typedef struct {
int flags;
char *cfg_path;
+ char *package;
} pow_args;
int pow_args_parse(int argc, char *argv[], pow_args *args);
diff --git a/src/config.c b/src/config.c
index dd44129..d82cf9f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -80,8 +80,6 @@ int pow_open_config(pow_config *cfg, char *path) {
}
repo->path = path_dup;
-
- printf("%s\n", path);
} else {
printf("invalid (or non existent) path for repo\n");
diff --git a/src/main.c b/src/main.c
index abc3ffc..64cb537 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,8 @@
#include "args.h"
#include "config.h"
+#include "repo.h"
+
+#include "stdio.h"
int main(int argc, char *argv[]) {
pow_args args = {0};
@@ -15,6 +18,11 @@ int main(int argc, char *argv[]) {
pow_config config = {0};
pow_open_config(&config, args.cfg_path);
+
+ if (args.flags & POW_FLAG_QUERY) {
+ repo_check_package(config.repos, config.repos_count, args.package);
+ }
+
pow_close_config(&config);
return 0;
diff --git a/src/package.c b/src/package.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/package.c
diff --git a/src/package.h b/src/package.h
new file mode 100644
index 0000000..c555428
--- /dev/null
+++ b/src/package.h
@@ -0,0 +1,9 @@
+#include "stddef.h"
+
+typedef struct {
+ const char *name;
+ const char *version;
+ const char *description;
+
+ size_t *arch;
+} pow_package;
diff --git a/src/repo.c b/src/repo.c
index e69de29..9238a27 100644
--- a/src/repo.c
+++ b/src/repo.c
@@ -0,0 +1,56 @@
+#define _XOPEN_SOURCE 700
+
+#include "repo.h"
+
+#include "dirent.h"
+#include "limits.h"
+#include "malloc.h"
+#include "stdio.h"
+
+int repo_check_package(pow_repo **repos, size_t repo_count, const char *query) {
+ if (!repos) {
+ printf("no repos defined in your config, please define them\n");
+
+ return 1;
+ }
+
+ DIR *dp;
+ struct dirent *ep;
+
+ for (size_t i = 0; i < repo_count; i++) {
+ char *package_path = malloc(PATH_MAX);
+
+ if (!package_path) {
+ printf("failed to allocate package_path, sizeof %zu\n", PATH_MAX);
+
+ return 1;
+ }
+
+ int written =
+ snprintf(package_path, PATH_MAX, "%s/%s", repos[i]->path, query);
+
+ if (written >= PATH_MAX) {
+ printf("something went seriously wrong. the path for the package %s is "
+ "too long?\n",
+ query);
+
+ free(package_path);
+
+ return 1;
+ }
+
+ dp = opendir(package_path);
+
+ free(package_path);
+
+ if (!dp) {
+ continue;
+ }
+
+ printf("found package %s in repo %s\n", query, repos[i]->path);
+
+ closedir(dp);
+ }
+
+ return 0;
+}
diff --git a/src/repo.h b/src/repo.h
index be04b3c..958210d 100644
--- a/src/repo.h
+++ b/src/repo.h
@@ -1,5 +1,15 @@
+#ifndef _POW_REPO_H
+#define _POW_REPO_H
+
#include "stddef.h"
+#define POW_X86_64 1
+#define POW_ARM 2
+
typedef struct {
const char *path;
} pow_repo;
+
+int repo_check_package(pow_repo **repos, size_t repo_count, const char *query);
+
+#endif
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..19dc193
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,6 @@
+#include "utils.h"
+#include "string.h"
+
+bool string_has_prefix(const char *pre, const char *str) {
+ return strncmp(pre, str, strlen(pre)) == 0;
+}
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..1c5163b
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,3 @@
+#include "stdbool.h"
+
+bool string_has_prefix(const char *pre, const char *str);