summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c
index 98ad3bf..aa9a236 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;
}