X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fgom_modify.c;h=82205ffb4ca03cc02548ac0ed131aa9a748313b9;hb=d2d823fd4fe80162765029e5bc29f9b4f6f968f5;hp=bc65a3a380412b2386af7e855cd1685ed7f4430b;hpb=08936924a7a4b1541ee5f9778cae6bffef1767b3;p=gedcom-parse.git diff --git a/gom/gom_modify.c b/gom/gom_modify.c index bc65a3a..82205ff 100644 --- a/gom/gom_modify.c +++ b/gom/gom_modify.c @@ -23,7 +23,6 @@ #include #include -#include #include "utf8tools.h" #include "gom.h" #include "gom_internal.h" @@ -79,33 +78,29 @@ char* gom_set_string_for_locale(char** data, const char* locale_str) return result; } -int update_date(struct date_value** dv, struct tm* tm_ptr) +struct xref_value* gom_set_xref_value(struct xref_value** data, + struct xref_value* newval) { - 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; + 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; } - -int update_time(char** tv, struct tm* tm_ptr) -{ - char tval[16]; - sprintf(tval, "%02d:%02d:%02d", - tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec); - - if (gom_set_string(tv, tval)) - return 0; - else - return 1; -} -