From: Peter Verthez Date: Tue, 22 Jan 2002 18:55:05 +0000 (+0000) Subject: Compatibility handling for ftree. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=f0775fe0dbf452814ada20f660c796dc13c877d5;p=gedcom-parse.git Compatibility handling for ftree. --- diff --git a/ChangeLog b/ChangeLog index 30f8e7a..83afe3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-01-22 Peter Verthez + + * gedcom/gedcom.y, gedcom/compat.c, gedcom/compat.h: Added + compatibility handling for ftree. + 2002-01-20 Peter Verthez * release 0.14 diff --git a/README b/README index 735e071..0dee7b2 100644 --- 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 diff --git a/gedcom/Makefile.am b/gedcom/Makefile.am index fb1ac39..9ba1378 100644 --- a/gedcom/Makefile.am +++ b/gedcom/Makefile.am @@ -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 index 0000000..f18e1be --- /dev/null +++ b/gedcom/compat.c @@ -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 , 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 index 0000000..2bd454f --- /dev/null +++ b/gedcom/compat.h @@ -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 , 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 */ diff --git a/gedcom/gedcom.y b/gedcom/gedcom.y index 9e68494..ed3f303 100644 --- a/gedcom/gedcom.y +++ b/gedcom/gedcom.y @@ -147,6 +147,7 @@ #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, $$) } head_subs - { if (compat_mode(C_FTREE)) - CHECK3(SOUR, GEDC, CHAR) + { if (compat_mode(C_FTREE)) { + CHECK3(SOUR, GEDC, CHAR); + compat_generate_submitter_link($4); + } else CHECK4(SOUR, SUBM, GEDC, CHAR) } CLOSE - { end_record(REC_HEAD, $4); } + { end_record(REC_HEAD, $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); + $$ + = start_element(ELT_SUB_ADDR, + par, $1 + 1, $3, $4, + GEDCOM_MAKE_NULL_OR_STRING(val2, $4)); + START(ADDR, $$) + } + no_std_subs + { CHECK0 } + CLOSE + { Gedcom_ctxt par = PARENT; + end_element(ELT_SUB_ADDR, par, $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; } ; diff --git a/gedcom/interface.h b/gedcom/interface.h index 24a9e64..3d4422f 100644 --- a/gedcom/interface.h +++ b/gedcom/interface.h @@ -24,6 +24,7 @@ #ifndef __INTERFACE_H #define __INTERFACE_H +#include "gedcom_internal.h" #include "gedcom.h" Gedcom_ctxt start_record(Gedcom_rec rec,