Compatibility handling for ftree.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Tue, 22 Jan 2002 18:55:05 +0000 (18:55 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Tue, 22 Jan 2002 18:55:05 +0000 (18:55 +0000)
ChangeLog
README
gedcom/Makefile.am
gedcom/compat.c [new file with mode: 0644]
gedcom/compat.h [new file with mode: 0644]
gedcom/gedcom.y
gedcom/interface.h

index 30f8e7aa45f560ba2e8a154e2f05795f253f0c76..83afe3fe5a5887e710a84c2c858ef18f0c25e9d2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-01-22  Peter Verthez  <Peter.Verthez@advalvas.be>
+
+       * gedcom/gedcom.y, gedcom/compat.c, gedcom/compat.h: Added
+       compatibility handling for ftree.
+
 2002-01-20  Peter Verthez  <Peter.Verthez@advalvas.be>
 
        * release 0.14
diff --git a/README b/README
index 735e07174e2e6ab081ddb9ee023825e7192b7b93..0dee7b29f4c8b0a053bde87f38108569da5913c5 100644 (file)
--- a/README
+++ b/README
@@ -22,16 +22,15 @@ Its main features are:
 
  - specific parsing and checking of cross-references
 
- - provisions for "compatibility-mode" parsing, to allow for not-exactly-
-   standard syntaxes used by other genealogy programs (only the hooks are
-   in at the moment, not the actual compatibility)
+ - "compatibility-mode" parsing, to allow for not-exactly-standard syntaxes
+   used by other genealogy programs; currently, compatibility is added for:
+     - ftree
 
 NOTE:
  - NO BACKWARD COMPATIBILITY is guaranteed for 0.x releases !
 
 To do list:
  - specific parsing of other special values
- - C++ interface
  - compatibility with other genealogy programs
  - older/newer Gedcom standards ?
  - ...
@@ -42,7 +41,7 @@ or to the SourceForge project web site and summary page:
   http://sourceforge.net/projects/gedcom-parse
 
 Also, have a look at the 'Genes' program, from which this library is a
-spin-off, and which intends to use this library:
+spin-off, and which uses this library:
   http://genes.sourceforge.net
   http://sourceforge.net/projects/genes
 
index fb1ac396fb14c7ba025ec268163d8ef2cfc183a3..9ba13787c098505e5530e8f7bbb04825cece7aac 100644 (file)
@@ -24,7 +24,8 @@ libgedcom_la_SOURCES = lex.gedcom_1byte_.c \
                        interface.c \
                       date.c \
                       hash.c \
-                      xref.c
+                      xref.c \
+                      compat.c
 libgedcom_la_LDFLAGS = -version-info $(LIBVERSION)
 libgedcom_la_LIBADD  = calendar/libcalendar.la
 BUILT_SOURCES = lex.gedcom_1byte_.c \
@@ -41,7 +42,8 @@ noinst_HEADERS = encoding.h \
                 multilex.h \
                 date.h \
                 hash.h \
-                xref.h
+                xref.h \
+                compat.h
 EXTRA_DIST = gedcom.y \
             gedcom_date.y \
             gedcom_1byte.lex \
diff --git a/gedcom/compat.c b/gedcom/compat.c
new file mode 100644 (file)
index 0000000..f18e1be
--- /dev/null
@@ -0,0 +1,98 @@
+/* Compatibility handling for the GEDCOM parser.
+   Copyright (C) 2001, 2002 The Genes Development Team
+   This file is part of the Gedcom parser library.
+   Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
+
+   The Gedcom parser library is free software; you can redistribute it
+   and/or modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The Gedcom parser library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the Gedcom parser library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* $Id$ */
+/* $Name$ */
+
+#include "compat.h"
+#include "interface.h"
+#include "xref.h"
+#include "gedcom_internal.h"
+#include "gedcom.h"
+
+#define SUBMITTER_LINK "@__COMPAT__SUBM__@"
+#define DEFAULT_SUBMITTER_NAME "Submitter"
+
+/* Incompatibily list (with GEDCOM 5.5):
+
+    - ftree:
+        - no submitter record, no submitter link in the header
+       - INDI.ADDR instead of INDI.RESI.ADDR
+       - NOTE doesn't have a value
+
+ */
+
+void compat_generate_submitter_link(Gedcom_ctxt parent)
+{
+  struct xref_value *xr = gedcom_parse_xref(SUBMITTER_LINK, XREF_USED,
+                                           XREF_SUBM);
+  struct tag_struct ts;
+  Gedcom_ctxt self;
+  
+  ts.string = "SUBM";
+  ts.value  = TAG_SUBM;
+  self = start_element(ELT_HEAD_SUBM,
+                      parent, 1, ts, SUBMITTER_LINK,
+                      GEDCOM_MAKE_XREF_PTR(val1, xr));
+  end_element(ELT_HEAD_SUBM, parent, self, NULL);
+}
+
+void compat_generate_submitter()
+{
+  struct xref_value *xr = gedcom_parse_xref(SUBMITTER_LINK, XREF_DEFINED,
+                                           XREF_SUBM);
+  struct tag_struct ts;
+  Gedcom_ctxt self1, self2;
+
+  /* first generate "0 SUBM" */
+  ts.string = "SUBM";
+  ts.value  = TAG_SUBM;
+  self1 = start_record(REC_SUBM, 0, GEDCOM_MAKE_XREF_PTR(val1, xr), ts,
+                      NULL, GEDCOM_MAKE_NULL(val2));
+
+  /* then generate "1 NAME ..." */
+  ts.string = "NAME";
+  ts.value  = TAG_NAME;
+  self2 = start_element(ELT_SUBM_NAME, self1, 1, ts, DEFAULT_SUBMITTER_NAME,
+                       GEDCOM_MAKE_STRING(val1, DEFAULT_SUBMITTER_NAME));
+
+  /* close "1 NAME ..." */
+  end_element(ELT_SUBM_NAME, self1, self2, NULL);
+
+  /* close "0 SUBM" */
+  end_record(REC_SUBM, self1);
+}
+
+Gedcom_ctxt compat_generate_resi_start(Gedcom_ctxt parent)
+{
+  Gedcom_ctxt self;
+  struct tag_struct ts;
+
+  ts.string = "RESI";
+  ts.value  = TAG_RESI;
+  self = start_element(ELT_SUB_INDIV_RESI, parent, 1, ts, NULL,
+                      GEDCOM_MAKE_NULL(val1));
+  return self;
+}
+
+void compat_generate_resi_end(Gedcom_ctxt parent, Gedcom_ctxt self)
+{
+  end_element(ELT_SUB_INDIV_RESI, parent, self, NULL);
+}
diff --git a/gedcom/compat.h b/gedcom/compat.h
new file mode 100644 (file)
index 0000000..2bd454f
--- /dev/null
@@ -0,0 +1,34 @@
+/* Header for compatibility handling for the GEDCOM parser.
+   Copyright (C) 2001, 2002 The Genes Development Team
+   This file is part of the Gedcom parser library.
+   Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
+
+   The Gedcom parser library is free software; you can redistribute it
+   and/or modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The Gedcom parser library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the Gedcom parser library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* $Id$ */
+/* $Name$ */
+
+#ifndef __COMPAT_H
+#define __COMPAT_H
+
+#include "gedcom.h"
+
+void compat_generate_submitter_link(Gedcom_ctxt parent);
+void compat_generate_submitter();
+Gedcom_ctxt compat_generate_resi_start(Gedcom_ctxt parent);
+void compat_generate_resi_end(Gedcom_ctxt parent, Gedcom_ctxt self);
+
+#endif /* __COMPAT_H */
index 9e684944d62578147c8f152e7c2d8751cd06ecd3..ed3f3033e57cf049c137b40ba7d26f5bac9b337c 100644 (file)
 #include "interface.h"
 #include "date.h"
 #include "xref.h"
+#include "compat.h"
 
 int  count_level    = 0;
 int  fail           = 0;
@@ -211,7 +212,7 @@ int  compat_mode(int flags);
                      #TAG, parenttag);                                       \
          HANDLE_ERROR;                                                        \
        }                                                                      \
