1 /* Event 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
27 #include "individual.h"
31 #include "source_citation.h"
32 #include "multimedia_link.h"
37 #include "gom_internal.h"
39 Gedcom_ctxt sub_evt_start(_ELT_PARAMS_)
41 Gom_ctxt ctxt = (Gom_ctxt)parent;
42 struct event *evt = NULL;
45 evt = (struct event *)malloc(sizeof(struct event));
46 memset (evt, 0, sizeof(struct event));
47 evt->event = parsed_tag;
48 evt->event_name = strdup(tag);
49 if (GEDCOM_IS_STRING(parsed_value))
50 evt->val = strdup(GEDCOM_STRING(parsed_value));
52 switch (ctxt->ctxt_type) {
54 family_add_event(ctxt, evt); break;
56 individual_add_event(ctxt, evt); break;
58 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
62 return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, event, evt);
65 Gedcom_ctxt sub_attr_start(_ELT_PARAMS_)
67 Gom_ctxt ctxt = (Gom_ctxt)parent;
68 struct event *evt = NULL;
71 evt = (struct event *)malloc(sizeof(struct event));
72 memset (evt, 0, sizeof(struct event));
73 evt->event = parsed_tag;
74 evt->event_name = strdup(tag);
75 if (GEDCOM_IS_STRING(parsed_value))
76 evt->val = strdup(GEDCOM_STRING(parsed_value));
77 switch (ctxt->ctxt_type) {
79 individual_add_attribute(ctxt, evt); break;
81 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
84 return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, event, evt);
87 STRING_CB(event, sub_evt_type_start, type)
88 DATE_CB(event, sub_evt_date_start, date)
89 AGE_CB(event, sub_evt_age_start, age)
90 STRING_CB(event, sub_evt_agnc_start, agency)
91 STRING_CB(event, sub_evt_caus_start, cause)
92 NULL_CB(event, sub_fam_evt_husb_wife_start)
93 XREF_CB(event, sub_evt_famc_start, family, make_family_record)
94 STRING_CB(event, sub_evt_famc_adop_start, adoption_parent)
96 Gedcom_ctxt sub_fam_evt_age_start(_ELT_PARAMS_)
98 struct age_value age = GEDCOM_AGE(parsed_value);
99 Gom_ctxt ctxt = (Gom_ctxt)parent;
100 struct event *evt = NULL;
102 evt = SAFE_CTXT_CAST(event, ctxt);
103 switch (ctxt->ctxt_type) {
104 case ELT_SUB_FAM_EVT_HUSB:
105 evt->husband_age = dup_age(age); break;
106 case ELT_SUB_FAM_EVT_WIFE:
107 evt->wife_age = dup_age(age); break;
109 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
112 return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, event, evt);
115 void event_add_place(Gom_ctxt ctxt, struct place* place)
117 struct event *evt = SAFE_CTXT_CAST(event, ctxt);
121 void event_add_address(Gom_ctxt ctxt, struct address* address)
123 struct event *evt = SAFE_CTXT_CAST(event, ctxt);
124 evt->address = address;
127 void event_add_phone(Gom_ctxt ctxt, char *phone)
129 struct event *evt = SAFE_CTXT_CAST(event, ctxt);
131 evt->phone[0] = strdup(phone);
132 else if (! evt->phone[1])
133 evt->phone[1] = strdup(phone);
134 else if (! evt->phone[2])
135 evt->phone[2] = strdup(phone);
138 void event_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
140 struct event *evt = SAFE_CTXT_CAST(event, ctxt);
141 LINK_CHAIN_ELT(source_citation, evt->citation, cit)
144 void event_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* mm)
146 struct event *evt = SAFE_CTXT_CAST(event, ctxt);
147 LINK_CHAIN_ELT(multimedia_link, evt->mm_link, mm)
150 void event_add_note(Gom_ctxt ctxt, struct note_sub* note)
152 struct event *evt = SAFE_CTXT_CAST(event, ctxt);
153 LINK_CHAIN_ELT(note_sub, evt->note, note)
156 void event_add_user_data(Gom_ctxt ctxt, struct user_data* data)
158 struct event *obj = SAFE_CTXT_CAST(event, ctxt);
159 LINK_CHAIN_ELT(user_data, obj->extra, data)
162 void event_subscribe()
164 gedcom_subscribe_to_element(ELT_SUB_FAM_EVT, sub_evt_start, def_elt_end);
165 gedcom_subscribe_to_element(ELT_SUB_FAM_EVT_EVEN,
166 sub_evt_start, def_elt_end);
167 gedcom_subscribe_to_element(ELT_SUB_INDIV_ATTR,
168 sub_attr_start, def_elt_end);
169 gedcom_subscribe_to_element(ELT_SUB_INDIV_RESI,
170 sub_attr_start, def_elt_end);
171 gedcom_subscribe_to_element(ELT_SUB_INDIV_BIRT,
172 sub_evt_start, def_elt_end);
173 gedcom_subscribe_to_element(ELT_SUB_INDIV_BIRT_FAMC,
174 sub_evt_famc_start, def_elt_end);
175 gedcom_subscribe_to_element(ELT_SUB_INDIV_GEN,
176 sub_evt_start, def_elt_end);
177 gedcom_subscribe_to_element(ELT_SUB_INDIV_ADOP,
178 sub_evt_start, def_elt_end);
179 gedcom_subscribe_to_element(ELT_SUB_INDIV_ADOP_FAMC,
180 sub_evt_famc_start, def_elt_end);
181 gedcom_subscribe_to_element(ELT_SUB_INDIV_ADOP_FAMC_ADOP,
182 sub_evt_famc_adop_start, def_elt_end);
183 gedcom_subscribe_to_element(ELT_SUB_INDIV_EVEN,
184 sub_evt_start, def_elt_end);
185 gedcom_subscribe_to_element(ELT_SUB_FAM_EVT_HUSB,
186 sub_fam_evt_husb_wife_start, def_elt_end);
187 gedcom_subscribe_to_element(ELT_SUB_FAM_EVT_WIFE,
188 sub_fam_evt_husb_wife_start, def_elt_end);
189 gedcom_subscribe_to_element(ELT_SUB_FAM_EVT_AGE,
190 sub_fam_evt_age_start, def_elt_end);
191 gedcom_subscribe_to_element(ELT_SUB_EVT_TYPE,
192 sub_evt_type_start, def_elt_end);
193 gedcom_subscribe_to_element(ELT_SUB_EVT_DATE,
194 sub_evt_date_start, def_elt_end);
195 gedcom_subscribe_to_element(ELT_SUB_EVT_AGE,
196 sub_evt_age_start, def_elt_end);
197 gedcom_subscribe_to_element(ELT_SUB_EVT_AGNC,
198 sub_evt_agnc_start, def_elt_end);
199 gedcom_subscribe_to_element(ELT_SUB_EVT_CAUS,
200 sub_evt_caus_start, def_elt_end);
203 void event_cleanup(struct event* evt)
206 SAFE_FREE(evt->event_name);
208 SAFE_FREE(evt->type);
209 SAFE_FREE(evt->date);
210 place_cleanup(evt->place);
211 address_cleanup(evt->address);
212 SAFE_FREE(evt->phone[0]);
213 SAFE_FREE(evt->phone[1]);
214 SAFE_FREE(evt->phone[2]);
216 SAFE_FREE(evt->agency);
217 SAFE_FREE(evt->cause);
218 DESTROY_CHAIN_ELTS(source_citation, evt->citation, citation_cleanup)
219 DESTROY_CHAIN_ELTS(multimedia_link, evt->mm_link, multimedia_link_cleanup)
220 DESTROY_CHAIN_ELTS(note_sub, evt->note, note_sub_cleanup)
221 SAFE_FREE(evt->husband_age);
222 SAFE_FREE(evt->wife_age);
223 SAFE_FREE(evt->adoption_parent);
224 DESTROY_CHAIN_ELTS(user_data, evt->extra, user_data_cleanup)