Don't lose the HEAD.TIME section of Lifelines.
[gedcom-parse.git] / gedcom / gedcom.y
index f853e7d3b85c4160662bb898047c3e7ecf97bce4..9eadd4424ed5e7840effb35ac197d68fd22b882c 100644 (file)
@@ -178,7 +178,7 @@ Gedcom_ctxt get_parentctxt(int offset);
 void pop_countarray();
 int  count_tag(int tag);
 int  check_occurrence(int tag);
-void clean_up(); 
+void clean_up();
 
 #define HANDLE_ERROR                                                          \
      { if (error_mechanism == IMMED_FAIL) {                                   \
@@ -261,7 +261,7 @@ void clean_up();
 }
 
 %token_table
-%expect 308
+%expect 309
 
 %token <string> BADTOKEN
 %token <number> OPEN
@@ -646,6 +646,8 @@ head_date_sect : OPEN DELIM TAG_DATE mand_line_item
                   $<ctxt>$ = start_element(ELT_HEAD_DATE,
                                            PARENT, $1, $3, $4,
                                            GEDCOM_MAKE_DATE(val1, dv));
+                  if (compat_mode(C_HEAD_TIME))
+                    compat_save_head_date_context($<ctxt>$);
                   START(DATE, $1, $<ctxt>$)
                 }
                  head_date_subs
@@ -679,9 +681,15 @@ head_date_time_sect : OPEN DELIM TAG_TIME mand_line_item
                     ;
 
 /* HEAD.TIME (Only for compatibility) */
-/* Just ignore the time... */
-head_time_sect : OPEN DELIM TAG_TIME opt_line_item CLOSE
-                 { gedcom_warning(_("Header change time lost in the compatibility"));
+head_time_sect : OPEN DELIM TAG_TIME opt_line_item
+                 { if (compat_mode(C_HEAD_TIME)) {
+                    $<ctxt>$ = compat_generate_head_time_start($1, $3, $4);
+                   }
+                 }
+                 CLOSE
+                 { if (compat_mode (C_HEAD_TIME)) {
+                    compat_generate_head_time_end($<ctxt>5);
+                  }
                  }
               ;
 
@@ -755,7 +763,13 @@ head_gedc_sect : OPEN DELIM TAG_GEDC
                   START(GEDC, $1, $<ctxt>$)
                 }
                  head_gedc_subs
-                { CHECK2(VERS, FORM) }
+                { if (compat_mode(C_NO_GEDC_FORM) && ! CHK_COND(FORM))
+                    compat_generate_gedcom_form($<ctxt>4);
+                  else CHK(FORM);
+                
+                  CHECK1(VERS)  
+                }
+
                  CLOSE
                  { end_element(ELT_HEAD_GEDC, PARENT, $<ctxt>4,
                               GEDCOM_MAKE_NULL(val1));
@@ -1423,7 +1437,7 @@ note_line_item : /* empty */
                       gedcom_error(_("Missing value")); YYERROR;
                     }
                     else {
-                      $$ = "";
+                      $$ = VALUE_IF_MISSING;
                     }
                   }
                | DELIM line_item
@@ -1439,9 +1453,32 @@ note_sub    : continuation_sub  /* 0:M */
             | source_cit_sub  /* 0:M */
             | ident_struc_sub  /* 0:1 */
             | change_date_sub  /* 0:1 */
+            | note_note_sect  { if (!compat_mode(C_NOTE_NOTE))
+                                 INVALID_TAG("NOTE");
+                              }
             | no_std_sub
             ;
 
+/* Same actions as cont_sect, for compatibility */
+note_note_sect : OPEN DELIM TAG_NOTE opt_line_item
+            { $3.string = "CONT";
+             $3.value  = TAG_CONT;
+             $<ctxt>$ = start_element(ELT_SUB_CONT,
+                                      PARENT, $1, $3, $4, 
+                                      GEDCOM_MAKE_NULL_OR_STRING(val1, $4));
+             SAFE_BUF_ADDCHAR(&concat_buffer, '\n');
+             if (GEDCOM_IS_STRING(&val1))
+               safe_buf_append(&concat_buffer, $4);
+             START(CONT, $1, $<ctxt>$)  
+            }  
+            no_std_subs  
+            { CHECK0 }  
+            CLOSE  
+            { end_element(ELT_SUB_CONT, PARENT, $<ctxt>5,
+                         GEDCOM_MAKE_NULL(val1));
+           }
+            ;
+
 /*********************************************************************/
 /**** Repository record                                           ****/
 /*********************************************************************/
@@ -2281,19 +2318,13 @@ continuation_sub : cont_sect  /* 0:M */
                  | conc_sect  /* 0:M */
                  ;
 
-cont_sect : OPEN DELIM TAG_CONT mand_line_item 
+cont_sect : OPEN DELIM TAG_CONT opt_line_item 
             { $<ctxt>$ = start_element(ELT_SUB_CONT,
                                       PARENT, $1, $3, $4, 
-                                      GEDCOM_MAKE_STRING(val1, $4));
-             if (compat_mode(C_NOTE_NO_VALUE)) {
-               char* str = get_buf_string(&concat_buffer);
-               if (str[0] != '\0')
-                 SAFE_BUF_ADDCHAR(&concat_buffer, '\n');
-             }
-             else {
-               SAFE_BUF_ADDCHAR(&concat_buffer, '\n');
-             }
-             safe_buf_append(&concat_buffer, $4);
+                                      GEDCOM_MAKE_NULL_OR_STRING(val1, $4));
+             SAFE_BUF_ADDCHAR(&concat_buffer, '\n');
+             if (GEDCOM_IS_STRING(&val1))
+               safe_buf_append(&concat_buffer, $4);
              START(CONT, $1, $<ctxt>$)  
             }  
             no_std_subs  
@@ -2308,6 +2339,9 @@ conc_sect : OPEN DELIM TAG_CONC mand_line_item
             { $<ctxt>$ = start_element(ELT_SUB_CONC,
                                       PARENT, $1, $3, $4, 
                                       GEDCOM_MAKE_STRING(val1, $4));
+             if (compat_mode(C_CONC_NEEDS_SPACE)) {
+               safe_buf_append(&concat_buffer, " ");
+             }
              safe_buf_append(&concat_buffer, $4);
              START(CONC, $1, $<ctxt>$)  
             }  
@@ -3751,7 +3785,7 @@ mand_pointer : /* empty */ { gedcom_error(_("Missing pointer")); YYERROR; }
 mand_line_item : /* empty */
                  { if (compat_mode(C_NO_REQUIRED_VALUES)) {
                      gedcom_debug_print("==Val: ==");
-                    $$ = "";
+                    $$ = VALUE_IF_MISSING;
                   }
                   else {
                     gedcom_error(_("Missing value")); YYERROR;