1 /* This program is free software; you can redistribute it and/or modify *
2 * it under the terms of the GNU General Public License as published by *
3 * the Free Software Foundation; either version 2 of the License, or *
4 * (at your option) any later version. *
6 (C) 2001 by The Genes Development Team
7 Original author: Peter Verthez (Peter.Verthez@advalvas.be)
15 #include "gedcom.tab.h"
22 static int current_level=-1;
23 static int level_diff=MAXGEDCLEVEL;
31 int test_loop(ENCODING enc, char* code)
35 set_encoding_width(enc);
36 res = open_conv_to_internal(code);
38 gedcom_error("Unable to open conversion context: %s",
45 case BADTOKEN: printf("BADTOKEN "); break;
46 case OPEN: printf("OPEN(%d) ", gedcom_lval.level); break;
47 case CLOSE: printf("CLOSE "); break;
48 case ESCAPE: printf("ESCAPE(%s) ", gedcom_lval.string); break;
49 case DELIM: printf("DELIM "); break;
50 case ANYCHAR: printf("%s ", gedcom_lval.string); break;
51 case POINTER: printf("POINTER(%s) ", gedcom_lval.pointer); break;
52 case USERTAG: printf("USERTAG(%s) ", gedcom_lval.tag); break;
53 default: printf("TAG(%s) ", gedcom_lval.tag); break;
58 close_conv_to_internal();
62 #endif /* of #ifdef LEXER_TEST */
64 #else /* of #ifndef IN_LEX */
66 char string_buf[MAXGEDCLINELEN+1];
68 #define TO_INTERNAL(str) to_internal(str, yyleng)
70 #define MKTAGACTION(the_tag) \
71 { gedcom_lval.tag = TO_INTERNAL(yytext); \
73 return TAG_##the_tag; \
77 /* The GEDCOM level number is converted into a sequence of opening
78 and closing brackets. Simply put, the following GEDCOM fragment:
91 { SOUR genes (1 higher: no closing brackets)
92 { VERS 1.6 (1 higher: no closing brackets)
93 } { NAME Genes (same level: 1 closing bracket)
94 } } { DATE 07 OCT 2001 (1 lower: 2 closing brackets)
108 But because this means that one token is converted into a series
109 of tokens, there is some initial code following immediately here
110 that returns "pending" tokens. */
112 #define ACTION_BEFORE_REGEXPS \
113 { if (level_diff < 1) { \
117 else if (level_diff == 1) { \
119 gedcom_lval.level = current_level; \
123 /* out of brackets... */ \
128 #define ACTION_0_DIGITS \
129 { gedcom_error ("Level number with leading zero"); \
134 #define ACTION_DIGITS \
135 { int level = atoi(TO_INTERNAL(yytext)); \
136 if ((level < 0) || (level > MAXGEDCLEVEL)) { \
137 gedcom_error ("Level number out of range [0..%d]", \
141 level_diff = level - current_level; \
143 current_level = level; \
144 if (level_diff < 1) { \
148 else if (level_diff == 1) { \
150 gedcom_lval.level = current_level; \
154 /* should never happen (error to GEDCOM spec) */ \
155 gedcom_error ("GEDCOM level number is %d higher than " \
163 #define ACTION_ALPHANUM \
164 { if (strlen(yytext) > MAXGEDCTAGLEN) { \
165 gedcom_error("Tag '%s' too long, max %d chars"); \
168 strncpy(string_buf, yytext, MAXGEDCTAGLEN+1); \
169 gedcom_lval.tag = TO_INTERNAL(string_buf); \
175 #define ACTION_DELIM \
176 { gedcom_lval.string = TO_INTERNAL(yytext); \
182 { gedcom_lval.string = TO_INTERNAL(yytext); \
183 /* Due to character conversions, it is possible \
184 that the current character will be combined with \
185 the next, and so now we don't have a character yet... \
186 In principle, this is only applicable to the 1byte case (e.g. ANSEL), \
187 but it doesn't harm the unicode case. \
189 if (strlen(gedcom_lval.string) > 0) \
194 #define ACTION_ESCAPE \
195 { gedcom_lval.string = TO_INTERNAL(yytext); \
200 #define ACTION_POINTER \
201 { gedcom_lval.pointer = TO_INTERNAL(yytext); \
206 /* Due to the conversion of level numbers into brackets, the
207 terminator is not important, so no token is returned here.
208 Although not strictly according to the GEDCOM spec, we'll ignore
209 whitespace just before the terminator.
212 #define ACTION_TERMINATOR \
218 /* Eventually we have to return 1 closing bracket (for the trailer).
219 We can detect whether we have sent the closing bracket using the
220 level_diff (at eof, first it is 2, then we increment it ourselves)
224 { if (level_diff == 2) { \
234 #define ACTION_UNEXPECTED \
235 { gedcom_error("Unexpected character: '%s' (0x%02x)", \
236 yytext, yytext[0]); \