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 = (struct note_sub *)malloc(sizeof(struct note_sub));
59 memset (note, 0, sizeof(struct note_sub));
60 if (GEDCOM_IS_XREF_PTR(parsed_value))
61 note->reference = GEDCOM_XREF_PTR(parsed_value);
63 switch (ctxt->ctxt_type) {
65 place_add_note(ctxt, note); break;
67 case ELT_SUB_FAM_EVT_EVEN:
68 case ELT_SUB_INDIV_ATTR:
69 case ELT_SUB_INDIV_RESI:
70 case ELT_SUB_INDIV_BIRT:
71 case ELT_SUB_INDIV_GEN:
72 case ELT_SUB_INDIV_ADOP:
73 case ELT_SUB_INDIV_EVEN:
74 event_add_note(ctxt, note); break;
76 citation_add_note(ctxt, note); break;
77 case ELT_SUB_MULTIM_OBJE:
78 multimedia_link_add_note(ctxt, note); break;
79 case ELT_SUB_LSS_SLGS:
80 case ELT_SUB_LIO_BAPL:
81 case ELT_SUB_LIO_SLGC:
82 lds_event_add_note(ctxt, note); break;
84 family_add_note(ctxt, note); break;
86 change_date_add_note(ctxt, note); break;
87 case ELT_SUB_PERS_NAME:
88 name_add_note(ctxt, note); break;
91 family_link_add_note(ctxt, note); break;
93 association_add_note(ctxt, note); break;
95 individual_add_note(ctxt, note); break;
97 multimedia_add_note(ctxt, note); break;
99 repository_add_note(ctxt, note); break;
101 source_add_note_to_data(ctxt, note); break;
103 source_add_note_to_repo(ctxt, note); break;
105 source_add_note(ctxt, note); break;
107 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
109 result = MAKE_GOM_CTXT(elt, note_sub, note);
113 return (Gedcom_ctxt)result;
116 void sub_note_end(_ELT_END_PARAMS_)
118 Gom_ctxt ctxt = (Gom_ctxt)self;
123 struct note_sub *note = SAFE_CTXT_CAST(note_sub, ctxt);
125 char *str = GEDCOM_STRING(parsed_value);
126 char *newvalue = strdup(str);
130 note->text = newvalue;
135 void note_sub_subscribe()
137 gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end);
140 void note_sub_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
142 struct note_sub *note = SAFE_CTXT_CAST(note_sub, ctxt);
144 LINK_CHAIN_ELT(source_citation, note->citation, cit);
147 void note_sub_add_user_data(Gom_ctxt ctxt, struct user_data* data)
149 struct note_sub *obj = SAFE_CTXT_CAST(note_sub, ctxt);
151 LINK_CHAIN_ELT(user_data, obj->extra, data);;
154 void note_sub_cleanup(struct note_sub* note)
157 SAFE_FREE(note->text);
158 DESTROY_CHAIN_ELTS(source_citation, note->citation, citation_cleanup);
159 DESTROY_CHAIN_ELTS(user_data, note->extra, user_data_cleanup);