summaryrefslogtreecommitdiffstats
path: root/food.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2021-12-20 22:52:48 +0200
committergramanas <anastasis.gramm2@gmail.com>2021-12-20 22:52:48 +0200
commitdbd6366285b23483567f2c1dc814fc9f371c4c64 (patch)
tree6df025dc5e668ddc618fddde289c4c2b1025e8dd /food.c
parentbf4733f991bb9e643ebc697d6f9f92b3bb6ad69c (diff)
downloadfoodtools-dbd6366285b23483567f2c1dc814fc9f371c4c64.tar.gz
foodtools-dbd6366285b23483567f2c1dc814fc9f371c4c64.tar.bz2
foodtools-dbd6366285b23483567f2c1dc814fc9f371c4c64.zip
merge steps
Diffstat (limited to 'food.c')
-rw-r--r--food.c62
1 files changed, 47 insertions, 15 deletions
diff --git a/food.c b/food.c
index 90ce489..d0466a3 100644
--- a/food.c
+++ b/food.c
@@ -2,6 +2,7 @@
#include "src/util.h"
#include "src/parser.h"
+#include "src/search.h"
#include "src/eval.h"
recipe ** cookbook;
@@ -10,15 +11,21 @@ static struct opts {
int json;
int html;
int rcp;
- char *query;
+ char query[2048];
+ int eval;
int list;
+ int search;
+ int search_strict;
int help;
} opt = {
.json = 0,
.html = 0,
.rcp = 0,
- .query = NULL,
+ .query = "",
+ .eval = 1,
.list = 0,
+ .search = 0,
+ .search_strict = 0,
.help = 0,
};
@@ -32,6 +39,9 @@ print_help(char * argv0) {
printf("-w html\n");
printf("-r rcp\n");
printf("-l, --list-ingredients\n");
+ printf("-s TERMS, --search TERMS\n");
+ printf("-S TERMS, --strict TERMS\n");
+ printf("-n, --no-eval\n");
}
int
@@ -48,10 +58,13 @@ main(int argc, char * argv[])
// {"verbose", no_argument, &verbose_flag, 1},
// {"brief", no_argument, &verbose_flag, 0},
{"help", no_argument, 0, 'h'},
+ {"no-eval", no_argument, 0, 'n'},
{"to-json", no_argument, 0, 'j'},
{"to-html", no_argument, 0, 'w'},
{"to-rcp", no_argument, 0, 'r'},
{"format", required_argument, 0, 'f'},
+ {"search", required_argument, 0, 's'},
+ {"strict", required_argument, 0, 'S'},
{"list-ingredients", no_argument, 0, 'l'},
// {"to-rcp", required_argument, 0, 'r'},
{0, 0, 0, 0}
@@ -59,7 +72,7 @@ main(int argc, char * argv[])
int option_index = 0;
- c = getopt_long (argc, argv, "jlhrwf:",
+ c = getopt_long (argc, argv, "jnlhrwf:s:S:",
long_options, &option_index);
if (c == -1)
@@ -84,6 +97,15 @@ main(int argc, char * argv[])
else
fprintf(stderr, "invalid format: %s\n", optarg);
break;
+ case 's':
+ opt.search = 1;
+ strcpy(opt.query, optarg);
+ break;
+ case 'S':
+ opt.search = 1;
+ opt.search_strict = 1;
+ strcpy(opt.query, optarg);
+ break;
case 'j':
opt.json = 1;
break;
@@ -99,6 +121,9 @@ main(int argc, char * argv[])
case 'h':
opt.help = 1;
break;
+ case 'n':
+ opt.eval = 0;
+ break;
case '?':
return -1;
break;
@@ -115,19 +140,26 @@ main(int argc, char * argv[])
if (optind < argc) {
while (optind < argc) {
recipe * r = parse(argv[optind++], NULL);
- if (r && opt.list) {
- /* recipe * r_merged = new_recipe(); */
- /* merge_items(r_merged, r); */
- recipe * r_merged = eval(r);
- pprint_items(r_merged);
- free_recipe(r_merged);
- }
- else if (r) {
- if (opt.json) tojson(r);
- if (opt.html) tohtml(r);
- if (opt.rcp) torcp(r);
+ if (r) {
+ if (opt.search) {
+ if (!query_for_items(r, opt.query, opt.search_strict))
+ continue;
+ }
+ if (opt.eval) {
+ recipe * r_eval = eval(r);
+ free_recipe(r);
+ r = r_eval;
+ }
+ if (opt.list) {
+ pprint_items(r);
+ }
+ else {
+ if (opt.json) tojson(r);
+ if (opt.html) tohtml(r);
+ if (opt.rcp) torcp(r);
+ }
+ free_recipe(r);
}
- free_recipe(r);
}
} else {
fprintf(stderr, "Specify filenames\n");