Compatibility handling for ftree.
[gedcom-parse.git] / gedcom / compat.c
1 /* Compatibility handling for the GEDCOM parser.
2    Copyright (C) 2001, 2002 The Genes Development Team
3    This file is part of the Gedcom parser library.
4    Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
5
6    The Gedcom parser library is free software; you can redistribute it
7    and/or modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The Gedcom parser library is distributed in the hope that it will be
12    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the Gedcom parser library; if not, write to the
18    Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20
21 /* $Id$ */
22 /* $Name$ */
23
24 #include "compat.h"
25 #include "interface.h"
26 #include "xref.h"
27 #include "gedcom_internal.h"
28 #include "gedcom.h"
29
30 #define SUBMITTER_LINK "@__COMPAT__SUBM__@"
31 #define DEFAULT_SUBMITTER_NAME "Submitter"
32
33 /* Incompatibily list (with GEDCOM 5.5):
34
35     - ftree:
36         - no submitter record, no submitter link in the header
37         - INDI.ADDR instead of INDI.RESI.ADDR
38         - NOTE doesn't have a value
39
40  */
41
42 void compat_generate_submitter_link(Gedcom_ctxt parent)
43 {
44   struct xref_value *xr = gedcom_parse_xref(SUBMITTER_LINK, XREF_USED,
45                                             XREF_SUBM);
46   struct tag_struct ts;
47   Gedcom_ctxt self;
48   
49   ts.string = "SUBM";
50   ts.value  = TAG_SUBM;
51   self = start_element(ELT_HEAD_SUBM,
52                        parent, 1, ts, SUBMITTER_LINK,
53                        GEDCOM_MAKE_XREF_PTR(val1, xr));
54   end_element(ELT_HEAD_SUBM, parent, self, NULL);
55 }
56
57 void compat_generate_submitter()
58 {
59   struct xref_value *xr = gedcom_parse_xref(SUBMITTER_LINK, XREF_DEFINED,
60                                             XREF_SUBM);
61   struct tag_struct ts;
62   Gedcom_ctxt self1, self2;
63
64   /* first generate "0 SUBM" */
65   ts.string = "SUBM";
66   ts.value  = TAG_SUBM;
67   self1 = start_record(REC_SUBM, 0, GEDCOM_MAKE_XREF_PTR(val1, xr), ts,
68                        NULL, GEDCOM_MAKE_NULL(val2));
69
70   /* then generate "1 NAME ..." */
71   ts.string = "NAME";
72   ts.value  = TAG_NAME;
73   self2 = start_element(ELT_SUBM_NAME, self1, 1, ts, DEFAULT_SUBMITTER_NAME,
74                         GEDCOM_MAKE_STRING(val1, DEFAULT_SUBMITTER_NAME));
75
76   /* close "1 NAME ..." */
77   end_element(ELT_SUBM_NAME, self1, self2, NULL);
78
79   /* close "0 SUBM" */
80   end_record(REC_SUBM, self1);
81 }
82
83 Gedcom_ctxt compat_generate_resi_start(Gedcom_ctxt parent)
84 {
85   Gedcom_ctxt self;
86   struct tag_struct ts;
87
88   ts.string = "RESI";
89   ts.value  = TAG_RESI;
90   self = start_element(ELT_SUB_INDIV_RESI, parent, 1, ts, NULL,
91                        GEDCOM_MAKE_NULL(val1));
92   return self;
93 }
94
95 void compat_generate_resi_end(Gedcom_ctxt parent, Gedcom_ctxt self)
96 {
97   end_element(ELT_SUB_INDIV_RESI, parent, self, NULL);
98 }