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.
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.
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.
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
25 #include "interface.h"
28 #include "gedcom_internal.h"
31 int compat_enabled = 1;
32 int compatibility = 0;
34 const char* default_charset = "";
36 #define SUBMITTER_LINK "@__COMPAT__SUBM__@"
37 #define DEFAULT_SUBMITTER_NAME "Submitter"
38 #define DEFAULT_GEDCOM_VERS "5.5"
39 #define DEFAULT_GEDCOM_FORM "LINEAGE-LINKED"
41 /* Incompatibility list (with GEDCOM 5.5):
44 - no submitter record, no submitter link in the header
45 - INDI.ADDR instead of INDI.RESI.ADDR
46 - NOTE doesn't have a value
49 - no submitter record, no submitter link in the header
50 - no GEDC field in the header
51 - no CHAR field in the header
52 - HEAD.TIME instead of HEAD.DATE.TIME (will be ignored here)
53 - '@' not written as '@@' in values
54 - lots of missing required values
57 /* Compatibility handling */
59 void gedcom_set_compat_handling(int enable_compat)
61 compat_enabled = enable_compat;
64 void set_compatibility(const char* program)
66 /* Reinitialize compatibility */
72 if (! strncmp(program, "ftree", 6)) {
73 gedcom_warning(_("Enabling compatibility with 'ftree'"));
74 compatibility = C_FTREE;
76 else if (! strncmp(program, "LIFELINES", 9)) {
77 /* Matches "LIFELINES 3.0.2" */
78 gedcom_warning(_("Enabling compatibility with 'Lifelines'"));
79 compatibility = C_LIFELINES;
80 default_charset = "ANSI";
86 int compat_mode(int compat_flags)
88 return (compat_flags & compatibility);
91 void compat_generate_submitter_link(Gedcom_ctxt parent)
93 struct xref_value *xr = gedcom_parse_xref(SUBMITTER_LINK, XREF_USED,
100 self = start_element(ELT_HEAD_SUBM,
101 parent, 1, ts, SUBMITTER_LINK,
102 GEDCOM_MAKE_XREF_PTR(val1, xr));
103 end_element(ELT_HEAD_SUBM, parent, self, NULL);
106 void compat_generate_submitter()
108 struct xref_value *xr = gedcom_parse_xref(SUBMITTER_LINK, XREF_DEFINED,
110 struct tag_struct ts;
111 Gedcom_ctxt self1, self2;
113 /* first generate "0 SUBM" */
116 self1 = start_record(REC_SUBM, 0, GEDCOM_MAKE_XREF_PTR(val1, xr), ts,
117 NULL, GEDCOM_MAKE_NULL(val2));
119 /* then generate "1 NAME ..." */
122 self2 = start_element(ELT_SUBM_NAME, self1, 1, ts, DEFAULT_SUBMITTER_NAME,
123 GEDCOM_MAKE_STRING(val1, DEFAULT_SUBMITTER_NAME));
125 /* close "1 NAME ..." */
126 end_element(ELT_SUBM_NAME, self1, self2, NULL);
129 end_record(REC_SUBM, self1);
132 void compat_generate_gedcom(Gedcom_ctxt parent)
134 struct tag_struct ts;
135 Gedcom_ctxt self1, self2;
137 /* first generate "1 GEDC" */
140 self1 = start_element(ELT_HEAD_GEDC, parent, 1, ts, NULL,
141 GEDCOM_MAKE_NULL(val1));
143 /* then generate "2 VERS <DEFAULT_GEDC_VERS>" */
146 self2 = start_element(ELT_HEAD_GEDC_VERS, self1, 2, ts,
148 GEDCOM_MAKE_STRING(val1, DEFAULT_GEDCOM_VERS));
151 end_element(ELT_HEAD_GEDC_VERS, self1, self2, NULL);
153 /* then generate "2 FORM <DEFAULT_GEDCOM_FORM> */
156 self2 = start_element(ELT_HEAD_GEDC_FORM, self1, 2, ts,
158 GEDCOM_MAKE_STRING(val1, DEFAULT_GEDCOM_FORM));
161 end_element(ELT_HEAD_GEDC_FORM, self1, self2, NULL);
164 end_element(ELT_HEAD_GEDC, parent, self1, NULL);
167 int compat_generate_char(Gedcom_ctxt parent)
169 struct tag_struct ts;
173 /* first generate "1 CHAR <DEFAULT_CHAR>" */
177 /* Must strdup, because default_charset is const char */
178 charset = strdup(default_charset);
182 self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, charset,
183 GEDCOM_MAKE_STRING(val1, charset));
187 end_element(ELT_HEAD_CHAR, parent, self1, NULL);
189 if (open_conv_to_internal(default_charset) == 0)
195 Gedcom_ctxt compat_generate_resi_start(Gedcom_ctxt parent)
198 struct tag_struct ts;
202 self = start_element(ELT_SUB_INDIV_RESI, parent, 1, ts, NULL,
203 GEDCOM_MAKE_NULL(val1));
207 void compat_generate_resi_end(Gedcom_ctxt parent, Gedcom_ctxt self)
209 end_element(ELT_SUB_INDIV_RESI, parent, self, NULL);