Better separation of compatibility handling.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 4 Jan 2003 14:48:32 +0000 (14:48 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 4 Jan 2003 14:48:32 +0000 (14:48 +0000)
gedcom/compat.c
gedcom/compat.h
gedcom/gedcom.y
gedcom/gedcom_lex_common.c

index 507de09e6676b6ada5f306fa060081677fb1cd1a..8b5ed50f3e1e8dd414651ee64d7ac9a7282ee89b 100644 (file)
@@ -30,7 +30,6 @@
 
 int compat_enabled = 1;
 int compatibility  = 0; 
-int compat_at = 0;
 const char* default_charset = "";
 
 #define SUBMITTER_LINK         "@__COMPAT__SUBM__@"
@@ -38,6 +37,11 @@ const char* default_charset = "";
 #define DEFAULT_GEDCOM_VERS    "5.5"
 #define DEFAULT_GEDCOM_FORM    "LINEAGE-LINKED"
 
+enum _COMPAT {
+  C_FTREE = 0x01,
+  C_LIFELINES = 0x02
+};
+
 /* Incompatibility list (with GEDCOM 5.5):
 
     - ftree:
@@ -54,6 +58,18 @@ const char* default_charset = "";
        - 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)
@@ -64,7 +80,6 @@ void gedcom_set_compat_handling(int enable_compat)
 void set_compatibility(const char* program)
 {
   /* Reinitialize compatibility */
-  compat_at = 0;
   default_charset = "";
   compatibility = 0;
   
@@ -78,14 +93,13 @@ void set_compatibility(const char* program)
       gedcom_warning(_("Enabling compatibility with 'Lifelines'"));
       compatibility = C_LIFELINES;
       default_charset = "ANSI";
-      compat_at = 1;
     }
   }
 }
 
-int compat_mode(int compat_flags)
+int compat_mode(Compat_rule rule)
 {
-  return (compat_flags & compatibility);
+  return (compat_matrix[rule] & compatibility);
 }
 
 void compat_generate_submitter_link(Gedcom_ctxt parent)
index 31e7576e7c080d5eb912f71375a01730873e60a5..03971d1fd2ded377456aa10ee2ed553692e2b34f 100644 (file)
 
 #include "gedcom.h"
 
-extern int compat_at;
-
-enum _COMPAT {
-  C_FTREE = 0x01,
-  C_LIFELINES = 0x02
-};
+typedef enum _COMPAT_RULES {
+  C_NO_SUBMITTER,
+  C_INDI_ADDR,
+  C_NOTE_NO_VALUE,
+  C_NO_GEDC,
+  C_NO_CHAR,
+  C_HEAD_TIME,
+  C_NO_DOUBLE_AT,
+  C_NO_REQUIRED_VALUES
+} Compat_rule;
 
 void set_compatibility(const char* program);
-int  compat_mode(int flags); 
+int  compat_mode(Compat_rule rule); 
 void compat_generate_submitter_link(Gedcom_ctxt parent);
 void compat_generate_submitter();
 void compat_generate_gedcom(Gedcom_ctxt parent);
index 702d1256dcba2c8f921ce3074776e0bc1f2c91d0..3e3667c4d410cbee1c5f2b5fc13bf37b8adcd53c 100644 (file)
@@ -444,22 +444,24 @@ head_sect    : OPEN DELIM TAG_HEAD
                                         NULL, GEDCOM_MAKE_NULL(val2));
                 START(HEAD, $1, $<ctxt>$) }
                head_subs
