1 /* Main file for building the gedcom object model.
2 Copyright (C) 2002 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2002.
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
29 #include "submitter.h"
30 #include "submission.h"
32 #include "individual.h"
33 #include "multimedia.h"
35 #include "repository.h"
41 #include "source_citation.h"
42 #include "multimedia_link.h"
44 #include "lds_event.h"
46 #include "change_date.h"
47 #include "personal_name.h"
48 #include "family_link.h"
49 #include "association.h"
50 #include "source_event.h"
51 #include "source_description.h"
53 #include "gom_internal.h"
55 void gom_default_callback (Gedcom_elt elt, Gedcom_ctxt parent, int level,
56 char* tag, char* raw_value, int parsed_tag);
63 individuals_cleanup();
64 multimedias_cleanup();
66 repositories_cleanup();
74 gedcom_set_default_callback(gom_default_callback);
76 submission_subscribe();
78 individual_subscribe();
79 multimedia_subscribe();
81 repository_subscribe();
83 submitter_subscribe();
91 multimedia_link_subscribe();
92 lds_event_subscribe();
94 change_date_subscribe();
96 family_link_subscribe();
97 association_subscribe();
98 source_event_subscribe();
99 source_description_subscribe();
101 if (atexit(gom_cleanup) != 0) {
102 gedcom_warning(_("Could not register gom cleanup function"));
108 int gom_parse_file(const char* file_name)
117 return gedcom_parse_file(file_name);
129 return gedcom_new_model();
132 int gom_write_file(const char* file_name, int *total_conv_fails)
134 Gedcom_write_hndl hndl;
137 hndl = gedcom_write_open(file_name);
139 result = write_header(hndl);
140 result |= write_submission(hndl);
141 result |= write_submitters(hndl);
142 result |= write_individuals(hndl);
143 result |= write_families(hndl);
144 result |= write_multimedia_recs(hndl);
145 result |= write_notes(hndl);
146 result |= write_repositories(hndl);
147 result |= write_sources(hndl);
148 result |= write_user_recs(hndl);
149 result |= gedcom_write_close(hndl, total_conv_fails);
155 int gom_write_xref_list(Gedcom_write_hndl hndl,
156 Gedcom_elt elt, int tag, int parent_rec_or_elt,
157 struct xref_list* val)
160 struct xref_list* xrl;
161 for (xrl = val; xrl; xrl = xrl->next) {
162 result |= gedcom_write_element_xref(hndl, elt, tag, parent_rec_or_elt,
168 Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr)
170 Gom_ctxt ctxt = (Gom_ctxt)malloc(sizeof(struct Gom_ctxt_struct));
174 ctxt->ctxt_type = ctxt_type;
175 ctxt->obj_type = obj_type;
176 ctxt->ctxt_ptr = ctxt_ptr;
181 void NULL_DESTROY(void* anything UNUSED)
185 void destroy_gom_ctxt(Gom_ctxt ctxt)
190 void gom_cast_error(const char* file, int line,
191 OBJ_TYPE expected, OBJ_TYPE found)
194 "Wrong gom ctxt cast at %s, line %d: expected %d, found %d\n",
195 file, line, expected, found);
199 void gom_mem_error(const char *filename, int line)
201 gedcom_error(_("Could not allocate memory at %s, %d"), filename, line);
204 void gom_xref_already_in_use(const char *xrefstr)
206 gedcom_error(_("Cross-reference key '%s' is already in use"), xrefstr);
209 void gom_unexpected_context(const char* file, int line, OBJ_TYPE found)
211 gedcom_warning(_("Internal error: Unexpected context at %s, line %d: %d"),
215 void gom_no_context(const char* file, int line)
217 gedcom_warning(_("Internal error: No context at %s, line %d"),
221 void gom_move_error(const char* type)
223 gedcom_warning(_("Could not move struct of type %s"), type);
226 void gom_find_error(const char* type)
228 gedcom_warning(_("Could not find struct of type %s in chain"), type);
231 void gom_default_callback (Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED,
232 int level, char* tag, char* raw_value,
233 int parsed_tag UNUSED)
235 gedcom_warning(_("Data loss in import: \"%d %s %s\""),
236 level, tag, raw_value);
239 void def_rec_end(Gedcom_rec rec UNUSED, Gedcom_ctxt self,
240 Gedcom_val parsed_value UNUSED)
242 Gom_ctxt ctxt = (Gom_ctxt)self;
243 destroy_gom_ctxt(ctxt);
246 void def_elt_end(Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED,
247 Gedcom_ctxt self, Gedcom_val parsed_value UNUSED)
249 Gom_ctxt ctxt = (Gom_ctxt)self;
250 destroy_gom_ctxt(ctxt);
253 void set_xref_type(struct xref_value* xr, const char *str)
255 if (!strcasecmp(str, "FAM"))
257 else if (!strcasecmp(str, "INDI"))
258 xr->type = XREF_INDI;
259 else if (!strcasecmp(str, "NOTE"))
260 xr->type = XREF_NOTE;
261 else if (!strcasecmp(str, "OBJE"))
262 xr->type = XREF_OBJE;
263 else if (!strcasecmp(str, "REPO"))
264 xr->type = XREF_REPO;
265 else if (!strcasecmp(str, "SOUR"))
266 xr->type = XREF_SOUR;
267 else if (!strcasecmp(str, "SUBM"))
268 xr->type = XREF_SUBM;
269 else if (!strcasecmp(str, "SUBN"))
270 xr->type = XREF_SUBN;