Better checking of library result values.
[gedcom-parse.git] / gom / source_description.c
1 /* Source description 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.
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 "source_description.h"
27 #include "source.h"
28 #include "user_rec.h"
29 #include "gom.h"
30 #include "gedcom.h"
31 #include "gom_internal.h"
32
33 Gedcom_ctxt sub_sour_caln_start(_ELT_PARAMS_)
34 {
35   Gom_ctxt ctxt = (Gom_ctxt)parent;
36   struct source_description *desc = NULL;
37
38   if (ctxt) {
39     desc
40       = (struct source_description *)malloc(sizeof(struct source_description));
41     memset (desc, 0, sizeof(struct source_description));
42     desc->call_number = strdup(GEDCOM_STRING(parsed_value));
43
44     switch (ctxt->ctxt_type) {
45       case ELT_SUB_REPO:
46         source_add_description(ctxt, desc); break;
47       default:
48         UNEXPECTED_CONTEXT(ctxt->ctxt_type);
49     }
50   }
51
52   return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, source_description, desc);
53 }
54
55 STRING_CB(source_description, sub_sour_caln_medi_start, media)
56      
57 void source_description_subscribe()
58 {
59   gedcom_subscribe_to_element(ELT_SUB_REPO_CALN, sub_sour_caln_start,
60                               def_elt_end);
61   gedcom_subscribe_to_element(ELT_SUB_REPO_CALN_MEDI,
62                               sub_sour_caln_medi_start, def_elt_end);
63 }
64
65 void source_description_add_user_data(Gom_ctxt ctxt, struct user_data* data)
66 {
67   struct source_description *obj = SAFE_CTXT_CAST(source_description, ctxt);
68   LINK_CHAIN_ELT(user_data, obj->extra, data)
69 }
70
71 void source_description_cleanup(struct source_description* desc)
72 {
73   if (desc) {
74     SAFE_FREE(desc->call_number);
75     SAFE_FREE(desc->media);
76     DESTROY_CHAIN_ELTS(user_data, desc->extra, user_data_cleanup)
77   }
78 }