1 /* Source 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
26 #include "source_event.h"
31 #include "gom_internal.h"
33 Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_)
35 Gom_ctxt ctxt = (Gom_ctxt)parent;
36 Gom_ctxt result = NULL;
41 struct source_event *evt
42 = (struct source_event *)malloc(sizeof(struct source_event));
46 memset (evt, 0, sizeof(struct source_event));
47 evt->recorded_events = strdup(GEDCOM_STRING(parsed_value));
49 if (! evt->recorded_events) {
54 switch (ctxt->ctxt_type) {
56 source_add_event(ctxt, evt); break;
58 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
60 result = MAKE_GOM_CTXT(elt, source_event, evt);
65 return (Gedcom_ctxt)result;
68 DATE_CB(source_event, sub_sour_even_date_start, date_period)
69 STRING_CB(source_event, sub_sour_even_plac_start, jurisdiction)
71 void source_event_subscribe()
73 gedcom_subscribe_to_element(ELT_SOUR_DATA_EVEN, sub_sour_even_start,
75 gedcom_subscribe_to_element(ELT_SOUR_DATA_EVEN_DATE,
76 sub_sour_even_date_start, def_elt_end);
77 gedcom_subscribe_to_element(ELT_SOUR_DATA_EVEN_PLAC,
78 sub_sour_even_plac_start, def_elt_end);
81 void source_event_add_user_data(Gom_ctxt ctxt, struct user_data* data)
83 struct source_event *obj = SAFE_CTXT_CAST(source_event, ctxt);
85 LINK_CHAIN_ELT(user_data, obj->extra, data);
88 void source_event_cleanup(struct source_event* evt)
91 SAFE_FREE(evt->recorded_events);
92 SAFE_FREE(evt->date_period);
93 SAFE_FREE(evt->jurisdiction);
94 DESTROY_CHAIN_ELTS(user_data, evt->extra, user_data_cleanup);
98 int write_source_events(Gedcom_write_hndl hndl, int parent,
99 struct source_event *evt)
102 struct source_event* obj;
106 for (obj = evt; obj; obj = obj->next) {
107 result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA_EVEN, 0,
108 parent, obj->recorded_events);
109 if (obj->date_period)
110 result |= gedcom_write_element_date(hndl, ELT_SOUR_DATA_EVEN_DATE, 0,
111 ELT_SOUR_DATA_EVEN, obj->date_period);
112 if (obj->jurisdiction)
113 result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA_EVEN_PLAC, 0,
114 ELT_SOUR_DATA_EVEN, obj->jurisdiction);
116 result |= write_user_data(hndl, obj->extra);