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)
13 char string_buf[MAXGEDCLINELEN+1];
15 #define TO_INTERNAL(str) to_internal(str, yyleng)
17 #define MKTAGACTION(the_tag) \
18 { gedcom_lval.tag = TO_INTERNAL(yytext); \
20 return TAG_##the_tag; }
23 /* The GEDCOM level number is converted into a sequence of opening
24 and closing brackets. Simply put, the following GEDCOM fragment:
37 { SOUR genes (1 higher: no closing brackets)
38 { VERS 1.6 (1 higher: no closing brackets)
39 } { NAME Genes (same level: 1 closing bracket)
40 } } { DATE 07 OCT 2001 (1 lower: 2 closing brackets)
54 But because this means that one token is converted into a series
55 of tokens, there is some initial code following immediately here
56 that returns "pending" tokens. */
58 #define ACTION_BEFORE_REGEXPS \
59 { if (level_diff < 1) { \
63 else if (level_diff == 1) { \
65 gedcom_lval.level = current_level; \
69 /* out of brackets... */ \
74 #define ACTION_0_DIGITS \
75 { gedcom_error ("Level number with leading zero"); \
80 #define ACTION_DIGITS \
81 { int level = atoi(TO_INTERNAL(yytext)); \
82 if ((level < 0) || (level > MAXGEDCLEVEL)) { \
83 gedcom_error ("Level number out of range [0..%d]", \
87 level_diff = level - current_level; \
89 current_level = level; \
90 if (level_diff < 1) { \
94 else if (level_diff == 1) { \
96 gedcom_lval.level = current_level; \
100 /* should never happen (error to GEDCOM spec) */ \
101 gedcom_error ("GEDCOM level number is %d higher than " \
109 #define ACTION_ALPHANUM \
110 { if (strlen(yytext) > MAXGEDCTAGLEN) { \
111 gedcom_error("Tag '%s' too long, max %d chars"); \
114 strncpy(string_buf, yytext, MAXGEDCTAGLEN+1); \
115 gedcom_lval.tag = TO_INTERNAL(string_buf); \
121 #define ACTION_DELIM \
122 { gedcom_lval.string = TO_INTERNAL(yytext); \
128 { gedcom_lval.string = TO_INTERNAL(yytext); \
129 /* Due to character conversions, it is possible \
130 that the current character will be combined with \
131 the next, and so now we don't have a character yet... \
132 In principle, this is only applicable to the 1byte case (e.g. ANSEL), \
133 but it doesn't harm the unicode case. \
135 if (strlen(gedcom_lval.string) > 0) \
140 #define ACTION_ESCAPE \
141 { gedcom_lval.string = TO_INTERNAL(yytext); \
146 #define ACTION_POINTER \
147 { gedcom_lval.pointer = TO_INTERNAL(yytext); \
152 /* Due to the conversion of level numbers into brackets, the
153 terminator is not important, so no token is returned here.
154 Although not strictly according to the GEDCOM spec, we'll ignore
155 whitespace just before the terminator.
158 #define ACTION_TERMINATOR \
164 /* Eventually we have to return 1 closing bracket (for the trailer).
165 We can detect whether we have sent the closing bracket using the
166 level_diff (at eof, first it is 2, then we increment it ourselves)
170 { if (level_diff == 2) { \
180 #define ACTION_UNEXPECTED \
181 { gedcom_error("Unexpected character: '%s' (0x%02x)", \
182 yytext, yytext[0]); \