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
30 #include "source_citation.h"
31 #include "multimedia_link.h"
32 #include "lds_event.h"
34 #include "change_date.h"
35 #include "personal_name.h"
36 #include "family_link.h"
37 #include "association.h"
38 #include "individual.h"
39 #include "multimedia.h"
40 #include "repository.h"
45 #include "gom_internal.h"
47 Gedcom_ctxt sub_note_start(_ELT_PARAMS_)
49 Gom_ctxt ctxt = (Gom_ctxt)parent;
50 Gom_ctxt result = NULL;
55 struct note_sub *note = SUB_MAKEFUNC(note_sub)();
57 int type = ctxt_type(ctxt);
58 if (GEDCOM_IS_XREF_PTR(parsed_value))
59 note->reference = GEDCOM_XREF_PTR(parsed_value);
63 ADDFUNC2(place,note_sub)(ctxt, note); break;
65 case ELT_SUB_FAM_EVT_EVEN:
66 case ELT_SUB_INDIV_ATTR:
67 case ELT_SUB_INDIV_RESI:
68 case ELT_SUB_INDIV_BIRT:
69 case ELT_SUB_INDIV_GEN:
70 case ELT_SUB_INDIV_ADOP:
71 case ELT_SUB_INDIV_EVEN:
72 ADDFUNC2(event,note_sub)(ctxt, note); break;
74 ADDFUNC2(source_citation,note_sub)(ctxt, note); break;
75 case ELT_SUB_MULTIM_OBJE:
76 ADDFUNC2(multimedia_link,note_sub)(ctxt, note); break;
77 case ELT_SUB_LSS_SLGS:
78 case ELT_SUB_LIO_BAPL:
79 case ELT_SUB_LIO_SLGC:
80 ADDFUNC2(lds_event,note_sub)(ctxt, note); break;
82 ADDFUNC2(family,note_sub)(ctxt, note); break;
84 ADDFUNC2(change_date,note_sub)(ctxt, note); break;
85 case ELT_SUB_PERS_NAME:
86 ADDFUNC2(personal_name,note_sub)(ctxt, note); break;
89 ADDFUNC2(family_link,note_sub)(ctxt, note); break;
91 ADDFUNC2(association,note_sub)(ctxt, note); break;
93 ADDFUNC2(individual,note_sub)(ctxt, note); break;
95 ADDFUNC2(multimedia,note_sub)(ctxt, note); break;
97 ADDFUNC2(repository,note_sub)(ctxt, note); break;
99 source_add_note_to_data(ctxt, note); break;
101 source_add_note_to_repo(ctxt, note); break;
103 ADDFUNC2(source,note_sub)(ctxt, note); break;
105 UNEXPECTED_CONTEXT(type);
107 result = MAKE_GOM_CTXT(elt, note_sub, note);
111 return (Gedcom_ctxt)result;
114 void sub_note_end(_ELT_END_PARAMS_)
116 if (GEDCOM_IS_STRING(parsed_value)) {
117 Gom_ctxt ctxt = (Gom_ctxt)self;
121 struct note_sub *obj = SAFE_CTXT_CAST(note_sub, ctxt);
123 char *str = GEDCOM_STRING(parsed_value);
124 char *newvalue = strdup(str);
128 obj->text = newvalue;
130 def_elt_end(elt, parent, self, parsed_value);
135 DEFINE_SUB_MAKEFUNC(note_sub)
136 DEFINE_SUB_ADDFUNC(note_sub)
137 DEFINE_SUB_FINDFUNC(note_sub)
138 DEFINE_SUB_REMOVEFUNC(note_sub)
139 DEFINE_SUB_MOVEFUNC(note_sub)
141 DEFINE_ADDFUNC2(note_sub, source_citation, citation)
142 DEFINE_ADDFUNC2(note_sub, user_data, extra)
144 void note_sub_subscribe()
146 gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end);
149 void UNREFALLFUNC(note_sub)(struct note_sub* obj)
152 struct note_sub* runner;
153 for (runner = obj; runner; runner = runner->next) {
154 unref_xref_value(runner->reference);
155 UNREFALLFUNC(source_citation)(runner->citation);
156 UNREFALLFUNC(user_data)(runner->extra);
161 void CLEANFUNC(note_sub)(struct note_sub* note)
164 SAFE_FREE(note->text);
165 DESTROY_CHAIN_ELTS(source_citation, note->citation);
166 DESTROY_CHAIN_ELTS(user_data, note->extra);
170 int write_note_subs(Gedcom_write_hndl hndl, int parent, struct note_sub* note)
173 struct note_sub* obj;
177 for (obj = note; obj; obj = obj->next) {
178 if (obj->reference) {
179 result |= gedcom_write_element_xref(hndl, ELT_SUB_NOTE, 0,
180 parent, obj->reference);
183 result |= gedcom_write_element_str(hndl, ELT_SUB_NOTE, 0,
187 result |= write_citations(hndl, ELT_SUB_NOTE, obj->citation);
189 result |= write_user_data(hndl, obj->extra);