summaryrefslogtreecommitdiffstats
path: root/src/lib.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2022-01-28 13:45:30 +0200
committergramanas <anastasis.gramm2@gmail.com>2022-01-28 13:45:30 +0200
commit53ab9ae05a579a19c626e8be0c1e2cf9244bf863 (patch)
treee6ec5ce8920124e8f4dd59d2ca20f45f30b4640e /src/lib.c
parent98849f6afb8e216000f6c642d9c9ffa26a58bd4c (diff)
downloadfoodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.tar.gz
foodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.tar.bz2
foodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.zip
sha1 sum and others
Diffstat (limited to 'src/lib.c')
-rw-r--r--src/lib.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib.c b/src/lib.c
new file mode 100644
index 0000000..f43bdc2
--- /dev/null
+++ b/src/lib.c
@@ -0,0 +1,48 @@
+#include "lib.h"
+#include "util.h"
+
+int
+collect_library(char *** dst, char * argv[], int argc, int optind)
+{
+ int n = 0;
+ FILE *fp;
+ char path[1035];
+
+ char ** lib = NULL;
+
+ for (int i = optind; i < argc; i++) {
+ lib = realloc(lib, sizeof(char **) * (n + 1));
+ lib[n] = strdup(argv[i]);
+ fdebug("%d: %s\n", n, lib[n]);
+ n = n + 1;
+ }
+
+ fp = popen("/bin/find /home/gramanas/code/foodtools/lib/ -name '*.rcp'", "r");
+ if (fp == NULL) {
+ fprintf(stderr, "Couldn't run /bin/find\n");
+ exit(1);
+ }
+
+ /* Read the output a line at a time */
+ while (fgets(path, sizeof(path), fp) != NULL) {
+ lib = realloc(lib, sizeof(char **) * (n + 1));
+ trim(path);
+ lib[n] = strdup(path);
+ fdebug("%d: %s\n", n, lib[n]);
+ n = n + 1;
+ }
+
+ /* close */
+ pclose(fp);
+
+ *dst = lib;
+ return n; // no of items
+}
+
+void
+free_library(char ** lib, int n) {
+ for (int i = 0; i < n; i++) {
+ free(lib[i]);
+ }
+ free(lib);
+}