summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnastasios Grammenos <anastasios.grammenos@noris.gr>2022-11-26 17:36:00 +0200
committerAnastasios Grammenos <anastasios.grammenos@noris.gr>2022-11-26 17:36:00 +0200
commit5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb (patch)
treea1c75260034119e8e7d2e5e7fd41ca18751900d0 /src
parent6b4fb66e50a566397ea68ec5e7ccb9196b6116da (diff)
downloadfoodtools-5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb.tar.gz
foodtools-5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb.tar.bz2
foodtools-5aa48ee3bd2797d0f39ffc677d97384dbe0f59fb.zip
ubuntu build and more cook
Diffstat (limited to 'src')
-rw-r--r--src/cook.c35
1 files changed, 25 insertions, 10 deletions
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);