1 /* User reference number sub-structure 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
28 #include "individual.h"
29 #include "multimedia.h"
31 #include "repository.h"
36 #include "gom_internal.h"
38 Gedcom_ctxt sub_user_ref_start(_ELT_PARAMS_)
40 Gom_ctxt ctxt = (Gom_ctxt)parent;
41 Gom_ctxt result = NULL;
46 struct user_ref_number *refn
47 = (struct user_ref_number *)malloc(sizeof(struct user_ref_number));
52 memset (refn, 0, sizeof(struct user_ref_number));
53 refn->value = strdup(GEDCOM_STRING(parsed_value));
59 switch (ctxt->ctxt_type) {
61 ADDFUNC2(family,user_ref_number)(ctxt, refn); break;
63 ADDFUNC2(individual,user_ref_number)(ctxt, refn); break;
65 ADDFUNC2(multimedia,user_ref_number)(ctxt, refn); break;
67 ADDFUNC2(note,user_ref_number)(ctxt, refn); break;
69 ADDFUNC2(repository,user_ref_number)(ctxt, refn); break;
71 ADDFUNC2(source,user_ref_number)(ctxt, refn); break;
73 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
76 result = MAKE_GOM_CTXT(elt, user_ref_number, refn);
81 return (Gedcom_ctxt)result;
84 DEFINE_STRING_CB(user_ref_number, sub_user_ref_type_start, type)
86 DEFINE_ADDFUNC2(user_ref_number, user_data, extra)
88 Gedcom_ctxt sub_user_rin_start(_ELT_PARAMS_)
90 Gom_ctxt ctxt = (Gom_ctxt)parent;
91 Gom_ctxt result = NULL;
96 char *str = GEDCOM_STRING(parsed_value);
98 switch (ctxt->ctxt_type) {
100 ADDFUNC2_STR(family,record_id)(ctxt, str); break;
102 ADDFUNC2_STR(individual,record_id)(ctxt, str); break;
104 ADDFUNC2_STR(multimedia,record_id)(ctxt, str); break;
106 ADDFUNC2_STR(note,record_id)(ctxt, str); break;
108 ADDFUNC2_STR(repository,record_id)(ctxt, str); break;
110 ADDFUNC2_STR(source,record_id)(ctxt, str); break;
112 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
114 result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
116 return (Gedcom_ctxt)result;
119 void user_ref_subscribe()
121 gedcom_subscribe_to_element(ELT_SUB_IDENT_REFN, sub_user_ref_start,
123 gedcom_subscribe_to_element(ELT_SUB_IDENT_REFN_TYPE, sub_user_ref_type_start,
125 gedcom_subscribe_to_element(ELT_SUB_IDENT_RIN, sub_user_rin_start,
129 void CLEANFUNC(user_ref_number)(struct user_ref_number* refn)
132 SAFE_FREE(refn->value);
133 SAFE_FREE(refn->type);
134 DESTROY_CHAIN_ELTS(user_data, refn->extra);
138 int write_user_refs(Gedcom_write_hndl hndl, int parent,
139 struct user_ref_number *refn)
142 struct user_ref_number* obj;
146 for (obj = refn; obj; obj = obj->next) {
147 result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_REFN, 0,
150 result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_REFN_TYPE, 0,
151 ELT_SUB_IDENT_REFN, obj->type);
153 result |= write_user_data(hndl, obj->extra);