summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2021-11-06 13:58:32 +0200
committergramanas <anastasis.gramm2@gmail.com>2021-11-06 13:58:32 +0200
commitaafa144e680fe3d11f0e59ea779dff1caa96ef67 (patch)
tree11e9e11d856437c63d9b6e42b8fd42378087bb90 /parser.c
parent66a86d1b20a1e97b2d008e73db7557887fc44edf (diff)
downloadfoodtools-aafa144e680fe3d11f0e59ea779dff1caa96ef67.tar.gz
foodtools-aafa144e680fe3d11f0e59ea779dff1caa96ef67.tar.bz2
foodtools-aafa144e680fe3d11f0e59ea779dff1caa96ef67.zip
Add include number
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/parser.c b/parser.c
index 11e4876..df8d80b 100644
--- a/parser.c
+++ b/parser.c
@@ -13,6 +13,8 @@ static const int
parse_title(const char * s, recipe * r, pt * type)
{
fdebug("^ title\n");
+ int rc = 0;
+
if (s[0] == '@' && strlen(s) > 1) {
char tmp[LINE_SIZE] = "";
strcpy(tmp, ++s);
@@ -20,9 +22,10 @@ parse_title(const char * s, recipe * r, pt * type)
r->title = strdup(tmp);
} else {
r->title = strdup(r->filename);
+ rc = 1;
}
*type = ITEMS;
- return 0;
+ return rc;
}
static const int
@@ -34,12 +37,21 @@ parse_item(const char * s, recipe * r, pt * type, char * error)
return 0;
}
- if (s[0] == '!') {
+ /* 1 - 9 in ascii */
+ if ((s[0] > 48 && s[0] < 58) || s[0] == '!') {
fdebug("INCLUDING: %s\n", s);
char tmp[LINE_SIZE] = "";
char path[LINE_SIZE] = "";
- strcpy(tmp, ++s);
+
+ char *endptr;
+ int n = (int)strtol(s, &endptr, 10);
+ if (endptr[0] != '!') {
+ sprintf(error, "malformed include: %s", s);
+ return 1;
+ }
+
+ strcpy(tmp, ++endptr);
trim(tmp);
if (!strlen(tmp)) {
@@ -60,6 +72,7 @@ parse_item(const char * s, recipe * r, pt * type, char * error)
sprintf(error, "Couldn't include %s", path);
return 1;
}
+ rr->n = n;
//copy_items(r, rr);
new_subrecipe(r, rr);
//free_recipe(rr);
@@ -99,6 +112,11 @@ parse_item(const char * s, recipe * r, pt * type, char * error)
buf[c] = '\0';
trim(buf);
+ if (!itemc) {
+ sprintf(error, "malformed ingderient: %s", buf);
+ return 1;
+ }
+
if (!strlen(buf)) {
sprintf(error, "empty ingredient quantity: %s", s);
return 1;
@@ -141,7 +159,7 @@ handle_line(const char * s, recipe * r, char * error, pt * type, const char * pr
switch (*type) {
case TITLE:
- if (!parse_title(s, r, type))
+ if (parse_title(s, r, type))
if (parse_item(s, r, type, error))
return 1;
break;