X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fgedcom_1byte.lex;h=7c47f18a461a32c78f68e25c241965f336c56fea;hb=31fb8432ef01f9d5a08cc801a785a07b4e9d12bd;hp=6fa1d6b0293089b3f4573f8482d7ecd1e1d6eb4e;hpb=e6cd9cd58e0e23f70e75b140d16354af665d7b43;p=gedcom-parse.git diff --git a/gedcom/gedcom_1byte.lex b/gedcom/gedcom_1byte.lex index 6fa1d6b..7c47f18 100644 --- a/gedcom/gedcom_1byte.lex +++ b/gedcom/gedcom_1byte.lex @@ -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,42 @@ 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); + + INIT_LINE_LEN; + 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