X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fgedcom.y;h=9eadd4424ed5e7840effb35ac197d68fd22b882c;hb=6190c7618fa60d3827fe7414925a66c694ca2047;hp=4a131b04a6718da38792cdd6af3dbdad1a4395bb;hpb=809c37c2f87962cbb9fcb84c851d961e276fef72;p=gedcom-parse.git diff --git a/gedcom/gedcom.y b/gedcom/gedcom.y index 4a131b0..9eadd44 100644 --- a/gedcom/gedcom.y +++ b/gedcom/gedcom.y @@ -178,7 +178,7 @@ Gedcom_ctxt get_parentctxt(int offset); void pop_countarray(); int count_tag(int tag); int check_occurrence(int tag); -void clean_up(); +void clean_up(); #define HANDLE_ERROR \ { if (error_mechanism == IMMED_FAIL) { \ @@ -261,7 +261,7 @@ void clean_up(); } %token_table -%expect 308 +%expect 309 %token BADTOKEN %token OPEN @@ -496,7 +496,7 @@ head_sub : head_sour_sect { OCCUR2(SOUR, 1, 1) } /* HEAD.SOUR */ head_sour_sect : OPEN DELIM TAG_SOUR mand_line_item - { set_compatibility($4); + { set_compatibility_program($4); $$ = start_element(ELT_HEAD_SOUR, PARENT, $1, $3, $4, GEDCOM_MAKE_STRING(val1, $4)); @@ -505,7 +505,8 @@ head_sour_sect : OPEN DELIM TAG_SOUR mand_line_item head_sour_subs { CHECK0 } CLOSE - { end_element(ELT_HEAD_SOUR, PARENT, $5, + { compute_compatibility(); + end_element(ELT_HEAD_SOUR, PARENT, $5, GEDCOM_MAKE_NULL(val1)); } ; @@ -521,7 +522,8 @@ head_sour_sub : head_sour_vers_sect { OCCUR2(VERS, 0, 1) } ; head_sour_vers_sect : OPEN DELIM TAG_VERS mand_line_item - { $$ = start_element(ELT_HEAD_SOUR_VERS, PARENT, + { set_compatibility_version($4); + $$ = start_element(ELT_HEAD_SOUR_VERS, PARENT, $1, $3, $4, GEDCOM_MAKE_STRING(val1, $4)); START(VERS, $1, $$) @@ -644,6 +646,8 @@ head_date_sect : OPEN DELIM TAG_DATE mand_line_item $$ = start_element(ELT_HEAD_DATE, PARENT, $1, $3, $4, GEDCOM_MAKE_DATE(val1, dv)); + if (compat_mode(C_HEAD_TIME)) + compat_save_head_date_context($$); START(DATE, $1, $$) } head_date_subs @@ -677,9 +681,15 @@ head_date_time_sect : OPEN DELIM TAG_TIME mand_line_item ; /* HEAD.TIME (Only for compatibility) */ -/* Just ignore the time... */ -head_time_sect : OPEN DELIM TAG_TIME opt_line_item CLOSE - { gedcom_warning(_("Header change time lost in the compatibility")); +head_time_sect : OPEN DELIM TAG_TIME opt_line_item + { if (compat_mode(C_HEAD_TIME)) { + $$ = compat_generate_head_time_start($1, $3, $4); + } + } + CLOSE + { if (compat_mode (C_HEAD_TIME)) { + compat_generate_head_time_end($5); + } } ; @@ -753,7 +763,13 @@ head_gedc_sect : OPEN DELIM TAG_GEDC START(GEDC, $1, $$) } head_gedc_subs - { CHECK2(VERS, FORM) } + { if (compat_mode(C_NO_GEDC_FORM) && ! CHK_COND(FORM)) + compat_generate_gedcom_form($4); + else CHK(FORM); + + CHECK1(VERS) + } + CLOSE { end_element(ELT_HEAD_GEDC, PARENT, $4, GEDCOM_MAKE_NULL(val1)); @@ -1232,6 +1248,8 @@ indi_addr_sect : OPEN DELIM TAG_ADDR opt_line_item = start_element(ELT_SUB_ADDR, par, $1 + 1, $3, $4, GEDCOM_MAKE_NULL_OR_STRING(val2, $4)); + reset_buffer(&concat_buffer); + safe_buf_append(&concat_buffer, $4); START(ADDR, $1 + 1, $$); } else { START(ADDR, $1, NULL) } @@ -1241,8 +1259,9 @@ indi_addr_sect : OPEN DELIM TAG_ADDR opt_line_item CLOSE { if (compat_mode(C_INDI_ADDR)) { Gedcom_ctxt par = PARENT; + char* complete = get_buf_string(&concat_buffer); end_element(ELT_SUB_ADDR, par, $5, - GEDCOM_MAKE_NULL(val1)); + GEDCOM_MAKE_STRING(val1, complete)); CHECK0; compat_generate_resi_end(PARENT, par); } @@ -1418,7 +1437,7 @@ note_line_item : /* empty */ gedcom_error(_("Missing value")); YYERROR; } else { - $$ = ""; + $$ = VALUE_IF_MISSING; } } | DELIM line_item @@ -1434,9 +1453,32 @@ note_sub : continuation_sub /* 0:M */ | source_cit_sub /* 0:M */ | ident_struc_sub /* 0:1 */ | change_date_sub /* 0:1 */ + | note_note_sect { if (!compat_mode(C_NOTE_NOTE)) + INVALID_TAG("NOTE"); + } | no_std_sub ; +/* Same actions as cont_sect, for compatibility */ +note_note_sect : OPEN DELIM TAG_NOTE opt_line_item + { $3.string = "CONT"; + $3.value = TAG_CONT; + $$ = start_element(ELT_SUB_CONT, + PARENT, $1, $3, $4, + GEDCOM_MAKE_NULL_OR_STRING(val1, $4)); + SAFE_BUF_ADDCHAR(&concat_buffer, '\n'); + if (GEDCOM_IS_STRING(&val1)) + safe_buf_append(&concat_buffer, $4); + START(CONT, $1, $$) + } + no_std_subs + { CHECK0 } + CLOSE + { end_element(ELT_SUB_CONT, PARENT, $5, + GEDCOM_MAKE_NULL(val1)); + } + ; + /*********************************************************************/ /**** Repository record ****/ /*********************************************************************/ @@ -2276,12 +2318,13 @@ continuation_sub : cont_sect /* 0:M */ | conc_sect /* 0:M */ ; -cont_sect : OPEN DELIM TAG_CONT mand_line_item +cont_sect : OPEN DELIM TAG_CONT opt_line_item { $$ = start_element(ELT_SUB_CONT, PARENT, $1, $3, $4, - GEDCOM_MAKE_STRING(val1, $4)); + GEDCOM_MAKE_NULL_OR_STRING(val1, $4)); SAFE_BUF_ADDCHAR(&concat_buffer, '\n'); - safe_buf_append(&concat_buffer, $4); + if (GEDCOM_IS_STRING(&val1)) + safe_buf_append(&concat_buffer, $4); START(CONT, $1, $$) } no_std_subs @@ -2296,6 +2339,9 @@ conc_sect : OPEN DELIM TAG_CONC mand_line_item { $$ = start_element(ELT_SUB_CONC, PARENT, $1, $3, $4, GEDCOM_MAKE_STRING(val1, $4)); + if (compat_mode(C_CONC_NEEDS_SPACE)) { + safe_buf_append(&concat_buffer, " "); + } safe_buf_append(&concat_buffer, $4); START(CONC, $1, $$) } @@ -3678,6 +3724,11 @@ user_sect : OPEN DELIM opt_xref USERTAG && compat_check_551_tag($4.string, &usertag_buffer)) { $4.string = get_buf_string(&usertag_buffer); } + else if (compat_mode(C_SUBM_COMM) && + compat_check_subm_comm($4.string, get_parenttag(0), + &usertag_buffer)) { + $4.string = get_buf_string(&usertag_buffer); + } else { gedcom_error(_("Undefined tag (and not a valid user tag): %s"), $4); @@ -3694,11 +3745,21 @@ user_sect : OPEN DELIM opt_xref USERTAG CLOSE { end_element(ELT_USER, PARENT, $7, GEDCOM_MAKE_NULL(val1)); + if (compat_mode(C_SUBM_COMM)) + compat_close_subm_comm(); } ; user_sects : /* empty */ { } | user_sects user_sect { } + | user_sects gen_sect + { if (compat_mode(C_SUBM_COMM)) { + } + else { + gedcom_error(_("Standard tag not allowed in user section")); + YYERROR; + } + } ; opt_xref : /* empty */ { $$ = NULL; } @@ -3724,7 +3785,7 @@ mand_pointer : /* empty */ { gedcom_error(_("Missing pointer")); YYERROR; } mand_line_item : /* empty */ { if (compat_mode(C_NO_REQUIRED_VALUES)) { gedcom_debug_print("==Val: =="); - $$ = ""; + $$ = VALUE_IF_MISSING; } else { gedcom_error(_("Missing value")); YYERROR; @@ -3787,9 +3848,23 @@ error_sect : OPEN DELIM opt_xref anytag opt_value error_subs CLOSE { } ; gen_sect : OPEN DELIM opt_xref anystdtag - { INVALID_TAG($4.string); } - opt_value opt_sects CLOSE - { } + { if (compat_mode(C_SUBM_COMM) + && compat_check_subm_comm_cont($4.string)) { + /* Will pass here */ + } + else { + INVALID_TAG($4.string); + } + } + opt_value + { if (compat_mode(C_SUBM_COMM)) { + $$ = compat_subm_comm_cont_start(PARENT, $6); + } + } + opt_sects CLOSE + { if (compat_mode(C_SUBM_COMM)) + compat_subm_comm_cont_end(PARENT, $7); + } ; gen_rec : gen_rec_top @@ -3966,7 +4041,7 @@ Gedcom_ctxt ctxt_stack[MAXGEDCLEVEL+1]; void push_countarray(int level) { int *count = NULL; - gedcom_debug_print("Push Count level: %d, level: %d\n", count_level, level); + gedcom_debug_print("Push Count level: %d, level: %d", count_level, level); if (count_level != level + 1) { gedcom_error(_("Internal error: count level mismatch")); exit(1); @@ -3976,7 +4051,7 @@ void push_countarray(int level) exit(1); } else { - gedcom_debug_print("calloc countarray %d\n", count_level); + gedcom_debug_print("calloc countarray %d", count_level); count = (int *)calloc(YYNTOKENS, sizeof(int)); if (count == NULL) { gedcom_error(_("Internal error: count array calloc error")); @@ -4023,14 +4098,14 @@ int check_occurrence(int tag) void pop_countarray() { int *count; - gedcom_debug_print("Pop Count level: %d\n", count_level); + gedcom_debug_print("Pop Count level: %d", count_level); if (count_level < 0) { gedcom_error(_("Internal error: count array underflow")); exit(1); } else { count = count_arrays[count_level]; - gedcom_debug_print("free countarray %d\n", count_level); + gedcom_debug_print("free countarray %d", count_level); free(count); count_arrays[count_level] = NULL; } @@ -4038,7 +4113,7 @@ void pop_countarray() void clean_up() { - gedcom_debug_print("Cleanup countarrays\n"); + gedcom_debug_print("Cleanup countarrays"); while (count_level > 0) { pop_countarray(); --count_level;