1 /* Source 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 "source_event.h"
29 #include "source_description.h"
30 #include "repository.h"
31 #include "multimedia_link.h"
33 #include "change_date.h"
37 #include "gom_internal.h"
39 struct source* gom_first_source = NULL;
41 REC_CB(source, sour_start, make_source_record)
42 GET_REC_BY_XREF(source, XREF_SOUR, gom_get_source_by_xref)
43 NULL_CB(source, sour_data_start)
44 STRING_CB(source, sour_data_agnc_start, data.agency)
45 STRING_CB(source, sour_auth_start, author)
46 STRING_CB(source, sour_titl_start, title)
47 STRING_CB(source, sour_abbr_start, abbreviation)
48 STRING_CB(source, sour_publ_start, publication)
49 STRING_CB(source, sour_text_start, text)
50 XREF_CB(source, sour_repo_start, repository.link, make_repository_record)
52 void source_subscribe()
54 gedcom_subscribe_to_record(REC_SOUR, sour_start, def_rec_end);
55 gedcom_subscribe_to_element(ELT_SOUR_DATA, sour_data_start, def_elt_end);
56 gedcom_subscribe_to_element(ELT_SOUR_DATA_AGNC, sour_data_agnc_start,
58 gedcom_subscribe_to_element(ELT_SOUR_AUTH, sour_auth_start, def_elt_end);
59 gedcom_subscribe_to_element(ELT_SOUR_TITL, sour_titl_start, def_elt_end);
60 gedcom_subscribe_to_element(ELT_SOUR_ABBR, sour_abbr_start, def_elt_end);
61 gedcom_subscribe_to_element(ELT_SOUR_PUBL, sour_publ_start, def_elt_end);
62 gedcom_subscribe_to_element(ELT_SOUR_TEXT, sour_text_start, def_elt_end);
63 gedcom_subscribe_to_element(ELT_SUB_REPO, sour_repo_start, def_elt_end);
66 void source_add_event(Gom_ctxt ctxt, struct source_event* evt)
68 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
69 LINK_CHAIN_ELT(source_event, sour->data.event, evt)
72 void source_add_note_to_data(Gom_ctxt ctxt, struct note_sub* note)
74 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
75 LINK_CHAIN_ELT(note_sub, sour->data.note, note)
78 void source_add_note_to_repo(Gom_ctxt ctxt, struct note_sub* note)
80 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
81 LINK_CHAIN_ELT(note_sub, sour->repository.note, note)
84 void source_add_description(Gom_ctxt ctxt, struct source_description* desc)
86 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
87 LINK_CHAIN_ELT(source_description, sour->repository.description, desc)
90 void source_add_to_value(NL_TYPE type, Gom_ctxt ctxt, char* str)
92 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
93 switch (ctxt->ctxt_type) {
95 sour->author = concat_strings (type, sour->author, str); break;
97 sour->title = concat_strings (type, sour->title, str); break;
99 sour->publication = concat_strings (type, sour->publication, str); break;
101 sour->text = concat_strings (type, sour->text, str); break;
103 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
107 void source_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link)
109 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
110 LINK_CHAIN_ELT(multimedia_link, sour->mm_link, link)
113 void source_add_note(Gom_ctxt ctxt, struct note_sub* note)
115 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
116 LINK_CHAIN_ELT(note_sub, sour->note, note)
119 void source_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
121 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
122 LINK_CHAIN_ELT(user_ref_number, sour->ref, ref)
125 void source_set_record_id(Gom_ctxt ctxt, char *rin)
127 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
128 sour->record_id = strdup(rin);
131 void source_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
133 struct source *sour = SAFE_CTXT_CAST(source, ctxt);
134 sour->change_date = chan;
137 void source_add_user_data(Gom_ctxt ctxt, struct user_data* data)
139 struct source *obj = SAFE_CTXT_CAST(source, ctxt);
140 LINK_CHAIN_ELT(user_data, obj->extra, data)
143 void source_cleanup(struct source* sour)
145 SAFE_FREE(sour->xrefstr);
146 DESTROY_CHAIN_ELTS(source_event, sour->data.event, source_event_cleanup)
147 SAFE_FREE(sour->data.agency)
148 DESTROY_CHAIN_ELTS(note_sub, sour->data.note, note_sub_cleanup)
149 SAFE_FREE(sour->author);
150 SAFE_FREE(sour->title);
151 SAFE_FREE(sour->abbreviation);
152 SAFE_FREE(sour->publication);
153 SAFE_FREE(sour->text);
154 DESTROY_CHAIN_ELTS(note_sub, sour->repository.note, note_sub_cleanup)
155 DESTROY_CHAIN_ELTS(source_description, sour->repository.description,
156 source_description_cleanup)
157 DESTROY_CHAIN_ELTS(multimedia_link, sour->mm_link, multimedia_link_cleanup)
158 DESTROY_CHAIN_ELTS(note_sub, sour->note, note_sub_cleanup)
159 DESTROY_CHAIN_ELTS(user_ref_number, sour->ref, user_ref_cleanup)
160 SAFE_FREE(sour->record_id);
161 change_date_cleanup(sour->change_date);
162 DESTROY_CHAIN_ELTS(user_data, sour->extra, user_data_cleanup)
165 void sources_cleanup()
167 DESTROY_CHAIN_ELTS(source, gom_first_source, source_cleanup);
170 struct source* gom_get_first_source()
172 return gom_first_source;
175 struct source* make_source_record(char* xrefstr)
178 MAKE_CHAIN_ELT(source, gom_first_source, src);
179 src->xrefstr = strdup(xrefstr);