Only try to delete address if present.
[gedcom-parse.git] / gom / gom_internal.h
1 /* General header for 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.
5
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.
10
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.
15
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
19    02111-1307 USA.  */
20
21 /* $Id$ */
22 /* $Name$ */
23
24 #ifndef __GOM_INTERNAL_H
25 #define __GOM_INTERNAL_H
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include <libintl.h>
30 #include <time.h>
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 #include "gom.h"
35 #include "gedcom.h"
36       
37 #define _(string) dgettext(PACKAGE, string)
38 #define N_(string) (string)
39
40 #ifdef __GNUC__
41 #define UNUSED __attribute__((unused))
42 #else
43 #define UNUSED
44 #endif
45
46 typedef enum {
47   T_NULL,
48   
49   T_header, T_submission, T_submitter, T_family, T_individual,
50   T_multimedia, T_note, T_repository, T_source, T_user_rec,
51   
52   T_address, T_event, T_place, T_source_citation, T_text,
53   T_note_sub, T_multimedia_link, T_lds_event, T_user_ref_number,
54   T_change_date, T_personal_name, T_family_link, T_pedigree,
55   T_association, T_source_event, T_source_description
56 } OBJ_TYPE;
57
58 /* Assumptions for context:
59     - In case of error, NULL is passed as context
60     - If not NULL, the ctxt_ptr of the context is not NULL also
61     - UNEXPECTED_CONTEXT is not treated as an error, but as a warning
62 */
63
64 struct Gom_ctxt_struct {
65   int ctxt_type;
66   OBJ_TYPE obj_type;
67   void* ctxt_ptr;
68 };
69
70 typedef struct Gom_ctxt_struct *Gom_ctxt;
71
72 Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr);
73 void destroy_gom_ctxt(Gom_ctxt ctxt);
74 void gom_cast_error(const char* file, int line,
75                     OBJ_TYPE expected, OBJ_TYPE found);
76 void gom_no_context(const char* file, int line);
77 void gom_unexpected_context(const char* file, int line, OBJ_TYPE found);
78 void gom_xref_already_in_use(const char *xrefstr);
79 void gom_move_error(const char* type);
80 void gom_find_error(const char* type);
81 void unref_xref_value(struct xref_value *xref);
82
83 int gom_write_xref_list(Gedcom_write_hndl hndl,
84                         Gedcom_elt elt, int tag, int parent_rec_or_elt,
85                         struct xref_list* val);
86
87 #define MAKE_GOM_CTXT(CTXT_TYPE, STRUCTTYPE, CTXT_PTR)                        \
88   make_gom_ctxt(CTXT_TYPE, T_ ## STRUCTTYPE, CTXT_PTR)
89
90 #define SAFE_CTXT_CAST(STRUCTTYPE, VAL)                                       \
91   (((VAL)->obj_type == T_ ## STRUCTTYPE) ?                                    \
92    (VAL)->ctxt_ptr :                                                          \
93    (gom_cast_error(__FILE__, __LINE__, T_ ## STRUCTTYPE, (VAL)->obj_type),    \
94     (VAL)->ctxt_ptr))
95
96 #define SAFE_FREE(PTR)                                                        \
97   if (PTR) {                                                                  \
98     free(PTR);                                                                \
99     PTR = NULL;                                                               \
100   }
101
102 #define UNEXPECTED_CONTEXT(CTXT_TYPE)                                         \
103   gom_unexpected_context(__FILE__, __LINE__, CTXT_TYPE)
104
105 #define NO_CONTEXT                                                            \
106   gom_no_context(__FILE__, __LINE__)
107
108 void gom_mem_error(const char *filename, int line);
109
110 #define MEMORY_ERROR gom_mem_error(__FILE__, __LINE__)
111
112 void def_rec_end(Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value);
113 void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent,
114                  Gedcom_ctxt self, Gedcom_val parsed_value);
115 void set_xref_type(struct xref_value *xr, const char* str);
116
117 int  update_date(struct date_value** dv, struct tm* tm_ptr);
118 int  update_time(char** tv, struct tm* tm_ptr);
119
120 void NULL_DESTROY(void* anything);
121
122 #include "func_template.h"
123
124 DECLARE_UNREFALLFUNC(xref_list);
125 DECLARE_CLEANFUNC(xref_list);
126   
127 #endif /* __GOM_INTERNAL_H */