X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fcompat.c;h=8b5ed50f3e1e8dd414651ee64d7ac9a7282ee89b;hb=a6ae7b8ee65f561b8ba9b189cf3e9504831621da;hp=59e61d313e8ece4954693c2ab0f3fab32f529926;hpb=0a9103e26559e1501b6cf7dd7f8eb00ba50de1cb;p=gedcom-parse.git diff --git a/gedcom/compat.c b/gedcom/compat.c index 59e61d3..8b5ed50 100644 --- a/gedcom/compat.c +++ b/gedcom/compat.c @@ -28,17 +28,21 @@ #include "gedcom_internal.h" #include "gedcom.h" -int compat_at = 0; +int compat_enabled = 1; +int compatibility = 0; +const char* default_charset = ""; #define SUBMITTER_LINK "@__COMPAT__SUBM__@" #define DEFAULT_SUBMITTER_NAME "Submitter" #define DEFAULT_GEDCOM_VERS "5.5" #define DEFAULT_GEDCOM_FORM "LINEAGE-LINKED" -/* Make default character set ANSI, for all 'special characters' - typically used in non-compliant gedcom generators */ -#define DEFAULT_CHAR "ANSI" -/* Incompatibily list (with GEDCOM 5.5): +enum _COMPAT { + C_FTREE = 0x01, + C_LIFELINES = 0x02 +}; + +/* Incompatibility list (with GEDCOM 5.5): - ftree: - no submitter record, no submitter link in the header @@ -49,10 +53,55 @@ int compat_at = 0; - no submitter record, no submitter link in the header - no GEDC field in the header - no CHAR field in the header - - TIME field outside of DATE field in the header (will be ignored here) + - HEAD.TIME instead of HEAD.DATE.TIME (will be ignored here) - '@' not written as '@@' in values + - lots of missing required values */ +int compat_matrix[] = +{ + /* C_NO_SUBMITTER */ C_FTREE | C_LIFELINES, + /* C_INDI_ADDR */ C_FTREE, + /* C_NOTE_NO_VALUE */ C_FTREE, + /* C_NO_GEDC */ C_LIFELINES, + /* C_NO_CHAR */ C_LIFELINES, + /* C_HEAD_TIME */ C_LIFELINES, + /* C_NO_DOUBLE_AT */ C_LIFELINES, + /* C_NO_REQUIRED_VALUES */ C_LIFELINES +}; + +/* Compatibility handling */ + +void gedcom_set_compat_handling(int enable_compat) +{ + compat_enabled = enable_compat; +} + +void set_compatibility(const char* program) +{ + /* Reinitialize compatibility */ + default_charset = ""; + compatibility = 0; + + if (compat_enabled) { + if (! strncmp(program, "ftree", 6)) { + gedcom_warning(_("Enabling compatibility with 'ftree'")); + compatibility = C_FTREE; + } + else if (! strncmp(program, "LIFELINES", 9)) { + /* Matches "LIFELINES 3.0.2" */ + gedcom_warning(_("Enabling compatibility with 'Lifelines'")); + compatibility = C_LIFELINES; + default_charset = "ANSI"; + } + } +} + +int compat_mode(Compat_rule rule) +{ + return (compat_matrix[rule] & compatibility); +} + void compat_generate_submitter_link(Gedcom_ctxt parent) { struct xref_value *xr = gedcom_parse_xref(SUBMITTER_LINK, XREF_USED, @@ -91,7 +140,7 @@ void compat_generate_submitter() end_element(ELT_SUBM_NAME, self1, self2, NULL); /* close "0 SUBM" */ - end_record(REC_SUBM, self1); + end_record(REC_SUBM, self1, NULL); } void compat_generate_gedcom(Gedcom_ctxt parent) @@ -133,16 +182,25 @@ int compat_generate_char(Gedcom_ctxt parent) { struct tag_struct ts; Gedcom_ctxt self1; + char* charset; /* first generate "1 CHAR " */ ts.string = "CHAR"; ts.value = TAG_CHAR; - self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, DEFAULT_CHAR, - GEDCOM_MAKE_STRING(val1, DEFAULT_CHAR)); - - /* close "1 CHAR" */ - end_element(ELT_HEAD_CHAR, parent, self1, NULL); - if (open_conv_to_internal(DEFAULT_CHAR) == 0) + + /* Must strdup, because default_charset is const char */ + charset = strdup(default_charset); + if (! charset) + MEMORY_ERROR; + else { + self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, charset, + GEDCOM_MAKE_STRING(val1, charset)); + free(charset); + + /* close "1 CHAR" */ + end_element(ELT_HEAD_CHAR, parent, self1, NULL); + } + if (open_conv_to_internal(default_charset) == 0) return 1; else return 0;