First check-in of gedcom object model.
[gedcom-parse.git] / gom / submitter.c
1 /* Submitter 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 "submitter.h"
27 #include "address.h"
28 #include "multimedia_link.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 submitter* gom_first_submitter = NULL;
36
37 REC_CB(submitter, subm_start, make_submitter_record)
38 GET_REC_BY_XREF(submitter, XREF_SUBM, gom_get_submitter_by_xref)
39 STRING_CB(submitter, subm_name_start, name)
40 STRING_CB(submitter, subm_rfn_start, record_file_nr)
41 STRING_CB(submitter, subm_rin_start, record_id)
42
43 Gedcom_ctxt subm_lang_start(_ELT_PARAMS_)
44 {
45   Gom_ctxt ctxt = (Gom_ctxt)parent;
46   struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
47   char *str = GEDCOM_STRING(parsed_value);
48   
49   if (! subm->language[0])
50     subm->language[0] = strdup(str);
51   else if (! subm->language[1])
52     subm->language[1] = strdup(str);
53   else if (! subm->language[2])
54     subm->language[2] = strdup(str);
55   
56   return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, submitter, subm);
57 }
58
59 void submitter_subscribe()
60 {
61   gedcom_subscribe_to_record(REC_SUBM, subm_start, def_rec_end);
62   gedcom_subscribe_to_element(ELT_SUBM_NAME, subm_name_start, def_elt_end);
63   gedcom_subscribe_to_element(ELT_SUBM_LANG, subm_lang_start, def_elt_end);
64   gedcom_subscribe_to_element(ELT_SUBM_RFN, subm_rfn_start, def_elt_end);
65   gedcom_subscribe_to_element(ELT_SUBM_RIN, subm_rin_start, def_elt_end);
66 }
67
68 void submitter_add_address(Gom_ctxt ctxt, struct address* address)
69 {
70   struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
71   subm->address = address;
72 }
73
74 void submitter_add_phone(Gom_ctxt ctxt, char *phone)
75 {
76   struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
77   if (! subm->phone[0])
78     subm->phone[0] = strdup(phone);
79   else if (! subm->phone[1])
80     subm->phone[1] = strdup(phone);
81   else if (! subm->phone[2])
82     subm->phone[2] = strdup(phone);
83 }
84
85 void submitter_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link)
86 {
87   struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
88   LINK_CHAIN_ELT(multimedia_link, subm->mm_link, link)
89 }
90
91 void submitter_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
92 {
93   struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
94   subm->change_date = chan;
95 }
96
97 void submitter_add_user_data(Gom_ctxt ctxt, struct user_data* data)
98 {
99   struct submitter *obj = SAFE_CTXT_CAST(submitter, ctxt);
100   LINK_CHAIN_ELT(user_data, obj->extra, data)
101 }
102
103 void submitter_cleanup(struct submitter* rec)
104 {
105   SAFE_FREE(rec->xrefstr);
106   SAFE_FREE(rec->name);
107   address_cleanup(rec->address);
108   SAFE_FREE(rec->phone[0]);
109   SAFE_FREE(rec->phone[1]);
110   SAFE_FREE(rec->phone[2]);
111   DESTROY_CHAIN_ELTS(multimedia_link, rec->mm_link, multimedia_link_cleanup)
112   SAFE_FREE(rec->language[0]);
113   SAFE_FREE(rec->language[1]);
114   SAFE_FREE(rec->language[2]);
115   SAFE_FREE(rec->record_file_nr);
116   SAFE_FREE(rec->record_id);
117   change_date_cleanup(rec->change_date);
118   DESTROY_CHAIN_ELTS(user_data, rec->extra, user_data_cleanup)
119 }
120
121 void submitters_cleanup()
122 {
123   DESTROY_CHAIN_ELTS(submitter, gom_first_submitter, submitter_cleanup);
124 }
125
126 struct submitter* gom_get_first_submitter()
127 {
128   return gom_first_submitter;
129 }
130
131 struct submitter* make_submitter_record(char* xrefstr)
132 {
133   struct submitter* subm;
134   MAKE_CHAIN_ELT(submitter, gom_first_submitter, subm);
135   subm->xrefstr = strdup(xrefstr);
136   return subm;
137 }