+/* This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+
+ (C) 2001 by The Genes Development Team
+ Original author: Peter Verthez (Peter.Verthez@advalvas.be)
+*/
+
/* $Id$ */
/* $Name$ */
/* General notes:
- - The syntax analysis doesn't handle the contents of the line values
- or their encoding; this is done in the semantic analysis.
+ - The syntax analysis doesn't handle the contents of the line values;
+ this is done in the semantic analysis.
*/
%{
#include "gedcom.h"
+#include "multilex.h"
+#include "encoding.h"
int count_level = 0;
int fail = 0;
int compat_enabled = 1;
+int gedcom_high_level_debug = 0;
int compatibility = 0;
-MECHANISM curr_mechanism=IMMED_FAIL;
-char string_buf[MAXGEDCLINELEN+1];
-char *string_buf_ptr;
+MECHANISM error_mechanism = IMMED_FAIL;
+
+char line_item_buf[MAXGEDCLINELEN * UTF_FACTOR + 1];
+char *line_item_buf_ptr;
enum _COMPAT {
C_FTREE = 0x01
#define HANDLE_ERROR \
{ \
- if (curr_mechanism == IMMED_FAIL) { \
+ if (error_mechanism == IMMED_FAIL) { \
YYABORT; \
} \
- else if (curr_mechanism == DEFER_FAIL) { \
+ else if (error_mechanism == DEFER_FAIL) { \
yyerrok; fail = 1; \
} \
- else if (curr_mechanism == IGNORE_ERRORS) { \
+ else if (error_mechanism == IGNORE_ERRORS) { \
yyerrok; \
} \
}
%}
%union {
+ int number;
char *string;
}
%expect 300
%token <string> BADTOKEN
-%token <string> OPEN
+%token <number> OPEN
%token <string> CLOSE
%token <string> ESCAPE
%token <string> DELIM
head_sect : OPEN DELIM TAG_HEAD
{ START(HEAD) }
head_subs
- { if (compat_mode(C_FTREE)) {
- CHECK3(SOUR, GEDC, CHAR);
- }
- else {
- CHECK4(SOUR, SUBM, GEDC, CHAR);
- }
- }
+ { if (compat_mode(C_FTREE))
+ CHECK3(SOUR, GEDC, CHAR)
+ else
+ CHECK4(SOUR, SUBM, GEDC, CHAR)
+ }
CLOSE { }
;
/* HEAD.SOUR */
head_sour_sect : OPEN DELIM TAG_SOUR mand_line_item
{ set_compatibility($4);
+ gedcom_debug_print("===Source: '%s', '%s'\n",
+ $4, $3);
START(SOUR)
}
head_sour_subs
head_sour_vers_sect : OPEN DELIM TAG_VERS mand_line_item
{ START(VERS)} no_std_subs { CHECK0 } CLOSE
- { }
+ { gedcom_debug_print("===Source version: '%s'\n", $4);
+ }
;
head_sour_name_sect : OPEN DELIM TAG_NAME mand_line_item
{ START(NAME) } no_std_subs { CHECK0 } CLOSE
- { }
+ { gedcom_debug_print("===Source name: '%s'\n", $4);
+ }
;
head_sour_corp_sect : OPEN DELIM TAG_CORP mand_line_item
- { START(CORP) }
+ { gedcom_debug_print("===Source corp name: '%s'\n", $4);
+ START(CORP) }
head_sour_corp_subs
{ CHECK0 }
CLOSE
/* HEAD.CHAR */
head_char_sect : OPEN DELIM TAG_CHAR mand_line_item
- { START(CHAR) }
+ { if (open_conv_to_internal($4) == 0) YYERROR;
+ START(CHAR) }
head_char_subs
{ CHECK0 }
CLOSE
| DELIM line_item { }
;
-line_item : anychar { CLEAR_BUFFER(string_buf);
- string_buf_ptr = string_buf;
+line_item : anychar { size_t i;
+ CLEAR_BUFFER(line_item_buf);
+ line_item_buf_ptr = line_item_buf;
/* The following also takes care of '@@' */
- *string_buf_ptr++ = $1[0];
- $$ = string_buf;
+ if (!strncmp($1, "@@", 3))
+ *line_item_buf_ptr++ = '@';
+ else
+ for (i=0; i < strlen($1); i++)
+ *line_item_buf_ptr++ = $1[i];
+ $$ = line_item_buf;
}
- | ESCAPE { CLEAR_BUFFER(string_buf);
- string_buf_ptr = string_buf;
+ | ESCAPE { CLEAR_BUFFER(line_item_buf);
+ line_item_buf_ptr = line_item_buf;
/* For now, ignore escapes */
- $$ = string_buf;
+ $$ = line_item_buf;
}
| line_item anychar
- { if (strlen(string_buf) >= MAXGEDCLINELEN) {
- gedcom_error("Line too long");
- YYERROR;
- }
- else {
- /* The following also takes care of '@@' */
- *string_buf_ptr++ = $2[0];
- $$ = string_buf;
- }
+ { size_t i;
+ /* The following also takes care of '@@' */
+ if (!strncmp($2, "@@", 3))
+ *line_item_buf_ptr++ = '@';
+ else
+ for (i=0; i < strlen($2); i++)
+ *line_item_buf_ptr++ = $2[i];
+ $$ = line_item_buf;
}
| line_item ESCAPE
{ /* For now, ignore escapes */
- $$ = string_buf;
+ $$ = line_item_buf;
}
;
/* Functions that handle the counting of subtags */
int* count_arrays[MAXGEDCLEVEL+1];
-char tag_stack[MAXGEDCLEVEL+1][MAXSTDTAGLENGTH+1];
+char tag_stack[MAXGEDCLEVEL+1][MAXSTDTAGLEN+1];
void push_countarray()
{
void set_parenttag(char* tag)
{
- strncpy(tag_stack[count_level], tag, MAXSTDTAGLENGTH+1);
+ strncpy(tag_stack[count_level], tag, MAXSTDTAGLEN+1);
}
char* get_parenttag()
}
/* Enabling debug mode */
-void gedcom_enable_debug()
+/* level 0: no debugging */
+/* level 1: only internal */
+/* level 2: also bison */
+void gedcom_set_debug_level(int level)
{
+ if (level > 0) {
+ gedcom_high_level_debug = 1;
+ }
+ if (level > 1) {
#if YYDEBUG != 0
- gedcom_debug = 1;
+ gedcom_debug = 1;
#endif
+ }
+}
+
+int gedcom_debug_print(char* s, ...)
+{
+ int res;
+ if (gedcom_high_level_debug) {
+ va_list ap;
+ va_start(ap, s);
+ res = vfprintf(stderr, s, ap);
+ va_end(ap);
+ }
+ return(res);
}
/* Setting the error mechanism */
void gedcom_set_error_handling(MECHANISM mechanism)
{
- curr_mechanism = mechanism;
+ error_mechanism = mechanism;
}
/* Compatibility handling */
{
return (compat_flags & compatibility);
}
+