From 51d16373fbaa027e91f230a7423ebb1b2d339042 Mon Sep 17 00:00:00 2001 From: Anastasios Grammenos Date: Sun, 23 Oct 2022 21:05:57 +0300 Subject: More --- src/eval.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/food.c | 2 +- src/types.c | 7 +++++-- src/types.h | 1 + 4 files changed, 62 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/eval.c b/src/eval.c index 98ad3bf..aa9a236 100644 --- a/src/eval.c +++ b/src/eval.c @@ -21,11 +21,64 @@ create_hash(recipe * r) sha1digest(NULL, r->sha1, (uint8_t *)data, strlen(data)); } +/* TODO: Needs work to actually remove the extra characters only when they + define a variable/time schedule */ +char * +inst2txt(char * s) +{ + char txt[FOOD_MAX_ARRAY] = "\0"; + int l = 0; + for (int i=0; i 0) { + duration[l] = s[i]; + duration[l+1] = '\0'; + l = strlen(duration); + } + if (s[i] == '[') + flag = flag + 1; + } + + if (strlen(duration)) { + return strdup(duration); + } + + return NULL; +} + int eval_step(step * s) { - s->duration = strdup(s->inst); - s->result = strdup(s->inst); + s->txt = inst2txt(s->inst); + s->duration = inst2duration(s->inst); + // s->result = strdup(s->inst); return 0; } diff --git a/src/food.c b/src/food.c index 95fde55..5c9730b 100644 --- a/src/food.c +++ b/src/food.c @@ -80,7 +80,7 @@ main(int argc, char * argv[]) {"to-html", no_argument, 0, 'w', "Format recipe to html", 0, 0 }, {"to-rcp", no_argument, 0, 'r', "Format recipe to rcp", 0, 0 }, {"list-ingredients", no_argument, 0, 'L', "List ingredients for matched recipes", 0, 0 }, - {"list", optional_argument, 0, 'l', "List matched recipes with optional FORMAT", "[FORMAT]", 0 }, + {"list", optional_argument, 0, 'l', "List matched recipes with optional FORMAT {t,p,h,s}", "[FORMAT]", 0 }, {"search", required_argument, 0, 's', "Return recipes matching QUERY", "QUERY", "Filters" }, {"title", required_argument, 0, 't', "Return recipes matching TITLE", "TITLE", 0 }, {"strict", required_argument, 0, 'S', "Return recipes matching QUERY, exactly", "QUERY", 0 }, diff --git a/src/types.c b/src/types.c index 68c402c..8debe70 100644 --- a/src/types.c +++ b/src/types.c @@ -74,6 +74,7 @@ new_step(recipe * r) if (!r->s[r->sn]) die("Couldn't allocate memory for step"); r->s[r->sn]->inst = NULL; + r->s[r->sn]->txt = NULL; r->s[r->sn]->duration = NULL; r->s[r->sn]->result = NULL; r->s[r->sn]->type = 0; @@ -87,6 +88,8 @@ free_step(step * s) return; if (s->inst) free(s->inst); + if (s->txt) + free(s->txt); if (s->duration) free(s->duration); if (s->result) @@ -220,8 +223,8 @@ tojson(recipe * r) printf(",\"steps\":["); int i = 0; for (; i < r->sn - 1; i++) - printf("{\"inst\":\"%s\",\"duration\":\"%s\",\"result\":\"%s\",\"type\":\"%s\"},", r->s[i]->inst, r->s[i]->duration, r->s[i]->result, r->s[i]->type == 0 ? "prep" : (r->s[i]->type == 1 ? "cook" : "serve") ); - printf("{\"inst\":\"%s\",\"duration\":\"%s\",\"result\":\"%s\",\"type\":\"%s\"}]", r->s[i]->inst, r->s[i]->duration, r->s[i]->result, r->s[i]->type == 0 ? "prep" : (r->s[i]->type == 1 ? "cook" : "serve") ); + printf("{\"inst\":\"%s\",\"txt\":\"%s\",\"duration\":\"%s\",\"result\":\"%s\",\"type\":\"%s\"},", r->s[i]->inst, r->s[i]->txt, r->s[i]->duration, r->s[i]->result, r->s[i]->type == 0 ? "prep" : (r->s[i]->type == 1 ? "cook" : "serve") ); + printf("{\"inst\":\"%s\",\"txt\":\"%s\",\"duration\":\"%s\",\"result\":\"%s\",\"type\":\"%s\"}]", r->s[i]->inst, r->s[i]->txt, r->s[i]->duration, r->s[i]->result, r->s[i]->type == 0 ? "prep" : (r->s[i]->type == 1 ? "cook" : "serve") ); } printf("}"); } diff --git a/src/types.h b/src/types.h index d589c79..057f889 100644 --- a/src/types.h +++ b/src/types.h @@ -14,6 +14,7 @@ enum step_type { typedef struct step_t { char *inst; + char *txt; char *duration; char *result; enum step_type type; -- cgit v1.2.3