-               { if (compat_mode(C_FTREE)) {
-                  CHECK3(SOUR, GEDC, CHAR);
-                  compat_generate_submitter_link($<ctxt>4);
-                }
-                else if (compat_mode(C_LIFELINES)) {
-                  CHECK1(SOUR);
+               { if (compat_mode(C_NO_SUBMITTER))
                   compat_generate_submitter_link($<ctxt>4);
+                else CHK(SUBM);
+
+                if (compat_mode(C_NO_GEDC))
                   compat_generate_gedcom($<ctxt>4);
+                else CHK(GEDC);
+
+                if (compat_mode(C_NO_CHAR)) {
                   if (compat_generate_char($<ctxt>4)) HANDLE_ERROR;
-                }
-                else
-                  CHECK4(SOUR, SUBM, GEDC, CHAR)
+                }
+                else CHK(CHAR);
+
+                CHECK1(SOUR);
               }
                CLOSE
                { end_record(REC_HEAD, $<ctxt>4, GEDCOM_MAKE_NULL(val1));
-                if (compat_mode(C_FTREE | C_LIFELINES))
+                if (compat_mode(C_NO_SUBMITTER))
                   compat_generate_submitter();
               }
              ;
@@ -471,7 +473,7 @@ head_subs    : /* empty */
 head_sub     : head_sour_sect  { OCCUR2(SOUR, 1, 1) }
              | head_dest_sect  { OCCUR2(DEST, 0, 1) }
              | head_date_sect  { OCCUR2(DATE, 0, 1) }
-             | head_time_sect  { if (!compat_mode(C_LIFELINES))
+             | head_time_sect  { if (!compat_mode(C_HEAD_TIME))
                                  INVALID_TAG("TIME");
                                 OCCUR2(TIME, 0, 1) }
              | head_subm_sect  { OCCUR2(SUBM, 1, 1) }
@@ -1074,7 +1076,7 @@ indi_sub    : indi_resn_sect  { OCCUR2(RESN, 0, 1) }
             | indi_afn_sect  /* 0:M */
             | ident_struc_sub  /* 0:1 */
             | change_date_sub  /* 0:1 */
-           | ftree_addr_sect { if (!compat_mode(C_FTREE))
+           | indi_addr_sect { if (!compat_mode(C_INDI_ADDR))
                                  INVALID_TAG("ADDR");
                              }
            | no_std_sub
@@ -1212,23 +1214,23 @@ indi_afn_sect  : OPEN DELIM TAG_AFN mand_line_item
                 }
                ;
 
-/* INDI.ADDR (Only for 'ftree' compatibility) */
-ftree_addr_sect : OPEN DELIM TAG_ADDR opt_line_item
-                  { if (compat_mode(C_FTREE)) {
+/* INDI.ADDR (Only for compatibility) */
+indi_addr_sect : OPEN DELIM TAG_ADDR opt_line_item
+                  { if (compat_mode(C_INDI_ADDR)) {
                      Gedcom_ctxt par = compat_generate_resi_start(PARENT);
                      START(RESI, $1, par);
                      $<ctxt>$
                        = start_element(ELT_SUB_ADDR,
                                        par, $1 + 1, $3, $4,
                                        GEDCOM_MAKE_NULL_OR_STRING(val2, $4));
-                     START(ADDR, $1, $<ctxt>$);
+                     START(ADDR, $1 + 1, $<ctxt>$);
                    }
                  else { START(ADDR, $1, NULL) }
                  }
                   ftree_addr_subs
                   { CHECK0 }
                   CLOSE
-                  { if (compat_mode(C_FTREE)) {
+                  { if (compat_mode(C_INDI_ADDR)) {
                      Gedcom_ctxt par = PARENT;
                      end_element(ELT_SUB_ADDR, par, $<ctxt>5,
                                  GEDCOM_MAKE_NULL(val1));
@@ -1403,7 +1405,7 @@ note_rec    : OPEN DELIM POINTER DELIM TAG_NOTE note_line_item
             ;
 
 note_line_item : /* empty */
-                   { if (!compat_mode(C_FTREE)) {
+                   { if (!compat_mode(C_NOTE_NO_VALUE)) {
                       gedcom_error(_("Missing value")); YYERROR;
                     }
                     else {
@@ -3695,7 +3697,7 @@ mand_pointer : /* empty */ { gedcom_error(_("Missing pointer")); YYERROR; }
              ;
 
 mand_line_item : /* empty */
-                 { if (compat_mode(C_LIFELINES)) {
+                 { if (compat_mode(C_NO_REQUIRED_VALUES)) {
                      /* Lifelines tends to not care about mandatory values */
                     gedcom_debug_print("==Val: ==");
                     $$ = "";
index f2fe44afeebf40290175267f3dedefdc4fc33a80..779af3bde742a0ab1366c89ecad485000d40b956 100644 (file)
@@ -46,7 +46,6 @@ static struct conv_buffer* str_buffer = NULL;
 #ifdef LEXER_TEST 
 YYSTYPE gedcom_lval;
 int line_no = 1;
-int compat_at = 0;
 
 int gedcom_lex();
 
@@ -361,7 +360,7 @@ static int dummy_conv = 0;
   } 
 
 #define ACTION_NORMAL_AT                                                      \
-  { if (compat_at) {                                                          \
+  { if (compat_mode(C_NO_DOUBLE_AT)) {                                        \
       int i, j;                                                               \
       char *yycopy = strdup(yytext);                                          \
       if (yycopy) {                                                           \