X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fcompat.c;h=c53465b609319744a7ed2ab63f4e051a7b94562d;hb=refs%2Fheads%2Flibiconv-gedcom-1.14;hp=3997fe695278d589e838a7f0e470125339b20f78;hpb=d2dbc2834cae06a5de0dec22c0e7a530b7dd1589;p=gedcom-parse.git diff --git a/gedcom/compat.c b/gedcom/compat.c index 3997fe6..c53465b 100644 --- a/gedcom/compat.c +++ b/gedcom/compat.c @@ -36,6 +36,14 @@ int compatibility_program = 0; int compatibility_version = 0; const char* default_charset = ""; +void cleanup_compat_buffer(); +struct safe_buffer compat_buffer = { NULL, 0, NULL, 0, cleanup_compat_buffer }; + +void cleanup_compat_buffer() +{ + cleanup_buffer(&compat_buffer); +} + #define SUBMITTER_LINK "@__COMPAT__SUBM__@" #define SLGC_FAMC_LINK "@__COMPAT__FAM_SLGC__@" #define DEFAULT_SUBMITTER_NAME "Submitter" @@ -96,13 +104,12 @@ struct program_data data[] = { - no FAMC field in SLGC - uses tab character (will be converted to 8 spaces here) - lines too long - - non-standard date formats + - double dates written as e.g. '1815/1816' - Personal Ancestral File 2: - '@' not written as '@@' in values - COMM tag in submitter record - - double dates written as e.g. '1815/1816' instead of '1815/16' - - non-standard date formats + - double dates written as e.g. '1815/1816' - Family Origins: - '@' not written as '@@' in values @@ -120,7 +127,7 @@ struct program_data data[] = { - '@' not written as '@@' in values - SUBM.CTRY instead of SUBM.ADDR.CTRY - lines too long - - non-standard date formats + - double dates written as e.g. '1815/1816' */ int compat_matrix[] = @@ -146,7 +153,6 @@ int compat_matrix[] = /* C_NOTE_TOO_LONG */ C_PAF4 | C_PAF5, /* C_NOTE_CONC_SOUR */ C_EASYTREE, /* C_NONSTD_SOUR_TAGS */ C_EASYTREE, - /* C_PAF_DATES */ C_PAF2 | C_PAF4 | C_PAF5 }; union _COMPAT_STATE { @@ -156,11 +162,22 @@ union _COMPAT_STATE { /* Compatibility handling */ +/** Allows to enable/disable the compatibility mode. + + \param enable_compat This argument can be: + - 0 Disable compatibility mode + - 1 Allow compatibility mode (this is the default) + */ void gedcom_set_compat_handling(int enable_compat) { compat_enabled = enable_compat; } +/** Allows to set some options for the compatibility handling. + + \param options Can be an OR'ed combination of the options listed defined + by the enum \ref Gedcom_compat. +*/ void gedcom_set_compat_options(Gedcom_compat options) { compat_options = options; @@ -269,6 +286,12 @@ int compat_mode(Compat_rule rule) return (compat_matrix[rule] & compatibility); } +void compat_close() +{ + compatibility_program = 0; + compatibility = 0; +} + /********************************************************************/ /* C_NO_SUBMITTER */ /********************************************************************/ @@ -639,6 +662,51 @@ void compat_subm_comm_cont_end(Gedcom_ctxt parent, Gedcom_ctxt self) } } +/********************************************************************/ +/* C_DOUBLE_DATES_4 */ +/********************************************************************/ + +void compat_date_start() +{ + if (compat_mode(C_DOUBLE_DATES_4)) { + reset_buffer(&compat_buffer); + compat_state[C_DOUBLE_DATES_4].i = 0; + } +} + +int compat_double_date_check(char* year2) +{ + return (compat_mode(C_DOUBLE_DATES_4) + && !compat_state[C_DOUBLE_DATES_4].i + && strlen(year2) == 4); +} + +int compat_double_date_final(struct date_value* dv, const char** curr_line) +{ + char* compat_line_value = get_buf_string(&compat_buffer); + compat_state[C_DOUBLE_DATES_4].i = 1; + if (compat_line_value && compat_line_value[0] + && (dv->type == DV_NO_MODIFIER || dv->type == DV_ABOUT) + && dv->date1.day == -1 + && dv->date1.month == -1) { + gedcom_warning(_("Converting '%s' to standard '%s'"), + *curr_line, compat_line_value); + *curr_line = compat_line_value; + } + return 1; +} + +int compat_date_check(struct date_value* dv, const char** curr_line) +{ + if (compat_mode(C_DOUBLE_DATES_4) + && compat_double_date_final(dv, curr_line)) { + return 1; + } + else { + return 0; + } +} + /********************************************************************/ /* C_NOTE_TOO_LONG */ /********************************************************************/