Handle tab character generated by PAF 5.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Mon, 27 Jan 2003 20:13:55 +0000 (20:13 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Mon, 27 Jan 2003 20:13:55 +0000 (20:13 +0000)
gedcom/compat.c
gedcom/compat.h
gedcom/gedcom_1byte.lex
gedcom/gedcom_hilo.lex
gedcom/gedcom_lex_common.c
gedcom/gedcom_lohi.lex

index 3b05680561597ee5ec0311282e409323a857b102..196113ffe1b576dd59ba476cb0ce3d22a42c02a1 100644 (file)
@@ -61,7 +61,8 @@ enum _COMPAT {
   C_PAF5         = 0x0004,
   C_PAF2         = 0x0008,
   C_FAMORIG      = 0x0010,
-  C_EASYTREE     = 0x0020
+  C_EASYTREE     = 0x0020,
+  C_PAF4         = 0x0040
 };
 
 struct program_data data[] = {
@@ -92,6 +93,7 @@ struct program_data data[] = {
         - '@' not written as '@@' in values
        - some 5.5.1 (draft) tags are used: EMAIL, FONE, ROMN
        - no FAMC field in SLGC
+       - uses tab character (will be converted to 8 spaces here)
 
     - Personal Ancestral File 2:
         - '@' not written as '@@' in values
@@ -107,6 +109,9 @@ struct program_data data[] = {
        - no submitter link in the header
        - NOTE doesn't have a value
        - NOTE.NOTE instead of NOTE.COND
+
+    - Personal Ancestral File 4:
+        - '@' not written as '@@' in values
  */
 
 int compat_matrix[] =
@@ -117,15 +122,17 @@ int compat_matrix[] =
   /* C_NO_GEDC */             C_LIFELINES | C_PAF2,
   /* C_NO_CHAR */             C_LIFELINES,
   /* C_HEAD_TIME */           C_LIFELINES,
-  /* C_NO_DOUBLE_AT */        C_LIFELINES | C_PAF5 | C_PAF2 | C_FAMORIG,
-  /* C_NO_REQUIRED_VALUES */  C_LIFELINES,
+  /* C_NO_DOUBLE_AT */        C_LIFELINES | C_PAF5 | C_PAF2 | C_FAMORIG
+                               | C_PAF4,
+  /* C_NO_REQUIRED_VALUES */  C_LIFELINES | C_PAF5,
   /* C_551_TAGS */            C_PAF5,
   /* C_NO_SLGC_FAMC */        C_PAF5,
   /* C_SUBM_COMM */           C_PAF2,
-  /* C_DOUBLE_DATES_4 */      C_PAF2,
+  /* C_DOUBLE_DATES_4 */      C_PAF2 | C_PAF5 | C_PAF4,
   /* C_CONC_NEEDS_SPACE */    C_FAMORIG,
   /* C_NO_GEDC_FORM */        C_EASYTREE,
-  /* C_NOTE_NOTE */           C_EASYTREE
+  /* C_NOTE_NOTE */           C_EASYTREE,
+  /* C_TAB_CHARACTER */       C_PAF5
 };
 
 int compat_state[C_NR_OF_RULES];
@@ -201,6 +208,10 @@ void compute_compatibility()
        compatibility = C_PAF2;
        version = 2;
       }
+      if (compatibility_version >= 40000 && compatibility_version < 50000) {
+       compatibility = C_PAF4;
+       version = 4;
+      }
       else if (compatibility_version >= 50000) {
        compatibility = C_PAF5;
        version = 5;
index b575469a7d5f435d16fc51ac462efea0a754e681..1d598228f2af73391ee20a161b490d60d8cace94 100644 (file)
@@ -43,6 +43,7 @@ typedef enum _COMPAT_RULES {
   C_CONC_NEEDS_SPACE,
   C_NO_GEDC_FORM,
   C_NOTE_NOTE,
+  C_TAB_CHARACTER,
   C_NR_OF_RULES
 } Compat_rule;
 
index 7c47f18a461a32c78f68e25c241965f336c56fea..69d6d15a4fccd4c847588063f97eaa49cf26dfbe 100644 (file)
@@ -214,6 +214,8 @@ ACTION_BEFORE_REGEXPS
 
 {normal_at}               ACTION_NORMAL_AT
 
+{tab}                     ACTION_TAB
+
 .                         ACTION_UNEXPECTED
 
 %%
index 91735f1e1c7eb6600463cee60d4f727b9cf0db6d..8d1997e524bdf45b06e9de49278e5ff770aeefd1 100644 (file)
@@ -217,6 +217,8 @@ ACTION_BEFORE_REGEXPS
 
 {normal_at}              ACTION_NORMAL_AT
 
+{tab}                    ACTION_TAB
+
 .                        ACTION_UNEXPECTED
 
 %%
index 68db840b4f645da43fcbd372fd474111bd95d99c..149a8a8bda9630855cb7fed8115ac38bd1fdfcec 100644 (file)
@@ -35,6 +35,7 @@ static size_t encoding_width;
 static int current_level = -1;
 static int level_diff=MAXGEDCLEVEL;
 static size_t line_len = 0;
+static int tab_space = 0;
 
 static struct conv_buffer* ptr_buffer = NULL;
 static struct conv_buffer* tag_buffer = NULL;
@@ -136,6 +137,11 @@ static void error_at_character()
   gedcom_error(_("'@' character should be written as '@@' in values"));
 }
 
+static void error_tab_character()
+{
+  gedcom_error(_("Tab character is not allowed in values"));
+}
+
 static void error_unexpected_character(const char* str, char ch)
 {
   gedcom_error(_("Unexpected character: '%s' (0x%02x)"), str, ch);
@@ -164,6 +170,12 @@ static int dummy_conv = 0;
     }                                                                         \
   }
 
+#define GENERATE_TAB_SPACE                                                    \
+  { gedcom_lval.string = " ";                                                 \
+    tab_space--;                                                              \
+    return DELIM;                                                             \
+  }
+
 #define MKTAGACTION(THETAG)                                                  \
   { CHECK_LINE_LEN;                                                          \
     gedcom_lval.tag.string = TO_INTERNAL(yytext, tag_buffer);                \
@@ -206,10 +218,16 @@ static int dummy_conv = 0;
 
    But because this means that one token is converted into a series
    of tokens, there is some initial code following immediately here
-   that returns "pending" tokens. */
+   that returns "pending" tokens.
+
+   Also, for compatibility tabs are converted into spaces, which is
+   also handled here */
 
 #define ACTION_BEFORE_REGEXPS                                                 \
-   { if (level_diff < 1) {                                                    \
+   { if (compat_mode(C_TAB_CHARACTER) && tab_space-- > 0) {                   \
+       GENERATE_TAB_SPACE;                                                    \
+     }                                                                        \
+     else if (level_diff < 1) {                                               \
        level_diff++;                                                          \
        return CLOSE;                                                          \
      }                                                                        \
@@ -383,6 +401,17 @@ static int dummy_conv = 0;
     }                                                                         \
   }
 
+#define ACTION_TAB                                                            \
+  { if (compat_mode(C_TAB_CHARACTER)) {                                       \
+      tab_space = 8;                                                          \
+      GENERATE_TAB_SPACE;                                                     \
+    }                                                                         \
+    else {                                                                    \
+      error_tab_character();                                                  \
+      return BADTOKEN;                                                        \
+    }                                                                         \
+  }
+
 #define ACTION_UNEXPECTED                                                     \
   { error_unexpected_character(yytext, yytext[0]);                            \
     return BADTOKEN;                                                          \
index 1678875433304b32ce7992b31faac16810571b1e..21f84eb95129ca29aa7ab670d7218bacac85785e 100644 (file)
@@ -217,6 +217,8 @@ ACTION_BEFORE_REGEXPS
 
 {normal_at}              ACTION_NORMAL_AT
 
+{tab}                    ACTION_TAB
+
 .                        ACTION_UNEXPECTED
 
 %%