From 5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb Mon Sep 17 00:00:00 2001 From: Anastasios Grammenos Date: Sat, 26 Nov 2022 17:36:00 +0200 Subject: ubuntu build and more cook --- src/cook.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'src/cook.c') diff --git a/src/cook.c b/src/cook.c index e3e104c..80c7f9f 100644 --- a/src/cook.c +++ b/src/cook.c @@ -8,6 +8,7 @@ static struct opts { int new; int change; + int eval; char title[2048]; char includes[100][2048]; int includes_n; @@ -19,6 +20,7 @@ static struct opts { } opt = { .new = 0, .change = 0, + .eval = 0, .title = "", .includes = {""}, .includes_n = 0, @@ -38,21 +40,23 @@ main(int argc, char * argv[]) struct foodoption long_options[] = {/* name, has_arg, flag, val, help, arg */ - {"help", no_argument, 0, 'h', "Print this help", 0, "General" }, - {"include", required_argument, 0, 'I', "Path to recipe library, can be passed multiple times", "PATH", 0 }, - {"new", no_argument, 0, 'n', "Create recipe", 0, "Commands" }, - {"change", required_argument, 0, 'c', "Change recipe", "FILE", 0 }, - {"title", required_argument, 0, 't', "Set recipe title", "TITLE", "Options" }, - {"ingredient", required_argument, 0, 'i', "Add an ingredient", "INGREDIENT", 0 }, - {"step", required_argument, 0, 's', "Add a step", "STEP", 0 }, + {"help", no_argument, 0, 'h', "Print this help", 0, "General" }, + {"include", required_argument, 0, 'I', "Path to recipe library, can be passed multiple times", "PATH", 0 }, + {"eval", no_argument, 0, 'e', "Eval recipe before output", 0, 0 }, + {"new", required_argument, 0, 'n', "Create recipe", "TITLE", "Commands" }, + {"change", required_argument, 0, 'c', "Change recipe", "FILE", 0 }, + {"title", required_argument, 0, 't', "Set recipe title", "TITLE", "Options" }, + {"ingredient", required_argument, 0, 'i', "Add an ingredient", "INGREDIENT", 0 }, + {"step", required_argument, 0, 's', "Add a step", "STEP", 0 }, {0, 0, 0, 0, 0} }; while (1) { int option_index = 0; - c = get_foodopt (argc, argv, "hI:nc:t:i:s:", + c = get_foodopt (argc, argv, "ehI:n:c:t:i:s:", long_options, &option_index); + printf("ASDASDASDA\n"); if (c == -1) break; @@ -76,10 +80,14 @@ main(int argc, char * argv[]) break; case 'n': opt.new = 1; + strcpy(opt.title, optarg); break; case 'c': opt.change = 1; break; + case 'e': + opt.eval = 1; + break; case '?': fprintf(stderr, "%s: option '%c' not recognised, try -h for help\n", argv[0], optopt); return -1; @@ -120,6 +128,7 @@ main(int argc, char * argv[]) if (opt.new) { recipe * r = new_recipe(); r->path = strdup("."); + r->filename = strdup(opt.title); char err[1000] = ""; int rc = 0; @@ -128,16 +137,22 @@ main(int argc, char * argv[]) for (int i = 0; i < opt.ing_n; i++) { rc = parse_item(opt.ing[i], r, NULL, err); if (rc) { - printf("ERROR: %s\n", err); + fprintf(stderr, "ERROR: %s\n", err); } } for (int i = 0; i < opt.step_n; i++) { rc = parse_step(opt.step[i], r, err); if (rc) { - printf("ERROR: %s\n", err); + fprintf(stderr, "ERROR: %s\n", err); } } + if (opt.eval) { + recipe * r_eval = eval(r); + free_recipe(r); + r = r_eval; + } + if (!rc) torcp(r); -- cgit v1.2.3