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 = MAKEFUNC(user_rec)(xr->string);
69 xr->object = (Gedcom_ctxt) user;
73 user = (struct user_rec*) ctxt;
77 user = MAKEFUNC(user_rec)(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 DEFINE_DESTROYFUNC(user_rec, gom_first_user_rec)
105 DEFINE_DELETEFUNC(user_rec)
106 DEFINE_GETXREFFUNC(user_rec, XREF_USER)
108 DEFINE_ADDFUNC2(user_rec, user_data, extra)
110 /* Specific function, because xrefstr not mandatory here */
111 struct user_rec* MAKEFUNC(user_rec)(const char* xrefstr)
113 struct user_rec* rec = NULL;
114 MAKE_CHAIN_ELT(user_rec, gom_first_user_rec, rec);
115 if (rec && xrefstr) {
116 rec->xrefstr = strdup(xrefstr);
117 if (! rec->xrefstr) MEMORY_ERROR;
122 struct user_rec* ADDFUNC(user_rec)(const char* xrefstr, const char* tag)
124 struct user_rec *obj = NULL;
125 struct xref_value* xrv = gedcom_get_by_xref(xrefstr);
126 if (tag && tag[0] == '_') {
128 gom_xref_already_in_use(xrefstr);
130 obj = MAKEFUNC(user_rec)(xrefstr);
132 obj->tag = strdup(tag);
136 xrv = gedcom_add_xref(XREF_USER, xrefstr, (Gedcom_ctxt)obj);
138 DESTROYFUNC(user_rec)(obj);
147 Gedcom_ctxt user_elt_start(_ELT_PARAMS_)
149 Gom_ctxt ctxt = (Gom_ctxt)parent;
150 Gom_ctxt result = NULL;
156 struct user_data *data
157 = (struct user_data *)malloc(sizeof(struct user_data));
162 memset (data, 0, sizeof(struct user_data));
165 data->tag = strdup(tag);
171 else if (GEDCOM_IS_STRING(parsed_value)) {
172 data->str_value = strdup(GEDCOM_STRING(parsed_value));
173 if (! data->str_value) {
176 free(data->str_value);
180 else if (GEDCOM_IS_XREF_PTR(parsed_value))
181 data->xref_value = GEDCOM_XREF_PTR(parsed_value);
184 switch (ctxt->obj_type) {
186 ADDFUNC2(header,user_data)(ctxt, data); break;
188 ADDFUNC2(submission,user_data)(ctxt, data); break;
190 ADDFUNC2(submitter,user_data)(ctxt, data); break;
192 ADDFUNC2(family,user_data)(ctxt, data); break;
194 ADDFUNC2(individual,user_data)(ctxt, data); break;
196 ADDFUNC2(multimedia,user_data)(ctxt, data); break;
198 ADDFUNC2(note,user_data)(ctxt, data); break;
200 ADDFUNC2(repository,user_data)(ctxt, data); break;
202 ADDFUNC2(source,user_data)(ctxt, data); break;
204 ADDFUNC2(user_rec,user_data)(ctxt, data); break;
206 ADDFUNC2(address,user_data)(ctxt, data); break;
208 ADDFUNC2(event,user_data)(ctxt, data); break;
210 ADDFUNC2(place,user_data)(ctxt, data); break;
211 case T_source_citation:
212 ADDFUNC2(source_citation,user_data)(ctxt, data); break;
214 ADDFUNC2(note_sub,user_data)(ctxt, data); break;
215 case T_multimedia_link:
216 ADDFUNC2(multimedia_link,user_data)(ctxt, data); break;
218 ADDFUNC2(lds_event,user_data)(ctxt, data); break;
219 case T_user_ref_number:
220 ADDFUNC2(user_ref_number,user_data)(ctxt, data); break;
222 ADDFUNC2(change_date,user_data)(ctxt, data); break;
223 case T_personal_name:
224 ADDFUNC2(personal_name,user_data)(ctxt, data); break;
226 ADDFUNC2(family_link,user_data)(ctxt, data); break;
228 ADDFUNC2(association,user_data)(ctxt, data); break;
230 ADDFUNC2(source_event,user_data)(ctxt, data); break;
231 case T_source_description:
232 ADDFUNC2(source_description,user_data)(ctxt, data); break;
234 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
236 result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
241 return (Gedcom_ctxt)result;
244 void user_rec_subscribe()
246 gedcom_subscribe_to_record(REC_USER, user_rec_start, def_rec_end);
247 gedcom_subscribe_to_element(ELT_USER, user_elt_start, def_elt_end);
250 void UNREFALLFUNC(user_data)(struct user_data *obj)
253 struct user_data* runner;
254 for (runner = obj; runner; runner = runner->next)
255 unref_xref_value(runner->xref_value);
259 void CLEANFUNC(user_data)(struct user_data* data)
262 SAFE_FREE(data->tag);
263 SAFE_FREE(data->str_value);
267 void UNREFALLFUNC(user_rec)(struct user_rec *obj)
270 unref_xref_value(obj->xref_value);
271 UNREFALLFUNC(user_data)(obj->extra);
275 void CLEANFUNC(user_rec)(struct user_rec* rec)
278 SAFE_FREE(rec->xrefstr);
280 SAFE_FREE(rec->str_value);
281 DESTROY_CHAIN_ELTS(user_data, rec->extra);
285 void user_recs_cleanup()
287 DESTROY_CHAIN_ELTS(user_rec, gom_first_user_rec);
290 struct user_rec* gom_get_first_user_rec()
292 return gom_first_user_rec;
295 int write_user_recs(Gedcom_write_hndl hndl)
298 struct user_rec* obj;
300 for (obj = gom_first_user_rec; obj; obj = obj->next) {
302 result |= gedcom_write_user_xref(hndl, 0, obj->tag, obj->xrefstr,
305 result |= gedcom_write_user_str(hndl, 0, obj->tag, obj->xrefstr,
308 result |= write_user_data(hndl, obj->extra);
313 int write_user_data(Gedcom_write_hndl hndl, struct user_data* data)
316 struct user_data* obj;
320 for (obj = data; obj; obj = obj->next) {
322 result |= gedcom_write_user_xref(hndl, obj->level, obj->tag, NULL,
325 result |= gedcom_write_user_str(hndl, obj->level, obj->tag, NULL,