1 /* Internals for building 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
25 #include "gom_internal.h"
27 const char* ctxt_names[] =
31 "header", "submission", "submitter", "family", "individual",
32 "multimedia", "note", "repository", "source", "user_rec",
34 "address", "event", "place", "source_citation", "text",
35 "note_sub", "multimedia_link", "lds_event", "user_ref_number",
36 "change_date", "personal_name", "family_link", "pedigree",
37 "association", "source_event", "source_description"
40 Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr)
42 Gom_ctxt ctxt = (Gom_ctxt)malloc(sizeof(struct Gom_ctxt_struct));
46 ctxt->ctxt_type = ctxt_type;
47 ctxt->obj_type = obj_type;
48 ctxt->ctxt_ptr = ctxt_ptr;
53 void NULL_DESTROY(void* anything UNUSED)
57 void destroy_gom_ctxt(Gom_ctxt ctxt)
62 void gom_cast_error(const char* file, int line,
63 OBJ_TYPE expected, OBJ_TYPE found)
65 const char* expected_name = "<out-of-bounds>";
66 const char* found_name = "<out-of-bounds>";
67 if (expected < T_LAST)
68 expected_name = ctxt_names[expected];
70 found_name = ctxt_names[found];
72 "Wrong gom ctxt cast at %s, line %d: expected %s, found %s\n",
73 file, line, expected_name, found_name);
77 void gom_mem_error(const char *filename, int line)
79 gedcom_error(_("Could not allocate memory at %s, %d"), filename, line);
82 void gom_xref_already_in_use(const char *xrefstr)
84 gedcom_error(_("Cross-reference key '%s' is already in use"), xrefstr);
87 void gom_unexpected_context(const char* file, int line, OBJ_TYPE found)
89 const char* found_name = "<out-of-bounds>";
91 found_name = ctxt_names[found];
92 gedcom_warning(_("Internal error: Unexpected context at %s, line %d: %s"),
93 file, line, found_name);
96 void gom_no_context(const char* file, int line)
98 gedcom_warning(_("Internal error: No context at %s, line %d"),
102 void gom_move_error(const char* type)
104 gedcom_warning(_("Could not move struct of type %s"), type);
107 void gom_find_error(const char* type)
109 gedcom_warning(_("Could not find struct of type %s in chain"), type);
112 void def_rec_end(Gedcom_rec rec UNUSED, Gedcom_ctxt self,
113 Gedcom_val parsed_value UNUSED)
115 Gom_ctxt ctxt = (Gom_ctxt)self;
116 destroy_gom_ctxt(ctxt);
119 /* TODO: do this in a way so that elements out of context can be handled */
120 void def_elt_end(Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED,
121 Gedcom_ctxt self, Gedcom_val parsed_value UNUSED)
123 Gom_ctxt ctxt = (Gom_ctxt)self;
124 destroy_gom_ctxt(ctxt);