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 struct address *addr = (struct address *)malloc(sizeof(struct address));
40 char *str = GEDCOM_STRING(parsed_value);
42 memset (addr, 0, sizeof(struct address));
43 addr->full_label = strdup(str);
46 switch (ctxt->ctxt_type) {
47 case ELT_HEAD_SOUR_CORP:
48 header_add_address(ctxt, addr); break;
50 case ELT_SUB_FAM_EVT_EVEN:
51 case ELT_SUB_INDIV_ATTR:
52 case ELT_SUB_INDIV_RESI:
53 case ELT_SUB_INDIV_BIRT:
54 case ELT_SUB_INDIV_GEN:
55 case ELT_SUB_INDIV_ADOP:
56 case ELT_SUB_INDIV_EVEN:
57 event_add_address(ctxt, addr); break;
59 repository_add_address(ctxt, addr); break;
61 submitter_add_address(ctxt, addr); break;
63 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
67 return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, address, addr);
70 Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_)
72 Gom_ctxt ctxt = (Gom_ctxt)parent;
73 struct address *addr = SAFE_CTXT_CAST(address, ctxt);
74 char *str = GEDCOM_STRING(parsed_value);
75 addr->full_label = concat_strings (WITH_NL, addr->full_label, str);
76 return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, address, addr);
79 STRING_CB(address, sub_addr_adr1_start, line1)
80 STRING_CB(address, sub_addr_adr2_start, line2)
81 STRING_CB(address, sub_addr_city_start, city)
82 STRING_CB(address, sub_addr_stae_start, state)
83 STRING_CB(address, sub_addr_post_start, postal)
84 STRING_CB(address, sub_addr_ctry_start, country)
86 Gedcom_ctxt sub_phon_start(_ELT_PARAMS_)
88 Gom_ctxt ctxt = (Gom_ctxt)parent;
91 char *str = GEDCOM_STRING(parsed_value);
92 switch (ctxt->ctxt_type) {
93 case ELT_HEAD_SOUR_CORP:
94 header_add_phone(ctxt, str); break;
96 case ELT_SUB_INDIV_ATTR:
97 case ELT_SUB_INDIV_RESI:
98 case ELT_SUB_INDIV_BIRT:
99 case ELT_SUB_INDIV_GEN:
100 case ELT_SUB_INDIV_ADOP:
101 case ELT_SUB_INDIV_EVEN:
102 event_add_phone(ctxt, str); break;
104 repository_add_phone(ctxt, str); break;
106 submitter_add_phone(ctxt, str); break;
108 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
110 return (Gedcom_ctxt) make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
113 return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, NULL, NULL);
116 void address_subscribe()
118 gedcom_subscribe_to_element(ELT_SUB_ADDR, sub_addr_start, def_elt_end);
119 gedcom_subscribe_to_element(ELT_SUB_ADDR_CONT,
120 sub_addr_cont_start, def_elt_end);
121 gedcom_subscribe_to_element(ELT_SUB_ADDR_ADR1,
122 sub_addr_adr1_start, def_elt_end);
123 gedcom_subscribe_to_element(ELT_SUB_ADDR_ADR2,
124 sub_addr_adr2_start, def_elt_end);
125 gedcom_subscribe_to_element(ELT_SUB_ADDR_CITY,
126 sub_addr_city_start, def_elt_end);
127 gedcom_subscribe_to_element(ELT_SUB_ADDR_STAE,
128 sub_addr_stae_start, def_elt_end);
129 gedcom_subscribe_to_element(ELT_SUB_ADDR_POST,
130 sub_addr_post_start, def_elt_end);
131 gedcom_subscribe_to_element(ELT_SUB_ADDR_CTRY,
132 sub_addr_ctry_start, def_elt_end);
133 gedcom_subscribe_to_element(ELT_SUB_PHON, sub_phon_start, def_elt_end);
136 void address_add_user_data(Gom_ctxt ctxt, struct user_data* data)
138 struct address *obj = SAFE_CTXT_CAST(address, ctxt);
139 LINK_CHAIN_ELT(user_data, obj->extra, data)
142 void address_cleanup(struct address *address)
145 SAFE_FREE(address->full_label);
146 SAFE_FREE(address->line1);
147 SAFE_FREE(address->line2);
148 SAFE_FREE(address->city);
149 SAFE_FREE(address->state);
150 SAFE_FREE(address->postal);
151 SAFE_FREE(address->country);
152 DESTROY_CHAIN_ELTS(user_data, address->extra, user_data_cleanup)