1 /* Implementation of the interface to applications.
2 Copyright (C) 2001, 2002 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
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
24 #include "gedcom_internal.h"
25 #include "interface.h"
27 static Gedcom_rec_start_cb record_start_callback [NR_OF_RECS] = { NULL };
28 static Gedcom_rec_end_cb record_end_callback [NR_OF_RECS] = { NULL };
29 static Gedcom_elt_start_cb element_start_callback[NR_OF_ELTS] = { NULL };
30 static Gedcom_elt_end_cb element_end_callback [NR_OF_ELTS] = { NULL };
31 static Gedcom_def_cb default_cb = NULL;
33 void gedcom_set_default_callback(Gedcom_def_cb func)
36 gedcom_error(_("Internal error: Duplicate registration for default callback"));
40 void gedcom_subscribe_to_record(Gedcom_rec rec,
41 Gedcom_rec_start_cb cb_start,
42 Gedcom_rec_end_cb cb_end)
44 if (record_start_callback[rec] || record_end_callback[rec])
45 gedcom_error(_("Internal error: Duplicate registration for record type %d"), rec);
47 record_start_callback[rec] = cb_start;
48 record_end_callback[rec] = cb_end;
52 void gedcom_subscribe_to_element(Gedcom_elt elt,
53 Gedcom_elt_start_cb cb_start,
54 Gedcom_elt_end_cb cb_end)
56 if (element_start_callback[elt] || element_end_callback[elt])
57 gedcom_error(_("Internal error: Duplicate registration for element type %d"), elt);
59 element_start_callback[elt] = cb_start;
60 element_end_callback[elt] = cb_end;
64 Gedcom_ctxt start_record(Gedcom_rec rec,
65 int level, Gedcom_val xref, struct tag_struct tag,
66 char *raw_value, Gedcom_val parsed_value)
68 Gedcom_rec_start_cb cb = record_start_callback[rec];
70 return (*cb)(rec, level, xref, tag.string, raw_value, tag.value,
76 void end_record(Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value)
78 Gedcom_rec_end_cb cb = record_end_callback[rec];
80 (*cb)(rec, self, parsed_value);
83 Gedcom_ctxt start_element(Gedcom_elt elt, Gedcom_ctxt parent,
84 int level, struct tag_struct tag, char *raw_value,
85 Gedcom_val parsed_value)
87 Gedcom_elt_start_cb cb = element_start_callback[elt];
88 Gedcom_ctxt ctxt = parent;
90 ctxt = (*cb)(elt, parent, level, tag.string, raw_value,
91 tag.value, parsed_value);
92 else if (default_cb != NULL && parent != NULL)
93 (*default_cb)(elt, parent, level, tag.string, raw_value, tag.value);
97 void end_element(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
98 Gedcom_val parsed_value)
100 Gedcom_elt_end_cb cb = element_end_callback[elt];
102 (*cb)(elt, parent, self, parsed_value);
105 const char* val_type_str[] = { N_("null value"),
106 N_("character string"),
108 N_("cross-reference") };
110 void gedcom_cast_error(const char* file, int line,
111 Gedcom_val_type tried_type,
112 Gedcom_val_type real_type)
115 (_("Wrong cast of value in file %s, at line %d: %s instead of %s"),
116 file, line, _(val_type_str[tried_type]), _(val_type_str[real_type]));