Taking care of const correctness.
[gedcom-parse.git] / gom / submission.c
1 /* Submission 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 "submission.h"
27 #include "submitter.h"
28 #include "user_rec.h"
29 #include "gom.h"
30 #include "gedcom.h"
31 #include "gom_internal.h"
32
33 struct submission* gom_submission = NULL;
34
35 REC_CB(submission, subn_start, make_submission_record)
36 XREF_CB(submission, subn_subm_start, submitter, make_submitter_record)
37 STRING_CB(submission, subn_famf_start, family_file)
38 STRING_CB(submission, subn_temp_start, temple_code)
39 STRING_CB(submission, subn_ance_start, nr_of_ancestor_gens)
40 STRING_CB(submission, subn_desc_start, nr_of_descendant_gens)
41 STRING_CB(submission, subn_ordi_start, ordinance_process_flag)
42 STRING_CB(submission, subn_rin_start, record_id)
43      
44 void submission_subscribe()
45 {
46   gedcom_subscribe_to_record(REC_SUBN, subn_start, def_rec_end);
47   gedcom_subscribe_to_element(ELT_SUBN_SUBM, subn_subm_start, def_elt_end);
48   gedcom_subscribe_to_element(ELT_SUBN_FAMF, subn_famf_start, def_elt_end);
49   gedcom_subscribe_to_element(ELT_SUBN_TEMP, subn_temp_start, def_elt_end);
50   gedcom_subscribe_to_element(ELT_SUBN_ANCE, subn_ance_start, def_elt_end);
51   gedcom_subscribe_to_element(ELT_SUBN_DESC, subn_desc_start, def_elt_end);
52   gedcom_subscribe_to_element(ELT_SUBN_ORDI, subn_ordi_start, def_elt_end);
53   gedcom_subscribe_to_element(ELT_SUBN_RIN, subn_rin_start, def_elt_end);  
54 }
55
56 void submission_add_user_data(Gom_ctxt ctxt, struct user_data* data)
57 {
58   struct submission *obj = SAFE_CTXT_CAST(submission, ctxt);
59   if (obj)
60     LINK_CHAIN_ELT(user_data, obj->extra, data);
61 }
62
63 void submission_cleanup()
64 {
65   if (gom_submission) {
66     SAFE_FREE(gom_submission->xrefstr);
67     SAFE_FREE(gom_submission->family_file);
68     SAFE_FREE(gom_submission->temple_code);
69     SAFE_FREE(gom_submission->nr_of_ancestor_gens);
70     SAFE_FREE(gom_submission->nr_of_descendant_gens);
71     SAFE_FREE(gom_submission->ordinance_process_flag);
72     SAFE_FREE(gom_submission->record_id);
73     DESTROY_CHAIN_ELTS(user_data, gom_submission->extra, user_data_cleanup);
74     SAFE_FREE(gom_submission);
75   }
76 }
77
78 struct submission* gom_get_submission()
79 {
80   return gom_submission;
81 }
82
83 struct submission* make_submission_record(const char* xref)
84 {
85   if (! gom_submission) {
86     gom_submission = (struct submission*)malloc(sizeof(struct submission));
87     if (! gom_submission)
88       MEMORY_ERROR;
89     else {
90       memset(gom_submission, 0, sizeof(struct submission));
91       gom_submission->xrefstr = strdup(xref);
92       if (!gom_submission->xrefstr) MEMORY_ERROR;
93     }
94   }
95   
96   return gom_submission;
97 }