#include "eval.h" #include "util.h" #include extern int sha1digest(uint8_t *digest, char *hexdigest, const uint8_t *data, size_t databytes); void create_hash(recipe * r) { char data[FOOD_MAX_ARRAY] = "\0"; for (int i = 0; i < r->in; i++) { strcat(data, r->i[i]->name); strcat(data, r->i[i]->qty); } if (r->sn) { for (int i = 0; i < r->sn; i++) strcat(data, r->s[i]->inst); } 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->txt = inst2txt(s->inst); s->duration = inst2duration(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) { if (!r) return NULL; recipe * _r = new_recipe(); merge_items(_r, r); merge_steps(_r, r); copy_metadata(_r, r); copy_subrecipes(_r, r, 0 /* shallow copy off */); create_hash(_r); resolve_steps(_r); return _r; }