Fix line numbers in #error preprocessor directives.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 13 Feb 2009 23:55:10 -0500
changeset 615 5467d19b4d7d
parent 614 0f2f298003ae
child 616 9f087be64555
Fix line numbers in #error preprocessor directives.
mojoshader_preprocessor.c
--- a/mojoshader_preprocessor.c	Fri Feb 13 23:38:21 2009 -0500
+++ b/mojoshader_preprocessor.c	Fri Feb 13 23:55:10 2009 -0500
@@ -639,18 +639,17 @@
     const char *data = NULL;
     int done = 0;
 
+    const char *source = NULL;
     while (!done)
     {
-        const char *source = state->source;
+        source = state->source;
         const Token token = preprocessor_internal_lexer(state);
         switch (token)
         {
+            case ((Token) '\n'):
+                state->line--;  // make sure error is on the right line.
+                // fall through!
             case TOKEN_INCOMPLETE_COMMENT:
-                state->source = source;  // move back so we catch this later.
-                done = 1;
-                break;
-
-            case ((Token) '\n'):
             case TOKEN_EOI:
                 done = 1;
                 break;
@@ -662,6 +661,8 @@
         } // switch
     } // while
 
+    state->source = source;  // move back so we catch this later.
+
     const char *prefix = "#error ";
     const size_t prefixlen = strlen(prefix);
     const int len = (int) (state->source - data);