summaryrefslogtreecommitdiffstats
path: root/src/food.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/food.c')
-rw-r--r--src/food.c90
1 files changed, 56 insertions, 34 deletions
diff --git a/src/food.c b/src/food.c
index 7ee222e..9506713 100644
--- a/src/food.c
+++ b/src/food.c
@@ -13,10 +13,13 @@ static struct opts {
int html;
int rcp;
char query[2048];
+ char add_val[100][2048];
char includes[100][2048];
int includes_n;
int title;
int eval;
+ int add;
+ int add_n;
int list;
int hash;
int search;
@@ -27,9 +30,12 @@ static struct opts {
.html = 0,
.rcp = 0,
.query = "",
+ .add_val = {""},
.includes = {""},
.includes_n = 0,
.eval = 1,
+ .add = 0,
+ .add_n = 0,
.title = 0,
.list = 0,
.hash = 0,
@@ -71,6 +77,8 @@ main(int argc, char * argv[])
{"to-json", no_argument, 0, 'j'},
{"to-html", no_argument, 0, 'w'},
{"to-rcp", no_argument, 0, 'r'},
+ {"add-item", required_argument, 0, 'a'},
+ //{"add-step", required_argument, 0, 'o'},
{"format", required_argument, 0, 'f'},
{"include", required_argument, 0, 'I'},
{"search", required_argument, 0, 's'},
@@ -84,7 +92,7 @@ main(int argc, char * argv[])
int option_index = 0;
- c = getopt_long (argc, argv, "jnlhrwf:s:S:t:H:I:",
+ c = getopt_long (argc, argv, "jnlhrwf:s:S:t:H:I:a:",
long_options, &option_index);
if (c == -1)
@@ -147,6 +155,10 @@ main(int argc, char * argv[])
case 'n':
opt.eval = 0;
break;
+ case 'a':
+ opt.add = 1;
+ strcpy(opt.add_val[opt.add_n++], optarg);
+ break;
case '?':
return -1;
break;
@@ -164,49 +176,59 @@ main(int argc, char * argv[])
int n = collect_library(&lib,
argv, argc, optind,
opt.includes, opt.includes_n);
-
+
for (int i = 0; i < n; i++) {
recipe * r = parse(lib[i], NULL);
- if (r) {
- if (opt.eval) {
- recipe * r_eval = eval(r);
+ if (!r) {
+ fprintf(stderr, "Recipe %s not found\n", lib[i]);
+ continue;
+ }
+
+ 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.hash) {
- if (!check_hash(r, opt.query)) {
- free_recipe(r);
- continue;
- }
- }
- if (opt.title) {
- if (strcmp(r->title, opt.query)) {
- free_recipe(r);
- continue;
- }
+ }
+ if (opt.title) {
+ if (strcmp(r->title, opt.query)) {
+ free_recipe(r);
+ continue;
}
- 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.search) {
+ int c;
+ if (!(c = query_for_items_pbn(r, opt.query, opt.search_strict))) {
+ free_recipe(r);
+ continue;
}
- if (opt.list) {
- pprint_items(r);
+ if (c < 0)
+ exit(1);
+ }
+ if (opt.add) {
+ for (int j = 0; j < opt.add_n; j++) {
+ char err[1000];
+ if (parse_item(opt.add_val[j], r, (pt *)NULL, err))
+ fprintf(stderr, "Error: %s\n", err);
}
+ }
+ 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);
- else if (opt.html) tohtml(r);
- else if (opt.rcp) torcp(r);
- else {
- listing(r);
- }
+ listing(r);
}
- free_recipe(r);
}
+ free_recipe(r);
}
free_library(lib, n);