diff options
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; } |