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.
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 "submitter.h"
28 #include "multimedia_link.h"
29 #include "change_date.h"
33 #include "gom_internal.h"
35 struct submitter* gom_first_submitter = NULL;
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)
43 Gedcom_ctxt subm_lang_start(_ELT_PARAMS_)
45 Gom_ctxt ctxt = (Gom_ctxt)parent;
46 Gom_ctxt result = NULL;
51 struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
55 char *str = GEDCOM_STRING(parsed_value);
58 while (i<2 && subm->language[i]) i++;
59 if (! subm->language[i]) {
60 subm->language[i] = strdup(str);
61 if (! subm->language[i]) {
67 result = MAKE_GOM_CTXT(elt, submitter, subm);
71 return (Gedcom_ctxt)result;
74 void submitter_subscribe()
76 gedcom_subscribe_to_record(REC_SUBM, subm_start, def_rec_end);
77 gedcom_subscribe_to_element(ELT_SUBM_NAME, subm_name_start, def_elt_end);
78 gedcom_subscribe_to_element(ELT_SUBM_LANG, subm_lang_start, def_elt_end);
79 gedcom_subscribe_to_element(ELT_SUBM_RFN, subm_rfn_start, def_elt_end);
80 gedcom_subscribe_to_element(ELT_SUBM_RIN, subm_rin_start, def_elt_end);
83 void submitter_add_address(Gom_ctxt ctxt, struct address* address)
85 struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
87 subm->address = address;
90 void submitter_add_phone(Gom_ctxt ctxt, const char *phone)
92 struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
95 while (i<2 && subm->phone[i]) i++;
96 if (! subm->phone[i]) {
97 subm->phone[i] = strdup(phone);
98 if (! subm->phone[i]) MEMORY_ERROR;
103 void submitter_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link)
105 struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
107 LINK_CHAIN_ELT(multimedia_link, subm->mm_link, link);
110 void submitter_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
112 struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt);
114 subm->change_date = chan;
117 void submitter_add_user_data(Gom_ctxt ctxt, struct user_data* data)
119 struct submitter *obj = SAFE_CTXT_CAST(submitter, ctxt);
121 LINK_CHAIN_ELT(user_data, obj->extra, data);
124 void submitter_cleanup(struct submitter* rec)
127 SAFE_FREE(rec->xrefstr);
128 SAFE_FREE(rec->name);
129 address_cleanup(rec->address);
130 SAFE_FREE(rec->phone[0]);
131 SAFE_FREE(rec->phone[1]);
132 SAFE_FREE(rec->phone[2]);
133 DESTROY_CHAIN_ELTS(multimedia_link, rec->mm_link, multimedia_link_cleanup);
134 SAFE_FREE(rec->language[0]);
135 SAFE_FREE(rec->language[1]);
136 SAFE_FREE(rec->language[2]);
137 SAFE_FREE(rec->record_file_nr);
138 SAFE_FREE(rec->record_id);
139 change_date_cleanup(rec->change_date);
140 DESTROY_CHAIN_ELTS(user_data, rec->extra, user_data_cleanup);
144 void submitters_cleanup()
146 DESTROY_CHAIN_ELTS(submitter, gom_first_submitter, submitter_cleanup);
149 struct submitter* gom_get_first_submitter()
151 return gom_first_submitter;
154 struct submitter* make_submitter_record(const char* xrefstr)
156 struct submitter* subm = NULL;
157 MAKE_CHAIN_ELT(submitter, gom_first_submitter, subm);
159 subm->xrefstr = strdup(xrefstr);
160 if (!subm->xrefstr) MEMORY_ERROR;
165 int write_submitters(Gedcom_write_hndl hndl)
169 struct submitter* obj;
171 for (obj = gom_first_submitter; obj; obj = obj->next) {
172 result |= gedcom_write_record_str(hndl, REC_SUBM, 0,
175 result |= gedcom_write_element_str(hndl, ELT_SUBM_NAME, 0, REC_SUBM,
178 result |= write_address(hndl, REC_SUBM, obj->address);
179 for (i = 0; i < 3 && obj->phone[i]; i++)
180 result |= gedcom_write_element_str(hndl, ELT_SUB_PHON, 0, REC_SUBM,
183 result |= write_multimedia_links(hndl, REC_SUBM, obj->mm_link);
184 for (i = 0; i < 3 && obj->language[i]; i++)
185 result |= gedcom_write_element_str(hndl, ELT_SUBM_LANG, 0, REC_SUBM,
187 if (obj->record_file_nr)
188 result |= gedcom_write_element_str(hndl, ELT_SUBM_RFN, 0, REC_SUBM,
189 obj->record_file_nr);
191 result |= gedcom_write_element_str(hndl, ELT_SUBM_RIN, 0, REC_SUBM,
193 if (obj->change_date)
194 result |= write_change_date(hndl, REC_SUBM, obj->change_date);
196 result |= write_user_data(hndl, obj->extra);