diff options
author | Anastasios Grammenos <anastasios.grammenos@noris.gr> | 2022-11-26 17:36:00 +0200 |
---|---|---|
committer | Anastasios Grammenos <anastasios.grammenos@noris.gr> | 2022-11-26 17:36:00 +0200 |
commit | 5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb (patch) | |
tree | a1c75260034119e8e7d2e5e7fd41ca18751900d0 | |
parent | 6b4fb66e50a566397ea68ec5e7ccb9196b6116da (diff) | |
download | foodtools-5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb.tar.gz foodtools-5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb.tar.bz2 foodtools-5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb.zip |
ubuntu build and more cook
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | src/cook.c | 35 |
2 files changed, 27 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac index 70c8713..f5d2f47 100644 --- a/configure.ac +++ b/configure.ac @@ -35,8 +35,8 @@ AC_CHECK_FUNCS([strerror]) AC_CHECK_FUNCS([strstr]) AC_CHECK_FUNCS([strtol]) AC_CHECK_HEADERS([stdint.h]) -AC_FUNC_MALLOC -AC_FUNC_REALLOC +#AC_FUNC_MALLOC +#AC_FUNC_REALLOC AC_TYPE_INT32_T AC_TYPE_SIZE_T AC_TYPE_UINT32_T @@ -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); |