1 /* Personal name 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
26 #include "personal_name.h"
27 #include "source_citation.h"
29 #include "individual.h"
33 #include "gom_internal.h"
35 Gedcom_ctxt sub_name_start(_ELT_PARAMS_)
37 Gom_ctxt ctxt = (Gom_ctxt)parent;
38 Gom_ctxt result = NULL;
41 struct personal_name *name
42 = (struct personal_name *)malloc(sizeof(struct personal_name));
46 memset (name, 0, sizeof(struct personal_name));
47 name->name = strdup(GEDCOM_STRING(parsed_value));
54 switch (ctxt->ctxt_type) {
56 ADDFUNC2(individual,personal_name)(ctxt, name); break;
58 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
60 result = MAKE_GOM_CTXT(elt, personal_name, name);
65 return (Gedcom_ctxt)result;
68 DEFINE_STRING_CB(personal_name, sub_name_npfx_start, prefix)
69 DEFINE_STRING_CB(personal_name, sub_name_givn_start, given)
70 DEFINE_STRING_CB(personal_name, sub_name_nick_start, nickname)
71 DEFINE_STRING_CB(personal_name, sub_name_spfx_start, surname_prefix)
72 DEFINE_STRING_CB(personal_name, sub_name_surn_start, surname)
73 DEFINE_STRING_CB(personal_name, sub_name_nsfx_start, suffix)
75 DEFINE_ADDFUNC2(personal_name, source_citation, citation)
76 DEFINE_ADDFUNC2(personal_name, note_sub, note)
77 DEFINE_ADDFUNC2(personal_name, user_data, extra)
81 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME, sub_name_start, def_elt_end);
82 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_NPFX, sub_name_npfx_start,
84 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_GIVN, sub_name_givn_start,
86 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_NICK, sub_name_nick_start,
88 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_SPFX, sub_name_spfx_start,
90 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_SURN, sub_name_surn_start,
92 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_NSFX, sub_name_nsfx_start,
96 void CLEANFUNC(personal_name)(struct personal_name* name)
99 SAFE_FREE(name->name);
100 SAFE_FREE(name->prefix);
101 SAFE_FREE(name->given);
102 SAFE_FREE(name->nickname);
103 SAFE_FREE(name->surname_prefix);
104 SAFE_FREE(name->surname);
105 SAFE_FREE(name->suffix);
106 DESTROY_CHAIN_ELTS(source_citation, name->citation);
107 DESTROY_CHAIN_ELTS(note_sub, name->note);
108 DESTROY_CHAIN_ELTS(user_data, name->extra);
112 int write_names(Gedcom_write_hndl hndl, int parent,
113 struct personal_name *name)
116 struct personal_name* obj;
120 for (obj = name; obj; obj = obj->next) {
121 result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME, 0,
124 result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_NPFX, 0,
125 parent, obj->prefix);
127 result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_GIVN, 0,
130 result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_NICK, 0,
131 parent, obj->nickname);
132 if (obj->surname_prefix)
133 result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_SPFX, 0,
134 parent, obj->surname_prefix);
136 result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_SURN, 0,
137 parent, obj->surname);
139 result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_NSFX, 0,
140 parent, obj->suffix);
142 result |= write_citations(hndl, ELT_SUB_PERS_NAME, obj->citation);
144 result |= write_note_subs(hndl, ELT_SUB_PERS_NAME, obj->note);
146 result |= write_user_data(hndl, obj->extra);