#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__@"
#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,
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;
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;
}
}
/* HEAD.SOUR */
head_sour_sect : OPEN DELIM TAG_SOUR mand_line_item
- { set_compatibility($4);
+ { set_compatibility_program($4);
$<ctxt>$ = start_element(ELT_HEAD_SOUR, PARENT,
$1, $3, $4,
GEDCOM_MAKE_STRING(val1, $4));
head_sour_subs
{ CHECK0 }
CLOSE
- { end_element(ELT_HEAD_SOUR, PARENT, $<ctxt>5,
+ { compute_compatibility();
+ end_element(ELT_HEAD_SOUR, PARENT, $<ctxt>5,
GEDCOM_MAKE_NULL(val1)); }
;
;
head_sour_vers_sect : OPEN DELIM TAG_VERS mand_line_item
- { $<ctxt>$ = start_element(ELT_HEAD_SOUR_VERS, PARENT,
+ { set_compatibility_version($4);
+ $<ctxt>$ = start_element(ELT_HEAD_SOUR_VERS, PARENT,
$1, $3, $4,
GEDCOM_MAKE_STRING(val1, $4));
START(VERS, $1, $<ctxt>$)