-     }
+     } 
 #define POP                                                                   \
      { pop_countarray();                                                      \
        --count_level;                                                         \
@@ -443,13 +444,18 @@ head_sect    : OPEN DELIM TAG_HEAD
                                         NULL, GEDCOM_MAKE_NULL(val2));
                 START(HEAD, $<ctxt>$) }
                head_subs
-               { if (compat_mode(C_FTREE))
-                  CHECK3(SOUR, GEDC, CHAR)
+               { if (compat_mode(C_FTREE)) {
+                  CHECK3(SOUR, GEDC, CHAR);
+                  compat_generate_submitter_link($<ctxt>4);
+                }
                 else
                   CHECK4(SOUR, SUBM, GEDC, CHAR)
               }
                CLOSE
-               { end_record(REC_HEAD, $<ctxt>4); }
+               { end_record(REC_HEAD, $<ctxt>4);
+                if (compat_mode(C_FTREE))
+                  compat_generate_submitter();
+              }
              ;
 
 head_subs    : /* empty */
@@ -1166,7 +1172,22 @@ 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
-                  { START(ADDR, NULL) } no_std_subs { CHECK0 } CLOSE { }
+                  { Gedcom_ctxt par = compat_generate_resi_start(PARENT);
+                   START(RESI, par);
+                   $<ctxt>$
+                     = start_element(ELT_SUB_ADDR,
+                                     par, $1 + 1, $3, $4,
+                                     GEDCOM_MAKE_NULL_OR_STRING(val2, $4));
+                   START(ADDR, $<ctxt>$)
+                 }
+                  no_std_subs
+                  { CHECK0 }
+                  CLOSE
+                  { Gedcom_ctxt par = PARENT;
+                   end_element(ELT_SUB_ADDR, par, $<ctxt>5, NULL);
+                   CHECK0;
+                   compat_generate_resi_end(PARENT, par);
+                 }
 
 /*********************************************************************/
 /**** Multimedia record                                           ****/
@@ -1746,7 +1767,7 @@ subm_subs  : /* empty */
            | subm_subs subm_sub
            ;
 
-subm_sub   : subm_name_sect  { OCCUR2(NAME, 0, 1) }
+subm_sub   : subm_name_sect  { OCCUR2(NAME, 1, 1) }
            | addr_struc_sub  /* 0:1 */
            | multim_link_sub  /* 0:M */
            | subm_lang_sect  { OCCUR2(LANG, 0, 3) }
@@ -3496,7 +3517,7 @@ mand_line_item : /* empty */ { gedcom_error(_("Missing value")); YYERROR; }
                                    $$ = $2; }
                ;
 
-opt_line_item : /* empty */ { }
+opt_line_item : /* empty */     { $$ = NULL; }
               | DELIM line_item { gedcom_debug_print("==Val: %s==", $2);
                                  $$ = $2; }
               ;
index 24a9e6475ca1ba2b2a0c2e7732927bb7124f9d5a..3d4422fa253d5fa69ce1a1d1345c0f600ec2a5c2 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef __INTERFACE_H
 #define __INTERFACE_H
 
+#include "gedcom_internal.h"
 #include "gedcom.h"
 
 Gedcom_ctxt start_record(Gedcom_rec rec,