Checked in external.h as gedcom.h (forgot to check in before...)
[gedcom-parse.git] / gedcom_lex_common.c
index d547ea4fa8eb6683e920cd60cef8772dc8250784..5d734c44689adb6e8fe9ae0b46c9bb15594af1f9 100644 (file)
 
 #ifndef IN_LEX
 
-#include "gedcom.tab.h"
-#include "gedcom.h"
+#include "gedcom_internal.h"
 #include "multilex.h"
 #include "encoding.h"
+#include "gedcom.h"
+#include "gedcom.tab.h"
 
 #define YY_NO_UNPUT
 
@@ -76,13 +77,14 @@ int test_loop(ENCODING enc, char* code)
   line_len = 0;
 
 #define CHECK_LINE_LEN                                                        \
-  { if (line_len != (size_t)-1)                                               \
+  { if (line_len != (size_t)-1) {                                             \
       line_len += strlen(yytext);                                             \
-    if (line_len > MAXGEDCLINELEN * encoding_width) {                         \
-      gedcom_error("Line too long, max %d characters",                        \
-                  MAXGEDCLINELEN);                                           \
-      line_len = (size_t)-1;                                                  \
-      return BADTOKEN;                                                        \
+      if (line_len > MAXGEDCLINELEN * encoding_width) {                       \
+        gedcom_error("Line too long, max %d characters",                      \
+                    MAXGEDCLINELEN);                                         \
+        line_len = (size_t)-1;                                                \
+        return BADTOKEN;                                                      \
+      }                                                                       \
     }                                                                         \
   }
 
@@ -264,6 +266,10 @@ int test_loop(ENCODING enc, char* code)
       return CLOSE;                                                           \
     }                                                                         \
     else {                                                                    \
+      /* Reset our state */                                                   \
+      current_level = -1;                                                     \
+      level_diff = MAXGEDCLEVEL;                                              \
+      /* ... then terminate lex */                                            \
       yyterminate();                                                          \
     }                                                                         \
   }