1 /* User record object in 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
27 #include "submission.h"
28 #include "submitter.h"
30 #include "individual.h"
31 #include "multimedia.h"
33 #include "repository.h"
38 #include "source_citation.h"
40 #include "multimedia_link.h"
41 #include "lds_event.h"
43 #include "change_date.h"
44 #include "personal_name.h"
45 #include "family_link.h"
46 #include "association.h"
47 #include "source_event.h"
48 #include "source_description.h"
52 #include "gom_internal.h"
54 struct user_rec* gom_first_user_rec = NULL;
56 Gedcom_ctxt user_rec_start(_REC_PARAMS_)
58 struct user_rec* user = NULL;
59 struct xref_value* xr = NULL;
60 Gom_ctxt result = NULL;
61 Gedcom_ctxt ctxt = NULL;
64 if (GEDCOM_IS_XREF_PTR(xref))
65 xr = GEDCOM_XREF_PTR(xref);
68 user = make_user_record(xr->string);
69 xr->object = (Gedcom_ctxt) user;
73 user = (struct user_rec*) ctxt;
77 user = make_user_record(NULL);
78 ctxt = (Gedcom_ctxt) user;
82 user->tag = strdup(tag);
87 else if (GEDCOM_IS_STRING(parsed_value)) {
88 user->str_value = strdup(GEDCOM_STRING(parsed_value));
89 if (!user->str_value) {
94 else if (GEDCOM_IS_XREF_PTR(parsed_value))
95 user->xref_value = GEDCOM_XREF_PTR(parsed_value);
98 result = MAKE_GOM_CTXT(rec, user_rec, ctxt);
101 return (Gedcom_ctxt)result;
104 GET_REC_BY_XREF(user_rec, XREF_USER, gom_get_user_rec_by_xref)
106 Gedcom_ctxt user_elt_start(_ELT_PARAMS_)
108 Gom_ctxt ctxt = (Gom_ctxt)parent;
109 Gom_ctxt result = NULL;
115 struct user_data *data
116 = (struct user_data *)malloc(sizeof(struct user_data));
121 memset (data, 0, sizeof(struct user_data));
124 data->tag = strdup(tag);
130 else if (GEDCOM_IS_STRING(parsed_value)) {
131 data->str_value = strdup(GEDCOM_STRING(parsed_value));
132 if (! data->str_value) {
135 free(data->str_value);
139 else if (GEDCOM_IS_XREF_PTR(parsed_value))
140 data->xref_value = GEDCOM_XREF_PTR(parsed_value);
143 switch (ctxt->obj_type) {
145 header_add_user_data(ctxt, data); break;
147 submission_add_user_data(ctxt, data); break;
149 submitter_add_user_data(ctxt, data); break;
151 family_add_user_data(ctxt, data); break;
153 individual_add_user_data(ctxt, data); break;
155 multimedia_add_user_data(ctxt, data); break;
157 note_add_user_data(ctxt, data); break;
159 repository_add_user_data(ctxt, data); break;
161 source_add_user_data(ctxt, data); break;
163 user_rec_add_user_data(ctxt, data); break;
165 address_add_user_data(ctxt, data); break;
167 event_add_user_data(ctxt, data); break;
169 place_add_user_data(ctxt, data); break;
170 case T_source_citation:
171 citation_add_user_data(ctxt, data); break;
173 note_sub_add_user_data(ctxt, data); break;
174 case T_multimedia_link:
175 multimedia_link_add_user_data(ctxt, data); break;
177 lds_event_add_user_data(ctxt, data); break;
178 case T_user_ref_number:
179 user_ref_add_user_data(ctxt, data); break;
181 change_date_add_user_data(ctxt, data); break;
182 case T_personal_name:
183 name_add_user_data(ctxt, data); break;
185 family_link_add_user_data(ctxt, data); break;
187 association_add_user_data(ctxt, data); break;
189 source_event_add_user_data(ctxt, data); break;
190 case T_source_description:
191 source_description_add_user_data(ctxt, data); break;
193 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
195 result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
200 return (Gedcom_ctxt)result;
203 void user_rec_subscribe()
205 gedcom_subscribe_to_record(REC_USER, user_rec_start, def_rec_end);
206 gedcom_subscribe_to_element(ELT_USER, user_elt_start, def_elt_end);
209 void user_rec_add_user_data(Gom_ctxt ctxt, struct user_data* data)
211 struct user_rec *obj = SAFE_CTXT_CAST(user_rec, ctxt);
213 LINK_CHAIN_ELT(user_data, obj->extra, data);
216 void user_data_cleanup(struct user_data* data)
219 SAFE_FREE(data->tag);
220 SAFE_FREE(data->str_value);
224 void user_rec_cleanup(struct user_rec* rec)
227 SAFE_FREE(rec->xrefstr);
229 SAFE_FREE(rec->str_value);
230 DESTROY_CHAIN_ELTS(user_data, rec->extra, user_data_cleanup);
234 void user_recs_cleanup()
236 DESTROY_CHAIN_ELTS(user_rec, gom_first_user_rec, user_rec_cleanup);
239 struct user_rec* gom_get_first_user_rec()
241 return gom_first_user_rec;
244 struct user_rec* make_user_record(const char* xrefstr)
246 struct user_rec* rec = NULL;
247 MAKE_CHAIN_ELT(user_rec, gom_first_user_rec, rec);
248 if (rec && xrefstr) {
249 rec->xrefstr = strdup(xrefstr);
250 if (! rec->xrefstr) MEMORY_ERROR;