1 /* Address 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 "gom_internal.h"
30 #include "repository.h"
31 #include "submitter.h"
36 Gedcom_ctxt sub_addr_start(_ELT_PARAMS_)
38 Gom_ctxt ctxt = (Gom_ctxt)parent;
39 Gom_ctxt result = NULL;
44 struct address *addr = (struct address *)malloc(sizeof(struct address));
48 memset (addr, 0, sizeof(struct address));
49 switch (ctxt->ctxt_type) {
50 case ELT_HEAD_SOUR_CORP:
51 ADDFUNC2_NOLIST(header,address)(ctxt, addr); break;
53 case ELT_SUB_FAM_EVT_EVEN:
54 case ELT_SUB_INDIV_ATTR:
55 case ELT_SUB_INDIV_RESI:
56 case ELT_SUB_INDIV_BIRT:
57 case ELT_SUB_INDIV_GEN:
58 case ELT_SUB_INDIV_ADOP:
59 case ELT_SUB_INDIV_EVEN:
60 ADDFUNC2_NOLIST(event,address)(ctxt, addr); break;
62 ADDFUNC2_NOLIST(repository,address)(ctxt, addr); break;
64 ADDFUNC2_NOLIST(submitter,address)(ctxt, addr); break;
66 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
68 result = MAKE_GOM_CTXT(elt, address, addr);
72 return (Gedcom_ctxt)result;
75 Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_)
77 Gom_ctxt ctxt = (Gom_ctxt)parent;
78 Gom_ctxt result = NULL;
82 result = make_gom_ctxt(elt, ctxt->ctxt_type, ctxt->ctxt_ptr);
84 return (Gedcom_ctxt)result;
87 DEFINE_STRING_END_CB(address, sub_addr_end, full_label)
88 DEFINE_STRING_CB(address, sub_addr_adr1_start, line1)
89 DEFINE_STRING_CB(address, sub_addr_adr2_start, line2)
90 DEFINE_STRING_CB(address, sub_addr_city_start, city)
91 DEFINE_STRING_CB(address, sub_addr_stae_start, state)
92 DEFINE_STRING_CB(address, sub_addr_post_start, postal)
93 DEFINE_STRING_CB(address, sub_addr_ctry_start, country)
95 DEFINE_ADDFUNC2(address, user_data, extra)
97 Gedcom_ctxt sub_phon_start(_ELT_PARAMS_)
99 Gom_ctxt ctxt = (Gom_ctxt)parent;
100 Gom_ctxt result = NULL;
105 char *str = GEDCOM_STRING(parsed_value);
106 switch (ctxt->ctxt_type) {
107 case ELT_HEAD_SOUR_CORP:
108 header_add_phone(ctxt, str); break;
109 case ELT_SUB_FAM_EVT:
110 case ELT_SUB_INDIV_ATTR:
111 case ELT_SUB_INDIV_RESI:
112 case ELT_SUB_INDIV_BIRT:
113 case ELT_SUB_INDIV_GEN:
114 case ELT_SUB_INDIV_ADOP:
115 case ELT_SUB_INDIV_EVEN:
116 event_add_phone(ctxt, str); break;
118 repository_add_phone(ctxt, str); break;
120 submitter_add_phone(ctxt, str); break;
122 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
124 result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
126 return (Gedcom_ctxt)result;
129 void address_subscribe()
131 gedcom_subscribe_to_element(ELT_SUB_ADDR, sub_addr_start, sub_addr_end);
132 gedcom_subscribe_to_element(ELT_SUB_ADDR_CONT,
133 sub_addr_cont_start, def_elt_end);
134 gedcom_subscribe_to_element(ELT_SUB_ADDR_ADR1,
135 sub_addr_adr1_start, def_elt_end);
136 gedcom_subscribe_to_element(ELT_SUB_ADDR_ADR2,
137 sub_addr_adr2_start, def_elt_end);
138 gedcom_subscribe_to_element(ELT_SUB_ADDR_CITY,
139 sub_addr_city_start, def_elt_end);
140 gedcom_subscribe_to_element(ELT_SUB_ADDR_STAE,
141 sub_addr_stae_start, def_elt_end);
142 gedcom_subscribe_to_element(ELT_SUB_ADDR_POST,
143 sub_addr_post_start, def_elt_end);
144 gedcom_subscribe_to_element(ELT_SUB_ADDR_CTRY,
145 sub_addr_ctry_start, def_elt_end);
146 gedcom_subscribe_to_element(ELT_SUB_PHON, sub_phon_start, def_elt_end);
149 void CLEANFUNC(address)(struct address *address)
152 SAFE_FREE(address->full_label);
153 SAFE_FREE(address->line1);
154 SAFE_FREE(address->line2);
155 SAFE_FREE(address->city);
156 SAFE_FREE(address->state);
157 SAFE_FREE(address->postal);
158 SAFE_FREE(address->country);
159 DESTROY_CHAIN_ELTS(user_data, address->extra);
164 int write_address(Gedcom_write_hndl hndl, int parent, struct address *address)
168 if (!address) return 1;
170 if (address->full_label)
171 result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR, 0, parent,
172 address->full_label);
174 result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_ADR1, 0,
175 ELT_SUB_ADDR, address->line1);
177 result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_ADR2, 0,
178 ELT_SUB_ADDR, address->line2);
180 result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_CITY, 0,
181 ELT_SUB_ADDR, address->city);
183 result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_STAE, 0,
184 ELT_SUB_ADDR, address->state);
186 result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_POST, 0,
187 ELT_SUB_ADDR, address->postal);
188 if (address->country)
189 result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_CTRY, 0,
190 ELT_SUB_ADDR, address->country);
192 result |= write_user_data(hndl, address->extra);