diff options
author | Anastasios Grammenos <anastasios.grammenos@noris.gr> | 2022-10-23 21:05:57 +0300 |
---|---|---|
committer | Anastasios Grammenos <anastasios.grammenos@noris.gr> | 2022-10-23 21:05:57 +0300 |
commit | 51d16373fbaa027e91f230a7423ebb1b2d339042 (patch) | |
tree | 9f088ae6544eb646c9c90e2323beeab9663e4360 /src/eval.c | |
parent | 7c5af1b2768247984a08569b35e47ff927e70389 (diff) | |
download | foodtools-51d16373fbaa027e91f230a7423ebb1b2d339042.tar.gz foodtools-51d16373fbaa027e91f230a7423ebb1b2d339042.tar.bz2 foodtools-51d16373fbaa027e91f230a7423ebb1b2d339042.zip |
More
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 57 |
1 files changed, 55 insertions, 2 deletions
@@ -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<strlen(s); i++) { + l = strlen(txt); + switch(s[i]) { + case '$': + case '[': + case ']': + case '{': + case '}': + continue; + default: + txt[l] = s[i]; + txt[l+1] = '\0'; + } + } + return strdup(txt); +} + +/* TODO: Still needs work for when the `[`s are not balanced */ +char * +inst2duration(char * s) +{ + char duration[FOOD_MAX_ARRAY] = "\0"; + + int flag = 0; + int l = 0; + + for (int i=0; i<strlen(s); i++) { + if (s[i] == ']') + flag = flag - 1; + if (flag > 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; } |