- int result;
- struct date_value* dval = gedcom_new_date_value(NULL);
- dval->type = DV_NO_MODIFIER;
- dval->date1.cal = CAL_GREGORIAN;
- dval->date1.day = tm_ptr->tm_mday;
- dval->date1.month = tm_ptr->tm_mon + 1;
- dval->date1.year = tm_ptr->tm_year + 1900;
- result = gedcom_normalize_date(DI_FROM_NUMBERS, dval);
-
- if (result == 0) {
- if (*dv) free(*dv);
- *dv = dval;
+ if (xref)
+ gedcom_unlink_xref(xref->type, xref->string);
+}
+
+void UNREFALLFUNC(xref_list)(struct xref_list* obj)
+{
+ if (obj) {
+ struct xref_list* runner;
+ for (runner = obj; runner; runner = runner->next) {
+ unref_xref_value(runner->xref);
+ UNREFALLFUNC(user_data)(runner->extra);
+ }
+ }
+}
+
+void CLEANFUNC(xref_list)(struct xref_list *obj)
+{
+ if (obj) {
+ DESTROY_CHAIN_ELTS(user_data, obj->extra);
+ }
+}
+
+struct xref_value* gom_set_xref(struct xref_value** data, const char* xref)
+{
+ struct xref_value* result = NULL;
+ struct xref_value* newval = NULL;
+
+ if (data) {
+ if (xref) {
+ newval = gedcom_get_by_xref(xref);
+ if (!newval)
+ gedcom_error(_("No record found for xref '%s'"), xref);
+ }
+
+ /* 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;
+ }