+2001-11-04 Peter Verthez <Peter.Verthez@advalvas.be>
+
+ * release 0.3
+
+ * Compatibility mode implemented.
+
2001-11-01 Peter Verthez <Peter.Verthez@advalvas.be>
* release 0.2
# $Id$
# $Name$
+CFLAGS=-Wall -pedantic
+
gedcom_parse: standalone.o lex.gedcom_.o gedcom.tab.o
cc standalone.o lex.gedcom_.o gedcom.tab.o -o gedcom_parse
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
-#define MAXGEDCOMLEVEL 99
+#define MAXGEDCLEVEL 99
+#define MAXGEDCLINELEN 256
+#define MAXGEDCTAGLEN 31
#define MAXSTDTAGLENGTH 4
#define GEDCOMTAGOFFSET 257
} MECHANISM;
int gedcom_error(char* s, ...);
+int gedcom_warning(char* s, ...);
+int gedcom_debug_print(char* s, ...);
void gedcom_enable_debug();
void gedcom_set_error_handling(MECHANISM mechanism);
+void gedcom_set_compat_handling(int enable_compat);
int gedcom_parse();
+int gedcom_lex();
extern int line_no;
%{
int current_level=-1;
-int level_diff=MAXGEDCOMLEVEL;
+int level_diff=MAXGEDCLEVEL;
int line_no=1;
%}
that returns "pending" tokens. */
%{
+char string_buf[MAXGEDCLINELEN+1];
+
if (level_diff < 1) {
level_diff++;
return CLOSE;
else {
/* out of brackets... */
}
-
-#define MKTAGACTION(tag) { gedcom_lval.string = gedcom_text; \
- BEGIN(NORMAL); \
- return TAG_##tag; }
+
+#define MKTAGACTION(tag) \
+ { gedcom_lval.string = gedcom_text; \
+ BEGIN(NORMAL); \
+ return TAG_##tag; }
+
%}
<INITIAL>{gen_delim}* /* ignore leading whitespace (also tabs) */
}
<INITIAL>{digit}+ { int level = atoi(gedcom_text);
- if ((level < 0) || (level > MAXGEDCOMLEVEL)) {
+ if ((level < 0) || (level > MAXGEDCLEVEL)) {
gedcom_error ("Level number out of range [0..%d]",
- MAXGEDCOMLEVEL);
+ MAXGEDCLEVEL);
return BADTOKEN;
}
level_diff = level - current_level;
<EXPECT_TAG>WIFE MKTAGACTION(WIFE)
<EXPECT_TAG>WILL MKTAGACTION(WILL)
-<EXPECT_TAG>{alphanum}+ { gedcom_lval.string = gedcom_text;
- BEGIN(NORMAL);
+<EXPECT_TAG>{alphanum}+ { if (strlen(gedcom_text) > MAXGEDCTAGLEN) {
+ gedcom_error("Tag '%s' too long, max %d chars");
+ return BADTOKEN;
+ }
+ strncpy(string_buf, gedcom_text, MAXGEDCTAGLEN+1);
+ gedcom_lval.string = string_buf;
+ BEGIN(NORMAL);
return USERTAG;
}
int main(int argc, char* argv[])
{
MECHANISM mech = IMMED_FAIL;
+ int compat_enabled = 1;
if (argc > 1) {
int i;
for (i=1; i<argc; i++) {
mech = DEFER_FAIL;
else if (!strncmp(argv[i], "-fn", 3))
mech = IGNORE_ERRORS;
+ else if (!strncmp(argv[i], "-nc", 3))
+ compat_enabled = 0;
else {
printf ("Unrecognized option: %s\n", argv[i]);
exit(1);
}
}
}
+ gedcom_set_compat_handling(compat_enabled);
gedcom_set_error_handling(mech);
if (gedcom_parse() == 0) {
printf("Parse succeeded\n");
+ return 0;
}
else {
printf("Parse failed\n");
+ return 1;
}
}
+int gedcom_debug_print(char* s, ...)
+{
+ int res;
+#if YYDEBUG != 0
+ if (gedcom_debug) {
+ va_list ap;
+ va_start(ap, s);
+ res = vfprintf(stderr, s, ap);
+ va_end(ap);
+ }
+#endif
+ return(res);
+}
+
+int gedcom_warning(char* s, ...)
+{
+ int res;
+ va_list ap;
+
+ va_start(ap, s);
+ fprintf(stderr, "Warning on line %d: ", line_no);
+ res = vfprintf(stderr, s, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+
+ return res;
+}
+
int gedcom_error(char* s, ...)
{
int res;