Reworked compatibility computation to take program version into account.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Tue, 14 Jan 2003 20:16:21 +0000 (20:16 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Tue, 14 Jan 2003 20:16:21 +0000 (20:16 +0000)
gedcom/compat.c
gedcom/compat.h
gedcom/gedcom.y

index be9b3a1ae4210546740cde88295f83435b9b3a76..cd85f044f064221cfbe2a40598d6a44a415499b0 100644 (file)
@@ -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;
   }
 }
 
index f5fc8f1e40174a34aaab0ccd49d289a2b5533a93..e5597c9390ac6b85fbbcb5c98eec0e644034f4ee 100644 (file)
@@ -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();
index 4a131b04a6718da38792cdd6af3dbdad1a4395bb..0564018e888f004ec6f70c99ece3ab97f543aaf1 100644 (file)
@@ -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);
                   $<ctxt>$ = 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, $<ctxt>5,
+                 { compute_compatibility();
+                  end_element(ELT_HEAD_SOUR, PARENT, $<ctxt>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
-                      { $<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>$)