summaryrefslogtreecommitdiffstats
path: root/food.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 /food.c
parent98849f6afb8e216000f6c642d9c9ffa26a58bd4c (diff)
downloadfoodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.tar.gz
foodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.tar.bz2
foodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.zip
sha1 sum and others
Diffstat (limited to 'food.c')
-rw-r--r--food.c64
1 files changed, 44 insertions, 20 deletions
diff --git a/food.c b/food.c
index d0466a3..f7ddbc1 100644
--- a/food.c
+++ b/food.c
@@ -4,6 +4,7 @@
#include "src/parser.h"
#include "src/search.h"
#include "src/eval.h"
+#include "src/lib.h"
recipe ** cookbook;
@@ -14,6 +15,7 @@ static struct opts {
char query[2048];
int eval;
int list;
+ int hash;
int search;
int search_strict;
int help;
@@ -24,6 +26,7 @@ static struct opts {
.query = "",
.eval = 1,
.list = 0,
+ .hash = 0,
.search = 0,
.search_strict = 0,
.help = 0,
@@ -65,6 +68,7 @@ main(int argc, char * argv[])
{"format", required_argument, 0, 'f'},
{"search", required_argument, 0, 's'},
{"strict", required_argument, 0, 'S'},
+ {"hash", required_argument, 0, 'H'},
{"list-ingredients", no_argument, 0, 'l'},
// {"to-rcp", required_argument, 0, 'r'},
{0, 0, 0, 0}
@@ -72,7 +76,7 @@ main(int argc, char * argv[])
int option_index = 0;
- c = getopt_long (argc, argv, "jnlhrwf:s:S:",
+ c = getopt_long (argc, argv, "jnlhrwf:s:S:H:",
long_options, &option_index);
if (c == -1)
@@ -106,6 +110,10 @@ main(int argc, char * argv[])
opt.search_strict = 1;
strcpy(opt.query, optarg);
break;
+ case 'H':
+ opt.hash = 1;
+ strcpy(opt.query, optarg);
+ break;
case 'j':
opt.json = 1;
break;
@@ -137,33 +145,49 @@ main(int argc, char * argv[])
return 0;
}
- if (optind < argc) {
- while (optind < argc) {
- recipe * r = parse(argv[optind++], NULL);
- if (r) {
- if (opt.search) {
- if (!query_for_items(r, opt.query, opt.search_strict))
- continue;
- }
- if (opt.eval) {
- recipe * r_eval = eval(r);
+ char ** lib = NULL;
+ int n = collect_library(&lib, argv, argc, optind);
+
+ for (int i = 0; i < n; i++) {
+ recipe * r = parse(lib[i], NULL);
+ if (r) {
+ if (opt.eval) {
+ recipe * r_eval = eval(r);
+ free_recipe(r);
+ r = r_eval;
+ }
+ if (opt.hash) {
+ if (!check_hash(r, opt.query)) {
free_recipe(r);
- r = r_eval;
+ continue;
}
- if (opt.list) {
- pprint_items(r);
+ }
+ if (opt.search) {
+ int c;
+ if (!(c = query_for_items_pbn(r, opt.query, opt.search_strict))) {
+ free_recipe(r);
+ continue;
}
+ if (c < 0)
+ exit(1);
+ }
+
+ if (opt.list) {
+ pprint_items(r);
+ }
+ else {
+ if (opt.json) tojson(r);
+ else if (opt.html) tohtml(r);
+ else if (opt.rcp) torcp(r);
else {
- if (opt.json) tojson(r);
- if (opt.html) tohtml(r);
- if (opt.rcp) torcp(r);
+ listing(r);
}
- free_recipe(r);
}
+ free_recipe(r);
}
- } else {
- fprintf(stderr, "Specify filenames\n");
}
+ free_library(lib, n);
+
return 0;
}