X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fgedcom_lex_common.c;h=109da8a1c33035ca9d26197fca562e45267c8ba3;hb=44bfd161d5274ff6a39f3640d745b9bbabe715ad;hp=6f7a1d3ca15252879dee6aa4259a55795727ad74;hpb=4e81582268d1fe7a45df84fa8b136279f59cb63e;p=gedcom-parse.git diff --git a/gedcom/gedcom_lex_common.c b/gedcom/gedcom_lex_common.c index 6f7a1d3..109da8a 100644 --- a/gedcom/gedcom_lex_common.c +++ b/gedcom/gedcom_lex_common.c @@ -27,9 +27,8 @@ #include "multilex.h" #include "encoding.h" #include "gedcom.h" -#include "gedcom.tab.h" - -#define YY_NO_UNPUT +#include "gedcom.tabgen.h" +#include "compat.h" static size_t encoding_width; static int current_level = -1; @@ -43,6 +42,7 @@ static char str_buf[MAXGEDCLINELEN * UTF_FACTOR + 1]; #ifdef LEXER_TEST YYSTYPE gedcom_lval; int line_no = 1; +int compat_at = 0; int gedcom_lex(); @@ -227,16 +227,26 @@ int test_loop(ENCODING enc, char* code) #define ACTION_ANY \ - { CHECK_LINE_LEN; \ - gedcom_lval.string = TO_INTERNAL(yytext, str_buf); \ - /* Due to character conversions, it is possible that the current \ - character will be combined with the next, and so now we don't have a \ - character yet... \ - In principle, this is only applicable to the 1byte case (e.g. ANSEL), \ - but it doesn't harm the unicode case. \ - */ \ - if (strlen(gedcom_lval.string) > 0) \ - return ANYCHAR; \ + { char* tmp; \ + CHECK_LINE_LEN; \ + tmp = TO_INTERNAL(yytext, str_buf); \ + if (!tmp) { \ + /* Something went wrong during conversion... */ \ + gedcom_error(_("Invalid character for encoding: '%s' (0x%02x)"), \ + yytext, yytext[0]); \ + return BADTOKEN; \ + } \ + else { \ + gedcom_lval.string = tmp; \ + /* Due to character conversions, it is possible that the current \ + character will be combined with the next, and so now we don't have a \ + character yet... \ + In principle, this is only applicable to the 1byte case (e.g. ANSEL),\ + but it doesn't harm the unicode case. \ + */ \ + if (strlen(gedcom_lval.string) > 0) \ + return ANYCHAR; \ + } \ } @@ -296,6 +306,20 @@ int test_loop(ENCODING enc, char* code) } \ } +#define ACTION_NORMAL_AT \ + { if (compat_at) { \ + int i, j; \ + char *yycopy = strdup(yytext); \ + for (i = 0; i < 2; i++) \ + for (j = yyleng - 1; j >= 0; --j) \ + unput(yycopy[j]); \ + free(yycopy); \ + } \ + else { \ + gedcom_error(_("'@' character should be written as '@@' in values")); \ + return BADTOKEN; \ + } \ + } #define ACTION_UNEXPECTED \ { gedcom_error(_("Unexpected character: '%s' (0x%02x)"), \