X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fcompat.c;h=cd85f044f064221cfbe2a40598d6a44a415499b0;hb=f38264a8dc9d6fbaa514e9f043adaa53c52191f4;hp=5bc93edfa078b348d63420d99cf9765da797c202;hpb=809c37c2f87962cbb9fcb84c851d961e276fef72;p=gedcom-parse.git diff --git a/gedcom/compat.c b/gedcom/compat.c index 5bc93ed..cd85f04 100644 --- a/gedcom/compat.c +++ b/gedcom/compat.c @@ -30,7 +30,9 @@ #include "gedcom.h" int compat_enabled = 1; -int compatibility = 0; +int compatibility = 0; +int compatibility_program = 0; +int compatibility_version = 0; const char* default_charset = ""; #define SUBMITTER_LINK "@__COMPAT__SUBM__@" @@ -39,6 +41,12 @@ const char* default_charset = ""; #define DEFAULT_GEDCOM_VERS "5.5" #define DEFAULT_GEDCOM_FORM "LINEAGE-LINKED" +enum _COMPAT_PROGRAM { + CP_FTREE = 1, + CP_LIFELINES, + CP_PAF +}; + enum _COMPAT { C_FTREE = 0x01, C_LIFELINES = 0x02, @@ -77,24 +85,10 @@ int compat_matrix[] = /* C_NO_DOUBLE_AT */ C_LIFELINES | C_PAF, /* C_NO_REQUIRED_VALUES */ C_LIFELINES, /* C_551_TAGS */ C_PAF, - /* C_NO_SLGC_FAMC */ C_PAF, - /* C_NR_OF_RULES */ 0 + /* C_NO_SLGC_FAMC */ C_PAF }; -int compat_state[] = -{ - /* C_NO_SUBMITTER */ 0, - /* C_INDI_ADDR */ 0, - /* C_NOTE_NO_VALUE */ 0, - /* C_NO_GEDC */ 0, - /* C_NO_CHAR */ 0, - /* C_HEAD_TIME */ 0, - /* C_NO_DOUBLE_AT */ 0, - /* C_NO_REQUIRED_VALUES */ 0, - /* C_551_TAGS */ 0, - /* C_NO_SLGC_FAMC */ 0, - /* C_NR_OF_RULES */ 0 -}; +int compat_state[C_NR_OF_RULES]; /* Compatibility handling */ @@ -103,12 +97,49 @@ void gedcom_set_compat_handling(int enable_compat) compat_enabled = enable_compat; } -void enable_compat_msg(const char* program_name) +void enable_compat_msg(const char* program_name, int version) +{ + if (version > 0) + gedcom_warning(_("Enabling compatibility with '%s', version %d"), + program_name, version); + else + gedcom_warning(_("Enabling compatibility with '%s'"), + program_name); +} + +void set_compatibility_program(const char* program) +{ + if (compat_enabled) { + if (! strncmp(program, "ftree", 6)) { + compatibility_program = CP_FTREE; + } + else if (! strncmp(program, "LIFELINES", 9)) { + compatibility_program = CP_LIFELINES; + if (strlen(program) > 10 && program[9] = ' ') + set_compatibility_version(program + 10); + } + else if (! strncmp(program, "PAF", 3)) { + compatibility_program = CP_PAF; + if (strlen(program) > 4 && program[3] = ' ') + set_compatibility_version(program + 4); + } + } +} + +void set_compatibility_version(const char* version) { - gedcom_warning(_("Enabling compatibility with '%s'"), program_name); + if (compat_enabled) { + unsigned int major=0, minor=0, patch=0; + int result; + + result = sscanf(version, "%u.%u.%u", &major, &minor, &patch); + if (result > 0) { + compatibility_version = major * 10000 + minor * 100 + patch; + } + } } -void set_compatibility(const char* program) +void compute_compatibility() { /* Reinitialize compatibility */ int i; @@ -116,22 +147,23 @@ void set_compatibility(const char* program) compatibility = 0; for (i = 0; i < C_NR_OF_RULES; i++) compat_state[i] = 0; - - if (compat_enabled) { - if (! strncmp(program, "ftree", 6)) { - enable_compat_msg("ftree"); + + switch (compatibility_program) { + case CP_FTREE: + enable_compat_msg("ftree", 0); compatibility = C_FTREE; - } - else if (! strncmp(program, "LIFELINES", 9)) { - /* Matches "LIFELINES 3.0.2" */ - enable_compat_msg("Lifelines"); + break; + case CP_LIFELINES: + enable_compat_msg("Lifelines", 0); compatibility = C_LIFELINES; default_charset = "ANSI"; - } - else if (! strncmp(program, "PAF", 4)) { - enable_compat_msg("Personal Ancestral File"); + break; + case CP_PAF: + enable_compat_msg("Personal Ancestral File", 0); compatibility = C_PAF; - } + break; + default: + break; } }