Forgotten internal header file.
[gedcom-parse.git] / gom / multimedia.c
1 /* Multimedia 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.
5
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.
10
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.
15
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
19    02111-1307 USA.  */
20
21 /* $Id$ */
22 /* $Name$ */
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include "multimedia.h"
27 #include "note_sub.h"
28 #include "user_ref.h"
29 #include "change_date.h"
30 #include "user_rec.h"
31 #include "gom.h"
32 #include "gedcom.h"
33 #include "gom_internal.h"
34
35 struct multimedia* gom_first_multimedia = NULL;
36
37 REC_CB(multimedia, obje_start, make_multimedia_record)
38 GET_REC_BY_XREF(multimedia, XREF_OBJE, gom_get_multimedia_by_xref)
39 STRING_CB(multimedia, obje_form_start, form)
40 STRING_CB(multimedia, obje_titl_start, title)     
41 NULL_CB(multimedia, obje_blob_start)     
42 XREF_CB(multimedia, obje_obje_start, continued, make_multimedia_record)
43
44 Gedcom_ctxt obje_blob_cont_start(_ELT_PARAMS_)
45 {
46   Gom_ctxt ctxt = (Gom_ctxt)parent;
47   struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt);
48   char *str = GEDCOM_STRING(parsed_value);
49   if (obj->data)
50     obj->data = concat_strings (WITHOUT_NL, obj->data, str);
51   else
52     obj->data = strdup(str);
53   return (Gedcom_ctxt) make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
54 }
55
56 void multimedia_subscribe()
57 {
58   gedcom_subscribe_to_record(REC_OBJE, obje_start, def_rec_end);
59   gedcom_subscribe_to_element(ELT_OBJE_FORM, obje_form_start, def_elt_end);
60   gedcom_subscribe_to_element(ELT_OBJE_TITL, obje_titl_start, def_elt_end);
61   gedcom_subscribe_to_element(ELT_OBJE_BLOB, obje_blob_start, def_elt_end);
62   gedcom_subscribe_to_element(ELT_OBJE_BLOB_CONT, obje_blob_cont_start,
63                               def_elt_end);
64   gedcom_subscribe_to_element(ELT_OBJE_OBJE, obje_obje_start, def_elt_end);
65 }
66
67 void multimedia_add_note(Gom_ctxt ctxt, struct note_sub* note)
68 {
69   struct multimedia* obj = SAFE_CTXT_CAST(multimedia, ctxt);
70   LINK_CHAIN_ELT(note_sub, obj->note, note)
71 }
72
73 void multimedia_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
74 {
75   struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt);
76   LINK_CHAIN_ELT(user_ref_number, obj->ref, ref)
77 }
78
79 void multimedia_set_record_id(Gom_ctxt ctxt, char *rin)
80 {
81   struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt);
82   obj->record_id = strdup(rin);
83 }
84
85 void multimedia_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
86 {
87   struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt);
88   obj->change_date = chan;
89 }
90
91 void multimedia_add_user_data(Gom_ctxt ctxt, struct user_data* data)
92 {
93   struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt);
94   LINK_CHAIN_ELT(user_data, obj->extra, data)
95 }
96
97 void multimedia_cleanup(struct multimedia* obj)
98 {
99   SAFE_FREE(obj->xrefstr);
100   SAFE_FREE(obj->form);
101   SAFE_FREE(obj->title);
102   DESTROY_CHAIN_ELTS(note_sub, obj->note, note_sub_cleanup)
103   SAFE_FREE(obj->data);
104   DESTROY_CHAIN_ELTS(user_ref_number, obj->ref, user_ref_cleanup)
105   SAFE_FREE(obj->record_id);
106   change_date_cleanup(obj->change_date);
107   DESTROY_CHAIN_ELTS(user_data, obj->extra, user_data_cleanup)
108 }
109
110 void multimedias_cleanup()
111 {
112   DESTROY_CHAIN_ELTS(multimedia, gom_first_multimedia, multimedia_cleanup);
113 }
114
115 struct multimedia* gom_get_first_multimedia()
116 {
117   return gom_first_multimedia;
118 }
119
120 struct multimedia* make_multimedia_record(char* xrefstr)
121 {
122   struct multimedia* multi;
123   MAKE_CHAIN_ELT(multimedia, gom_first_multimedia, multi);
124   multi->xrefstr = strdup(xrefstr);
125   return multi;
126 }