1 /* Note 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.
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
27 #include "source_citation.h"
31 #include "change_date.h"
36 #include "gom_internal.h"
38 struct note* gom_first_note = NULL;
40 Gedcom_ctxt note_start(_REC_PARAMS_)
42 Gom_ctxt result = NULL;
43 struct xref_value* xr = GEDCOM_XREF_PTR(xref);
44 struct note* note = (struct note*) xr->object;
46 note = make_note_record(xr->string);
47 xr->object = (Gedcom_ctxt) note;
50 note->text = strdup(GEDCOM_STRING(parsed_value));
54 result = MAKE_GOM_CTXT(rec, note, xr->object);
56 return (Gedcom_ctxt)result;
59 GET_REC_BY_XREF(note, XREF_NOTE, gom_get_note_by_xref)
61 Gedcom_ctxt sub_cont_conc_start(_ELT_PARAMS_)
63 Gom_ctxt ctxt = (Gom_ctxt)parent;
64 Gom_ctxt result = NULL;
69 char *str = GEDCOM_STRING(parsed_value);
70 NL_TYPE type = (elt == ELT_SUB_CONT ? WITH_NL : WITHOUT_NL);
71 switch (ctxt->ctxt_type) {
73 header_add_to_note(type, ctxt, str); break;
75 citation_add_to_desc(type, ctxt, str); break;
76 case ELT_SUB_SOUR_TEXT:
77 citation_add_to_text(type, ctxt, str); break;
79 note_sub_add_to_note(type, ctxt, str); break;
81 note_add_to_note(type, ctxt, str); break;
86 source_add_to_value(type, ctxt, str); break;
88 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
90 result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
92 return (Gedcom_ctxt)result;
97 gedcom_subscribe_to_record(REC_NOTE, note_start, def_rec_end);
98 gedcom_subscribe_to_element(ELT_SUB_CONT, sub_cont_conc_start, def_elt_end);
99 gedcom_subscribe_to_element(ELT_SUB_CONC, sub_cont_conc_start, def_elt_end);
102 void note_add_to_note(NL_TYPE type, Gom_ctxt ctxt, const char* str)
104 struct note *note = SAFE_CTXT_CAST(note, ctxt);
106 char *newvalue = concat_strings (type, note->text, str);
108 note->text = newvalue;
114 void note_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
116 struct note *note = SAFE_CTXT_CAST(note, ctxt);
118 LINK_CHAIN_ELT(source_citation, note->citation, cit);
121 void note_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
123 struct note *note = SAFE_CTXT_CAST(note, ctxt);
125 LINK_CHAIN_ELT(user_ref_number, note->ref, ref);
128 void note_set_record_id(Gom_ctxt ctxt, const char *rin)
130 struct note *note = SAFE_CTXT_CAST(note, ctxt);
132 note->record_id = strdup(rin);
133 if (! note->record_id) MEMORY_ERROR;
137 void note_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
139 struct note *note = SAFE_CTXT_CAST(note, ctxt);
141 note->change_date = chan;
144 void note_add_user_data(Gom_ctxt ctxt, struct user_data* data)
146 struct note *obj = SAFE_CTXT_CAST(note, ctxt);
148 LINK_CHAIN_ELT(user_data, obj->extra, data);
151 void note_cleanup(struct note* note)
154 SAFE_FREE(note->xrefstr);
155 SAFE_FREE(note->text);
156 DESTROY_CHAIN_ELTS(source_citation, note->citation, citation_cleanup);
157 DESTROY_CHAIN_ELTS(user_ref_number, note->ref, user_ref_cleanup);
158 SAFE_FREE(note->record_id);
159 change_date_cleanup(note->change_date);
160 DESTROY_CHAIN_ELTS(user_data, note->extra, user_data_cleanup);
166 DESTROY_CHAIN_ELTS(note, gom_first_note, note_cleanup);
169 struct note* gom_get_first_note()
171 return gom_first_note;
174 struct note* make_note_record(const char* xrefstr)
176 struct note* note = NULL;
177 MAKE_CHAIN_ELT(note, gom_first_note, note);
179 note->xrefstr = strdup(xrefstr);
180 if (! note->xrefstr) MEMORY_ERROR;