New function gom_set_xref_value.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 5 Jan 2003 17:46:44 +0000 (17:46 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 5 Jan 2003 17:46:44 +0000 (17:46 +0000)
gom/gom_modify.c

index 3da2fa88e01c54f53dc820a5b269e97fb775e771..82205ffb4ca03cc02548ac0ed131aa9a748313b9 100644 (file)
@@ -77,3 +77,30 @@ char* gom_set_string_for_locale(char** data, const char* locale_str)
 
   return result;
 }
+
+struct xref_value* gom_set_xref_value(struct xref_value** data,
+                                     struct xref_value* newval)
+{
+  struct xref_value* result = NULL;
+  if (data) {
+    /* Unreference the old value if not NULL */
+    if (*data)
+      result = gedcom_unlink_xref((*data)->type, (*data)->string);
+    else
+      result = newval;
+
+    /* Reference the new value if not NULL */
+    if (result != NULL && newval) {
+      result = gedcom_link_xref(newval->type, newval->string);
+      /* On error, perform rollback to old value (guaranteed to work) */
+      if (result == NULL)
+       gedcom_link_xref((*data)->type, (*data)->string);
+    }
+    
+    if (result != NULL) {
+      *data = newval;
+      result = newval;
+    }
+  }
+  return result;
+}