1 /* Source code for modifying 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 "utf8tools.h"
29 #include "gom_internal.h"
31 void gom_set_unknown(const char* unknown)
33 convert_set_unknown(unknown);
36 char* gom_get_string(char* data)
41 char* gom_get_string_for_locale(char* data, int* conversion_failures)
43 return convert_utf8_to_locale(gom_get_string(data), conversion_failures);
46 char* gom_set_string(char** data, const char* utf8_str)
51 if (!is_utf8_string(utf8_str)) {
52 gedcom_error(_("The input '%s' is not a valid UTF-8 string"), utf8_str);
55 newptr = strdup(utf8_str);
59 if (*data) free(*data);
68 char* gom_set_string_for_locale(char** data, const char* locale_str)
71 char* utf8_str = convert_locale_to_utf8(locale_str);
74 gedcom_error(_("The input '%s' is not a valid string for the locale"),
77 result = gom_set_string(data, utf8_str);
82 void CLEANFUNC(xref_list)(struct xref_list *obj)
85 DESTROY_CHAIN_ELTS(user_data, obj->extra);
89 struct xref_value* gom_set_xref(struct xref_value** data, const char* xref)
91 struct xref_value* result = NULL;
92 struct xref_value* newval = NULL;
96 newval = gedcom_get_by_xref(xref);
98 gedcom_error(_("No record found for xref '%s'"), xref);
101 /* Unreference the old value if not NULL */
103 result = gedcom_unlink_xref((*data)->type, (*data)->string);
107 /* Reference the new value if not NULL */
108 if (result != NULL && newval) {
109 result = gedcom_link_xref(newval->type, newval->string);
110 /* On error, perform rollback to old value (guaranteed to work) */
112 gedcom_link_xref((*data)->type, (*data)->string);
115 if (result != NULL) {
123 struct xref_list* gom_add_xref(struct xref_list** data, const char* xref)
125 struct xref_value* result = NULL;
126 struct xref_value* newval = NULL;
127 struct xref_list* xrl = NULL;
130 newval = gedcom_get_by_xref(xref);
132 gedcom_error(_("No record found for xref '%s'"), xref);
134 result = gedcom_link_xref(newval->type, newval->string);
135 if (result != NULL) {
136 MAKE_CHAIN_ELT(xref_list, *data, xrl);
137 if (xrl) xrl->xref = newval;
145 int gom_remove_xref(struct xref_list** data, const char* xref)
147 struct xref_value* xr = NULL;
151 xr = gedcom_get_by_xref(xref);
153 gedcom_error(_("No record found for xref '%s'"), xref);
155 struct xref_list* xrl = NULL;
156 for (xrl = *data ; xrl ; xrl = xrl->next) {
157 if (xrl->xref == xr) {
158 UNLINK_CHAIN_ELT(xref_list, *data, xrl);
159 gedcom_unlink_xref(xr->type, xr->string);
160 CLEANFUNC(xref_list)(xrl);
167 gedcom_error(_("Xref '%s' to remove not part of chain"), xref);