summaryrefslogtreecommitdiffstats
path: root/src/parser.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2022-05-11 02:17:51 +0300
committergramanas <anastasis.gramm2@gmail.com>2022-05-11 02:17:51 +0300
commit3515199c9e158d4b6fe5d064539bdf288dca7b81 (patch)
tree7c4ac203010c03fefb4d736871b3b3f0a2db3f98 /src/parser.c
parent16538abf8d1231279133508ba15376145b818518 (diff)
downloadfoodtools-3515199c9e158d4b6fe5d064539bdf288dca7b81.tar.gz
foodtools-3515199c9e158d4b6fe5d064539bdf288dca7b81.tar.bz2
foodtools-3515199c9e158d4b6fe5d064539bdf288dca7b81.zip
initial library includes
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/parser.c b/src/parser.c
index df8d80b..5009ca1 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -6,7 +6,7 @@
typedef enum parser_type {
TITLE = 0,
ITEMS,
- STEPS,
+ STEPS,
} pt;
static const int
@@ -58,16 +58,22 @@ parse_item(const char * s, recipe * r, pt * type, char * error)
sprintf(error, "malformed include: %s", s);
return 1;
}
-
+
+ /* First search for full path */
if (tmp[0] == '/' || tmp[0] == '~') {
strcpy(path, tmp);
} else {
+ /* Then search for file local path */
strcpy(path, r->path);
strcat(path, "/");
strcat(path, tmp);
}
- recipe * rr = parse(path, r->filename);
+ recipe * rr = NULL;
+ rr = parse(path, r->filename);
+
+ /* TODO: Check for path from included libs */
+
if (!rr) {
sprintf(error, "Couldn't include %s", path);
return 1;
@@ -76,10 +82,10 @@ parse_item(const char * s, recipe * r, pt * type, char * error)
//copy_items(r, rr);
new_subrecipe(r, rr);
//free_recipe(rr);
-
+
return 0;
}
-
+
int l = strlen(s);
int val = 1; /* key vs value flag */
int itemc = 0;
@@ -121,7 +127,7 @@ parse_item(const char * s, recipe * r, pt * type, char * error)
sprintf(error, "empty ingredient quantity: %s", s);
return 1;
}
-
+
for (int i = 0; i < itemc; i++) {
r->i[r->in - 1 - i]->qty = strdup(buf);
}
@@ -144,7 +150,7 @@ parse_step(const char * s, recipe * r, char * error)
r->s[r->sn - 1]->inst = tmp;
return 0;
}
-
+
sprintf(error, "malformed step: %s", s);
return 1;
}
@@ -171,7 +177,7 @@ handle_line(const char * s, recipe * r, char * error, pt * type, const char * pr
if (parse_step(s, r, error))
return 1;
}
-
+
return 0;
}
@@ -204,7 +210,7 @@ next_escaped_line(FILE *f, char * line, int * lino, char * error) {
sprintf(error, "line exceeds %d characters", LINE_SIZE);
return -1;
}
-
+
/* remove `\` */
line[l - 1] = '\0';
strcat(line, tmp);
@@ -217,7 +223,7 @@ recipe *
parse(char * path, const char * prev)
{
fdebug("Parsing: %s\n", path);
-
+
FILE *f;
if (!strcmp(path, "-")) {
f = stdin;
@@ -247,7 +253,7 @@ parse(char * path, const char * prev)
char error[LINE_SIZE] = "";
int lino = 0;
enum parser_type type = TITLE;
-
+
while (!next_escaped_line(f, line, &lino, error)) {
if (handle_line(line, r, error, &type, prev))
break;