blob: 98ad3bf5fe326bdf458ab24035c5843d8849b3ee (
plain) (
tree)
|
|
#include "eval.h"
#include "util.h"
#include <stdint.h>
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));
}
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)
{
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;
}
|