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();
72 int gom_parse_file(const char* file_name)
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"));
104 return gedcom_parse_file(file_name);
107 Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr)
109 Gom_ctxt ctxt = (Gom_ctxt)malloc(sizeof(struct Gom_ctxt_struct));
113 ctxt->ctxt_type = ctxt_type;
114 ctxt->obj_type = obj_type;
115 ctxt->ctxt_ptr = ctxt_ptr;
120 void NULL_DESTROY(void* anything)
124 void destroy_gom_ctxt(Gom_ctxt ctxt)
129 void gom_cast_error(const char* file, int line,
130 OBJ_TYPE expected, OBJ_TYPE found)
133 "Wrong gom ctxt cast at %s, line %d: expected %d, found %d\n",
134 file, line, expected, found);
138 void gom_mem_error(const char *filename, int line)
140 gedcom_error(_("Could not allocate memory at %s, %d"), filename, line);
143 void gom_unexpected_context(const char* file, int line, OBJ_TYPE found)
145 gedcom_warning(_("Internal error: Unexpected context at %s, line %d: %d"),
149 void gom_no_context(const char* file, int line)
151 gedcom_warning(_("Internal error: No context at %s, line %d"),
155 void gom_default_callback (Gedcom_elt elt, Gedcom_ctxt parent, int level,
156 char* tag, char* raw_value, int parsed_tag)
158 gedcom_warning(_("Data loss in import: \"%d %s %s\""),
159 level, tag, raw_value);
162 void def_rec_end(Gedcom_rec rec, Gedcom_ctxt self)
164 Gom_ctxt ctxt = (Gom_ctxt)self;
165 destroy_gom_ctxt(ctxt);
168 void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
169 Gedcom_val parsed_value)
171 Gom_ctxt ctxt = (Gom_ctxt)self;
172 destroy_gom_ctxt(ctxt);
175 void set_xref_type(struct xref_value* xr, const char *str)
177 if (!strcasecmp(str, "FAM"))
179 else if (!strcasecmp(str, "INDI"))
180 xr->type = XREF_INDI;
181 else if (!strcasecmp(str, "NOTE"))
182 xr->type = XREF_NOTE;
183 else if (!strcasecmp(str, "OBJE"))
184 xr->type = XREF_OBJE;
185 else if (!strcasecmp(str, "REPO"))
186 xr->type = XREF_REPO;
187 else if (!strcasecmp(str, "SOUR"))
188 xr->type = XREF_SOUR;
189 else if (!strcasecmp(str, "SUBM"))
190 xr->type = XREF_SUBM;
191 else if (!strcasecmp(str, "SUBN"))
192 xr->type = XREF_SUBN;
197 char* concat_strings(NL_TYPE type, char *str1, const char *str2)
199 if (str1 != NULL && str2 != NULL) {
202 size_t len1 = strlen(str1);
203 size_t len2 = strlen(str2);
204 size_t len = len1 + len2 + 1;
207 newp = (char*) realloc(str1, len);
214 wp = memcpy (wp, str2, len2);
222 struct date_value* dup_date(struct date_value dv)
224 struct date_value* dv_ptr;
225 dv_ptr = (struct date_value*) malloc(sizeof(struct date_value));
229 memcpy(dv_ptr, &dv, sizeof(struct date_value));
234 struct age_value* dup_age(struct age_value age)
236 struct age_value* age_ptr;
237 age_ptr = (struct age_value*) malloc(sizeof(struct age_value));
241 memcpy(age_ptr, &age, sizeof(struct age_value));