*** empty log message ***
[gedcom-parse.git] / gedcom / gedcom_1byte.lex
index 6fa1d6b0293089b3f4573f8482d7ecd1e1d6eb4e..42e7cb82453bce723dc5863e956d4e0ab1ef5676 100644 (file)
@@ -22,7 +22,8 @@
 /* $Name$ */
 
 %{
-#undef IN_LEX    /* include only a specific part of the following file */
+#define LEX_SECTION 1  /* include only a specific part of the following file */
+#define yymyinit gedcom_1byte_myinit
 #include "gedcom_lex_common.c"
 
 static size_t encoding_width = 1;
@@ -48,12 +49,13 @@ alphanum     {alpha}|{digit}
 gen_delim    {delim}|{tab}
 
 escape       @#{any_char}+@
-pointer      @{alphanum}{non_at}+@
+pointer      @{alphanum}{non_at}*@
 
 %%
 
 %{
-#define IN_LEX    /* include only a specific part of the following file */
+#undef LEX_SECTION
+#define LEX_SECTION 2  /* include only a specific part of the following file */
 #include "gedcom_lex_common.c"
 
 ACTION_BEFORE_REGEXPS
@@ -215,14 +217,41 @@ ACTION_BEFORE_REGEXPS
 .                         ACTION_UNEXPECTED
 
 %%
+#undef LEX_SECTION
+#define LEX_SECTION 3  /* include only a specific part of the following file */
+#include "gedcom_lex_common.c"
 
-static int exitfuncregistered = 0;
-
-int yywrap()
+int gedcom_check_token(const char* str, ParseState state, int check_token)
 {
-  if (! exitfuncregistered && atexit(yylex_cleanup) == 0)
-    exitfuncregistered = 1;
-  return 1;
+  int result = 0;
+  int token;
+  YY_BUFFER_STATE buffer;
+
+  yy_delete_buffer(YY_CURRENT_BUFFER);
+  buffer = yy_scan_string(str);
+
+  if (state == STATE_NORMAL)
+    BEGIN(NORMAL);
+  else if (state == STATE_INITIAL)
+    BEGIN(INITIAL);
+  else if (state == STATE_EXPECT_TAG)
+    BEGIN(EXPECT_TAG);
+
+  /* Input is UTF-8 coming from the application, so bypass iconv */
+  dummy_conv = 1;
+  token = yylex();
+  if (token != check_token)
+    result = 1;
+  
+  if (token != 0) {
+    token = yylex();
+    if (token != 0)
+      result = 1;
+  }
+  dummy_conv = 0;
+  
+  yy_delete_buffer(buffer);
+  return result;
 }
 
 #ifdef LEXER_TEST