From cf1ea01de310ebfd9338d86d6cf649c81ce17a01 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sun, 11 Nov 2012 10:32:43 +0100 Subject: [PATCH] parser_compile_file vs parser_compile_string --- gmqcc.h | 9 +++++---- main.c | 4 ++-- parser.c | 28 +++++++++++++++++++++------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/gmqcc.h b/gmqcc.h index bf3c7c6..7b10013 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -939,10 +939,11 @@ void cprintmsg (lex_ctx ctx, int lvl, const char *msgtype, const char *msg, ...) /*===================== parser.c commandline ========================*/ /*===================================================================*/ -bool parser_init (); -bool parser_compile(const char *filename); -bool parser_finish (const char *output); -void parser_cleanup(); +bool parser_init (); +bool parser_compile_file (const char *filename); +bool parser_compile_string(const char *name, const char *str); +bool parser_finish (const char *output); +void parser_cleanup (); /*===================================================================*/ /*======================= main.c commandline ========================*/ diff --git a/main.c b/main.c index a65a735..dddc9eb 100644 --- a/main.c +++ b/main.c @@ -460,7 +460,7 @@ int main(int argc, char **argv) { (items_data[itr].type == TYPE_SRC ? "progs.src" : ("unknown")))))); - if (!parser_compile(items_data[itr].filename)) { + if (!parser_compile_file(items_data[itr].filename)) { retval = 1; goto cleanup; } @@ -500,7 +500,7 @@ int main(int argc, char **argv) { if (!line[0] || (line[0] == '/' && line[1] == '/')) continue; printf(" src: %s\n", line); - if (!parser_compile(line)) { + if (!parser_compile_file(line)) { retval = 1; goto srcdone; } diff --git a/parser.c b/parser.c index 72fa486..f548e22 100644 --- a/parser.c +++ b/parser.c @@ -2840,14 +2840,8 @@ bool parser_init() return true; } -bool parser_compile(const char *filename) +bool parser_compile() { - parser->lex = lex_open(filename); - if (!parser->lex) { - printf("failed to open file \"%s\"\n", filename); - return false; - } - /* initial lexer/parser state */ parser->lex->flags.noops = true; @@ -2878,6 +2872,26 @@ bool parser_compile(const char *filename) return !parser->errors; } +bool parser_compile_file(const char *filename) +{ + parser->lex = lex_open(filename); + if (!parser->lex) { + printf("failed to open file \"%s\"\n", filename); + return false; + } + return parser_compile(); +} + +bool parser_compile_string(const char *name, const char *str) +{ + parser->lex = lex_open_string(str, strlen(str), name); + if (!parser->lex) { + printf("failed to create lexer for string \"%s\"\n", name); + return false; + } + return parser_compile(); +} + void parser_cleanup() { size_t i; -- 2.39.2