1 /* Header 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
25 #include "submission.h"
26 #include "submitter.h"
31 #include "gom_internal.h"
33 struct header gom_header;
35 Gedcom_ctxt head_start(_REC_PARAMS_)
38 return (Gedcom_ctxt) MAKE_GOM_CTXT(rec, header, &gom_header);
41 STRING_CB(header, head_sour_start, source.id)
42 STRING_CB(header, head_sour_name_start, source.name)
43 STRING_CB(header, head_sour_vers_start, source.version)
44 STRING_CB(header, head_sour_corp_start, source.corporation.name)
45 STRING_CB(header, head_sour_data_start, source.data.name)
46 DATE_CB(header, head_sour_data_date_start, source.data.date)
47 STRING_CB(header, head_sour_data_copr_start, source.data.copyright)
48 STRING_CB(header, head_dest_start, destination)
49 XREF_CB(header, head_subm_start, submitter, make_submitter_record)
50 XREF_CB(header, head_subn_start, submission, make_submission_record)
51 DATE_CB(header, head_date_start, date)
52 STRING_CB(header, head_date_time_start, time)
53 STRING_CB(header, head_file_start, filename)
54 STRING_CB(header, head_copr_start, copyright)
55 NULL_CB(header, head_gedc_start)
56 STRING_CB(header, head_gedc_vers_start, gedcom.version)
57 STRING_CB(header, head_gedc_form_start, gedcom.form)
58 STRING_CB(header, head_char_start, charset.name)
59 STRING_CB(header, head_char_vers_start, charset.version)
60 STRING_CB(header, head_lang_start, language)
61 NULL_CB(header, head_plac_start)
62 STRING_CB(header, head_plac_form_start, place_hierarchy)
63 NULL_CB(header, head_note_start) /* the end callback will fill the value */
64 STRING_END_CB(header, head_note_end, note)
66 void header_add_address(Gom_ctxt ctxt, struct address* addr)
68 struct header *head = SAFE_CTXT_CAST(header, ctxt);
70 head->source.corporation.address = addr;
73 void header_add_phone(Gom_ctxt ctxt, const char* phone)
75 struct header *head = SAFE_CTXT_CAST(header, ctxt);
77 struct header_corporation *corp = &(head->source.corporation);
79 while (i<2 && corp->phone[i]) i++;
80 if (! corp->phone[i]) {
81 corp->phone[i] = strdup(phone);
82 if (! corp->phone[i]) MEMORY_ERROR;
87 void header_add_user_data(Gom_ctxt ctxt, struct user_data* data)
89 struct header *head = SAFE_CTXT_CAST(header, ctxt);
91 LINK_CHAIN_ELT(user_data, head->extra, data);
94 void header_subscribe()
96 gedcom_subscribe_to_record(REC_HEAD, head_start, def_rec_end);
97 gedcom_subscribe_to_element(ELT_HEAD_SOUR, head_sour_start, def_elt_end);
98 gedcom_subscribe_to_element(ELT_HEAD_SOUR_NAME, head_sour_name_start,
100 gedcom_subscribe_to_element(ELT_HEAD_SOUR_VERS, head_sour_vers_start,
102 gedcom_subscribe_to_element(ELT_HEAD_SOUR_CORP, head_sour_corp_start,
104 gedcom_subscribe_to_element(ELT_HEAD_SOUR_DATA, head_sour_data_start,
106 gedcom_subscribe_to_element(ELT_HEAD_SOUR_DATA_DATE,
107 head_sour_data_date_start, def_elt_end);
108 gedcom_subscribe_to_element(ELT_HEAD_SOUR_DATA_COPR,
109 head_sour_data_copr_start, def_elt_end);
110 gedcom_subscribe_to_element(ELT_HEAD_DEST, head_dest_start, def_elt_end);
111 gedcom_subscribe_to_element(ELT_HEAD_DATE, head_date_start, def_elt_end);
112 gedcom_subscribe_to_element(ELT_HEAD_DATE_TIME,
113 head_date_time_start, def_elt_end);
114 gedcom_subscribe_to_element(ELT_HEAD_SUBM, head_subm_start, def_elt_end);
115 gedcom_subscribe_to_element(ELT_HEAD_SUBN, head_subn_start, def_elt_end);
116 gedcom_subscribe_to_element(ELT_HEAD_FILE, head_file_start, def_elt_end);
117 gedcom_subscribe_to_element(ELT_HEAD_COPR, head_copr_start, def_elt_end);
118 gedcom_subscribe_to_element(ELT_HEAD_GEDC, head_gedc_start, def_elt_end);
119 gedcom_subscribe_to_element(ELT_HEAD_GEDC_VERS,
120 head_gedc_vers_start, def_elt_end);
121 gedcom_subscribe_to_element(ELT_HEAD_GEDC_FORM,
122 head_gedc_form_start, def_elt_end);
123 gedcom_subscribe_to_element(ELT_HEAD_CHAR, head_char_start, def_elt_end);
124 gedcom_subscribe_to_element(ELT_HEAD_CHAR_VERS,
125 head_char_vers_start, def_elt_end);
126 gedcom_subscribe_to_element(ELT_HEAD_LANG, head_lang_start, def_elt_end);
127 gedcom_subscribe_to_element(ELT_HEAD_PLAC, head_plac_start, def_elt_end);
128 gedcom_subscribe_to_element(ELT_HEAD_PLAC_FORM,
129 head_plac_form_start, def_elt_end);
130 gedcom_subscribe_to_element(ELT_HEAD_NOTE, head_note_start, head_note_end);
133 void header_cleanup()
135 SAFE_FREE(gom_header.source.id);
136 SAFE_FREE(gom_header.source.name);
137 SAFE_FREE(gom_header.source.version);
138 SAFE_FREE(gom_header.source.corporation.name);
139 address_cleanup(gom_header.source.corporation.address);
140 SAFE_FREE(gom_header.source.corporation.phone[0]);
141 SAFE_FREE(gom_header.source.corporation.phone[1]);
142 SAFE_FREE(gom_header.source.corporation.phone[2]);
143 SAFE_FREE(gom_header.source.data.name);
144 SAFE_FREE(gom_header.source.data.date);
145 SAFE_FREE(gom_header.source.data.copyright);
146 SAFE_FREE(gom_header.destination);
147 SAFE_FREE(gom_header.date);
148 SAFE_FREE(gom_header.time);
149 SAFE_FREE(gom_header.filename);
150 SAFE_FREE(gom_header.copyright);
151 SAFE_FREE(gom_header.gedcom.version);
152 SAFE_FREE(gom_header.gedcom.form);
153 SAFE_FREE(gom_header.charset.name);
154 SAFE_FREE(gom_header.charset.version);
155 SAFE_FREE(gom_header.language);
156 SAFE_FREE(gom_header.place_hierarchy);
157 SAFE_FREE(gom_header.note);
158 DESTROY_CHAIN_ELTS(user_data, gom_header.extra, user_data_cleanup);
161 struct header* gom_get_header()
166 int write_header(Gedcom_write_hndl hndl)
171 result |= gedcom_write_record_str(hndl, REC_HEAD, NULL, NULL);
172 if (gom_header.charset.name)
173 result |= gedcom_write_element_str(hndl, ELT_HEAD_CHAR, 0, REC_HEAD,
174 gom_header.charset.name);
175 if (gom_header.charset.version)
176 result |= gedcom_write_element_str(hndl, ELT_HEAD_CHAR_VERS, 0,
178 gom_header.charset.version);
179 if (gom_header.source.id)
180 result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR, 0, REC_HEAD,
181 gom_header.source.id);
182 if (gom_header.source.name)
183 result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_NAME, 0,
185 gom_header.source.name);
186 if (gom_header.source.version)
187 result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_VERS, 0,
189 gom_header.source.version);
190 if (gom_header.source.corporation.name)
191 result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_CORP, 0,
193 gom_header.source.corporation.name);
194 if (gom_header.source.corporation.address)
195 result |= write_address(hndl, ELT_HEAD_SOUR_CORP,
196 gom_header.source.corporation.address);
197 for (i = 0; i < 3 && gom_header.source.corporation.phone[i]; i++)
198 result |= gedcom_write_element_str(hndl, ELT_SUB_PHON, 0, ELT_HEAD_SOUR_CORP,
199 gom_header.source.corporation.phone[i]);
200 if (gom_header.source.data.name)
201 result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_DATA, 0,
203 gom_header.source.data.name);
204 if (gom_header.source.data.date)
205 result |= gedcom_write_element_date(hndl, ELT_HEAD_SOUR_DATA_DATE, 0,
207 gom_header.source.data.date);
208 if (gom_header.source.data.copyright)
209 result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_DATA_COPR, 0,
211 gom_header.source.data.copyright);
212 if (gom_header.destination)
213 result |= gedcom_write_element_str(hndl, ELT_HEAD_DEST, 0, REC_HEAD,
214 gom_header.destination);
216 result |= gedcom_write_element_date(hndl, ELT_HEAD_DATE, 0, REC_HEAD,
219 result |= gedcom_write_element_str(hndl, ELT_HEAD_DATE_TIME, 0,
220 ELT_HEAD_DATE, gom_header.time);
221 if (gom_header.submitter)
222 result |= gedcom_write_element_xref(hndl, ELT_HEAD_SUBM, 0, REC_HEAD,
223 gom_header.submitter);
224 if (gom_header.submission)
225 result |= gedcom_write_element_xref(hndl, ELT_HEAD_SUBN, 0, REC_HEAD,
226 gom_header.submission);
227 if (gom_header.filename)
228 result |= gedcom_write_element_str(hndl, ELT_HEAD_FILE, 0, REC_HEAD,
229 gom_header.filename);
230 if (gom_header.copyright)
231 result |= gedcom_write_element_str(hndl, ELT_HEAD_COPR, 0, REC_HEAD,
232 gom_header.copyright);
233 result |= gedcom_write_element_str(hndl, ELT_HEAD_GEDC, 0, REC_HEAD,
235 if (gom_header.gedcom.version)
236 result |= gedcom_write_element_str(hndl, ELT_HEAD_GEDC_VERS, 0,
238 gom_header.gedcom.version);
239 if (gom_header.gedcom.form)
240 result |= gedcom_write_element_str(hndl, ELT_HEAD_GEDC_FORM, 0,
242 gom_header.gedcom.form);
243 if (gom_header.language)
244 result |= gedcom_write_element_str(hndl, ELT_HEAD_LANG, 0,
246 gom_header.language);
247 if (gom_header.place_hierarchy) {
248 result |= gedcom_write_element_str(hndl, ELT_HEAD_PLAC, 0, REC_HEAD,
250 result |= gedcom_write_element_str(hndl, ELT_HEAD_PLAC_FORM, 0,
252 gom_header.place_hierarchy);
255 result |= gedcom_write_element_str(hndl, ELT_HEAD_NOTE, 0,
258 if (gom_header.extra)
259 result |= write_user_data(hndl, gom_header.extra);