mojoshader_preprocessor.c
changeset 621 bbeb13128ddb
parent 620 1c4cf996004e
child 622 59b3003f6494
--- a/mojoshader_preprocessor.c	Sat Feb 14 02:47:17 2009 -0500
+++ b/mojoshader_preprocessor.c	Sat Feb 14 17:25:55 2009 -0500
@@ -744,6 +744,24 @@
 } // handle_pp_undef
 
 
+static void handle_pp_endif(Context *ctx)
+{
+    IncludeState *state = ctx->include_stack;
+    Conditional *cond = state->conditional_stack;
+
+    if (!require_newline(state))
+        fail(ctx, "Invalid #endif directive");
+    else if (cond == NULL)
+        fail(ctx, "Unmatched #endif");
+    else
+    {
+        state->conditional_stack = cond->next;  // pop it.
+        cond->next = NULL;
+        put_conditionals(ctx, cond);
+    } // else
+} // handle_pp_endif
+
+
 static void unterminated_pp_condition(Context *ctx)
 {
     IncludeState *state = ctx->include_stack;
@@ -763,7 +781,6 @@
     // pop this conditional, we'll report the next error next time...
 
     state->conditional_stack = cond->next;  // pop it.
-
     cond->next = NULL;
     put_conditionals(ctx, cond);
 } // unterminated_pp_condition
@@ -799,7 +816,6 @@
         // TOKEN_PP_IFNDEF,
         // TOKEN_PP_ELSE,
         // TOKEN_PP_ELIF,
-        // TOKEN_PP_ENDIF,
 
         const Conditional *cond = state->conditional_stack;
         const int skipping = ((cond != NULL) && (cond->skipping));
@@ -824,6 +840,12 @@
             continue;  // will return at top of loop.
         } // else if
 
+        else if (token == TOKEN_PP_ENDIF)
+        {
+            handle_pp_endif(ctx);
+            continue;  // get the next thing.
+        } // else if
+
         // !!! FIXME: #else, #elif and #endif must be above (skipping) test.
         else if (skipping)
         {