summaryrefslogtreecommitdiffstats
path: root/src/eval.c
blob: 1267b00bdb8853f1ab8b022386494d165e5dd88c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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[FODD_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));
}

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);

  create_hash(_r);
  
  return _r;
}