1 /* Multimedia link 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 "multimedia_link.h"
28 #include "source_citation.h"
31 #include "individual.h"
33 #include "submitter.h"
37 #include "gom_internal.h"
39 Gedcom_ctxt sub_obje_start(_ELT_PARAMS_)
41 Gom_ctxt ctxt = (Gom_ctxt)parent;
42 Gom_ctxt result = NULL;
47 struct multimedia_link *mm
48 = (struct multimedia_link *)malloc(sizeof(struct multimedia_link));
52 memset (mm, 0, sizeof(struct multimedia_link));
53 if (GEDCOM_IS_XREF_PTR(parsed_value))
54 mm->reference = GEDCOM_XREF_PTR(parsed_value);
56 switch (ctxt->ctxt_type) {
58 case ELT_SUB_FAM_EVT_EVEN:
59 case ELT_SUB_INDIV_ATTR:
60 case ELT_SUB_INDIV_RESI:
61 case ELT_SUB_INDIV_BIRT:
62 case ELT_SUB_INDIV_GEN:
63 case ELT_SUB_INDIV_ADOP:
64 case ELT_SUB_INDIV_EVEN:
65 event_add_mm_link(ctxt, mm); break;
67 citation_add_mm_link(ctxt, mm); break;
69 family_add_mm_link(ctxt, mm); break;
71 individual_add_mm_link(ctxt, mm); break;
73 source_add_mm_link(ctxt, mm); break;
75 submitter_add_mm_link(ctxt, mm); break;
77 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
79 result = MAKE_GOM_CTXT(elt, multimedia_link, mm);
83 return (Gedcom_ctxt)result;
86 STRING_CB(multimedia_link, sub_obje_form_start, form)
87 STRING_CB(multimedia_link, sub_obje_titl_start, title)
88 STRING_CB(multimedia_link, sub_obje_file_start, file)
90 void multimedia_link_subscribe()
92 gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE,
93 sub_obje_start, def_elt_end);
94 gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE_FORM,
95 sub_obje_form_start, def_elt_end);
96 gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE_TITL,
97 sub_obje_titl_start, def_elt_end);
98 gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE_FILE,
99 sub_obje_file_start, def_elt_end);
102 void multimedia_link_add_note(Gom_ctxt ctxt, struct note_sub* note)
104 struct multimedia_link *mm = SAFE_CTXT_CAST(multimedia_link, ctxt);
106 LINK_CHAIN_ELT(note_sub, mm->note, note);
109 void multimedia_link_add_user_data(Gom_ctxt ctxt, struct user_data* data)
111 struct multimedia_link *obj = SAFE_CTXT_CAST(multimedia_link, ctxt);
113 LINK_CHAIN_ELT(user_data, obj->extra, data);
116 void multimedia_link_cleanup(struct multimedia_link* mm)
120 SAFE_FREE(mm->title);
122 DESTROY_CHAIN_ELTS(note_sub, mm->note, note_sub_cleanup);
123 DESTROY_CHAIN_ELTS(user_data, mm->extra, user_data_cleanup);
127 int write_multimedia_links(Gedcom_write_hndl hndl, int parent,
128 struct multimedia_link* mm)
131 struct multimedia_link* obj;
135 for (obj = mm; obj; obj = obj->next) {
136 if (obj->reference) {
137 result |= gedcom_write_element_xref(hndl, ELT_SUB_MULTIM_OBJE, 0,
138 parent, obj->reference);
141 result |= gedcom_write_element_str(hndl, ELT_SUB_MULTIM_OBJE, 0,
144 result |= gedcom_write_element_str(hndl, ELT_SUB_MULTIM_OBJE_FORM, 0,
145 ELT_SUB_MULTIM_OBJE, obj->form);
147 result |= gedcom_write_element_str(hndl, ELT_SUB_MULTIM_OBJE_TITL, 0,
148 ELT_SUB_MULTIM_OBJE, obj->title);
150 result |= gedcom_write_element_str(hndl, ELT_SUB_MULTIM_OBJE_FILE, 0,
151 ELT_SUB_MULTIM_OBJE, obj->file);
153 result |= write_note_subs(hndl, ELT_SUB_MULTIM_OBJE, obj->note);
155 result |= write_user_data(hndl, obj->extra);