diff options
author | Anastasios Grammenos <anastasios.grammenos@noris.gr> | 2022-06-06 20:35:45 +0300 |
---|---|---|
committer | Anastasios Grammenos <anastasios.grammenos@noris.gr> | 2022-06-06 20:35:45 +0300 |
commit | d8ac772cb5217df8fce435307524242a50153a07 (patch) | |
tree | bbda6a6a74ec5bed1e285fb58e5f2444dbd43d5f /src/parser.c | |
parent | 55eb1d5f31544ed51e1e31024ecbb9cde68b0c72 (diff) | |
download | foodtools-d8ac772cb5217df8fce435307524242a50153a07.tar.gz foodtools-d8ac772cb5217df8fce435307524242a50153a07.tar.bz2 foodtools-d8ac772cb5217df8fce435307524242a50153a07.zip |
Allow empty ingredient quantity
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c index e4bffb4..9206f42 100644 --- a/src/parser.c +++ b/src/parser.c @@ -87,7 +87,10 @@ parse_item(const char * s, recipe * r, pt * type, char * error) char buf[LINE_SIZE] = ""; for (int i = 0; i < l; i++) { if (val) { - if (s[i] == ',' || s[i] == '=') { + if (s[i] == ',' || s[i] == '=' || i == l - 1) { + if (i == l - 1) { + buf[c++] = s[i]; + } buf[c++] = '\0'; if (!strlen(buf)) { sprintf(error, "malformed ingredient: %s", s); @@ -118,8 +121,9 @@ parse_item(const char * s, recipe * r, pt * type, char * error) } if (!strlen(buf)) { - sprintf(error, "empty ingredient quantity: %s", s); - return 1; + // sprintf(error, "empty ingredient quantity: %s", s); + // return 1; + strcpy(buf, "*"); } for (int i = 0; i < itemc; i++) { @@ -230,7 +234,10 @@ parse(char * path, const char * prev) strcpy(tmp, path); } f = fopen(tmp, "r"); - if (!f) return NULL; + if (!f) { + fprintf(stderr, "Can't open %s\n", path); + return NULL; + } } recipe * r = new_recipe(); |