diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 27 | ||||
-rw-r--r-- | src/types.c | 9 |
2 files changed, 32 insertions, 4 deletions
@@ -21,6 +21,31 @@ create_hash(recipe * r) sha1digest(NULL, r->sha1, (uint8_t *)data, strlen(data)); } +int +eval_step(step * s) +{ + s->duration = strdup(s->inst); + s->result = strdup(s->inst); + return 0; +} + +int +resolve_steps(recipe * r) +{ + if (!r) return 1; + + int rc = 0; + for (int i=0; i < r->sn; i++) { + rc += eval_step(r->s[i]); + } + + if (rc > 0) { + return 1; + } + + return 0; +} + recipe * eval(recipe * r) { @@ -33,6 +58,8 @@ eval(recipe * r) copy_subrecipes(_r, r, 0 /* shallow copy off */); create_hash(_r); + + resolve_steps(_r); return _r; } diff --git a/src/types.c b/src/types.c index 9314f8d..68c402c 100644 --- a/src/types.c +++ b/src/types.c @@ -72,7 +72,7 @@ new_step(recipe * r) r->s[r->sn] = (step *)malloc(sizeof(step)); if (!r->s[r->sn]) - die("Couldn't allocate memory for item"); + die("Couldn't allocate memory for step"); r->s[r->sn]->inst = NULL; r->s[r->sn]->duration = NULL; r->s[r->sn]->result = NULL; @@ -220,8 +220,8 @@ tojson(recipe * r) printf(",\"steps\":["); int i = 0; for (; i < r->sn - 1; i++) - printf("\"%s\",", r->s[i]->inst); - printf("\"%s\"]", r->s[i]->inst); + 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("}"); } @@ -421,7 +421,8 @@ distinct_sum_items(recipe * dst, recipe * src) if (!strcmp(dst->i[n]->qty, "") && !strcmp(src->i[i]->qty, "")) { // noop - } else if (strlen(dst->i[n]->qty) + strlen(src->i[i]->qty) != 0) { + } else if (!strcmp(dst->i[n]->qty, "") + || !strcmp(src->i[i]->qty, "")) { char tmp[FOOD_MAX_ARRAY] = ""; strcat(tmp, dst->i[n]->qty); strcat(tmp, src->i[i]->qty); |