+
+struct xref_list* gom_add_xref(struct xref_list** data, const char* xref)
+{
+ struct xref_value* result = NULL;
+ struct xref_value* newval = NULL;
+ struct xref_list* xrl = NULL;
+
+ if (data && xref) {
+ newval = gedcom_get_by_xref(xref);
+ if (!newval)
+ gedcom_error(_("No record found for xref '%s'"), xref);
+ else {
+ result = gedcom_link_xref(newval->type, newval->string);
+ if (result != NULL) {
+ MAKE_CHAIN_ELT(xref_list, *data, xrl);
+ if (xrl) xrl->xref = newval;
+ }
+ }
+ }
+
+ return xrl;
+}
+
+int gom_remove_xref(struct xref_list** data, const char* xref)
+{
+ struct xref_value* xr = NULL;
+ int result = 1;
+
+ if (data && xref) {
+ xr = gedcom_get_by_xref(xref);
+ if (!xr)
+ gedcom_error(_("No record found for xref '%s'"), xref);
+ else {
+ struct xref_list* xrl = NULL;
+ for (xrl = *data ; xrl ; xrl = xrl->next) {
+ if (xrl->xref == xr) {
+ UNLINK_CHAIN_ELT(xref_list, *data, xrl);
+ gedcom_unlink_xref(xr->type, xr->string);
+ CLEANFUNC(xref_list)(xrl);
+ SAFE_FREE(xrl);
+ result = 0;
+ break;
+ }
+ }
+ if (result == 1)
+ gedcom_error(_("Xref '%s' to remove not part of chain"), xref);
+ }
+ }
+
+ return result;
+}