From: Peter Verthez Date: Tue, 14 Jan 2003 20:16:21 +0000 (+0000) Subject: Reworked compatibility computation to take program version into account. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=f38264a8dc9d6fbaa514e9f043adaa53c52191f4;p=gedcom-parse.git Reworked compatibility computation to take program version into account. --- diff --git a/gedcom/compat.c b/gedcom/compat.c index be9b3a1..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, @@ -89,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; @@ -102,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; } } diff --git a/gedcom/compat.h b/gedcom/compat.h index f5fc8f1..e5597c9 100644 --- a/gedcom/compat.h +++ b/gedcom/compat.h @@ -41,7 +41,9 @@ typedef enum _COMPAT_RULES { C_NR_OF_RULES } Compat_rule; -void set_compatibility(const char* program); +void set_compatibility_program(const char* program); +void set_compatibility_version(const char* version); +void compute_compatibility(); int compat_mode(Compat_rule rule); void compat_generate_submitter_link(Gedcom_ctxt parent); void compat_generate_submitter(); diff --git a/gedcom/gedcom.y b/gedcom/gedcom.y index 4a131b0..0564018 100644 --- a/gedcom/gedcom.y +++ b/gedcom/gedcom.y @@ -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, $$)