diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2022-09-06 10:42:48 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2022-09-06 10:42:48 +0300 |
commit | 433ce0f6795a4db89921b26274dd0b18fcccbb21 (patch) | |
tree | 8fb8f7d8a8d62b9530a525a039dc8dccf9647418 /src/parser.c | |
parent | f946969da0c409d35672dfd2749f1b66e96ee8a4 (diff) | |
download | foodtools-433ce0f6795a4db89921b26274dd0b18fcccbb21.tar.gz foodtools-433ce0f6795a4db89921b26274dd0b18fcccbb21.tar.bz2 foodtools-433ce0f6795a4db89921b26274dd0b18fcccbb21.zip |
Small parser refactor
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/parser.c b/src/parser.c index 9206f42..e90b200 100644 --- a/src/parser.c +++ b/src/parser.c @@ -217,12 +217,11 @@ next_escaped_line(FILE *f, char * line, int * lino, char * error) { return 0; } -recipe * -parse(char * path, const char * prev) +FILE * +file_from_path(const char * path) { - fdebug("Parsing: %s\n", path); - FILE *f; + if (!strcmp(path, "-")) { f = stdin; } else { @@ -234,10 +233,20 @@ parse(char * path, const char * prev) strcpy(tmp, path); } f = fopen(tmp, "r"); - if (!f) { - fprintf(stderr, "Can't open %s\n", path); - return NULL; - } + } + + return f; +} + +recipe * +parse(char * path, const char * prev) +{ + fdebug("Parsing: %s\n", path); + + FILE *f = file_from_path(path); + if (!f) { + fprintf(stderr, "Can't open %s\n", path); + return NULL; } recipe * r = new_recipe(); |