]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
parser_compile_file vs parser_compile_string
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 09:32:43 +0000 (10:32 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 09:33:29 +0000 (10:33 +0100)
gmqcc.h
main.c
parser.c

diff --git a/gmqcc.h b/gmqcc.h
index bf3c7c664beb1658ec27c54dcefc80e6e9cdd55e..7b100139bbf54191e71a43299d3c25edd02b29a1 100644 (file)
--- 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 a65a735ebb6b351442bf6c8be743bc31bc654a76..dddc9eb3d51a3fa5ff8ee306ff641aa8c2e3fe21 100644 (file)
--- 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;
             }
index 72fa486ca0f07020f3dce7a568faf34739855f9b..f548e22403f2e5a5a82a0c58b18b16a2fc562ab5 100644 (file)
--- 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;