X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fmultimedia.c;h=9dbf90b5ee390d22015181cc7b534a05cfc14ac8;hb=1b7536d78e236978e83fbf8acc9f90e2141e13b0;hp=13c8b3eaee6db3953778fcd57bfd7269e01737d1;hpb=5b045164f4a11b1f4d709820e784e1ca77b61b3f;p=gedcom-parse.git diff --git a/gom/multimedia.c b/gom/multimedia.c index 13c8b3e..9dbf90b 100644 --- a/gom/multimedia.c +++ b/gom/multimedia.c @@ -34,31 +34,24 @@ struct multimedia* gom_first_multimedia = NULL; -REC_CB(multimedia, obje_start, make_multimedia_record) -GET_REC_BY_XREF(multimedia, XREF_OBJE, gom_get_multimedia_by_xref) -STRING_CB(multimedia, obje_form_start, form) -STRING_CB(multimedia, obje_titl_start, title) -NULL_CB(multimedia, obje_blob_start) -XREF_CB(multimedia, obje_obje_start, continued, make_multimedia_record) - -void obje_blob_end(_ELT_END_PARAMS_) -{ - Gom_ctxt ctxt = (Gom_ctxt)self; - - if (! ctxt) - NO_CONTEXT; - else { - struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt); - if (obj) { - char *str = GEDCOM_STRING(parsed_value); - char *newvalue = strdup(str); - if (! newvalue) - MEMORY_ERROR; - else - obj->data = newvalue; - } - } -} +DEFINE_MAKEFUNC(multimedia, gom_first_multimedia) +DEFINE_DESTROYFUNC(multimedia, gom_first_multimedia) +DEFINE_ADDFUNC(multimedia, XREF_OBJE) +DEFINE_DELETEFUNC(multimedia) +DEFINE_GETXREFFUNC(multimedia, XREF_OBJE) + +DEFINE_REC_CB(multimedia, obje_start) +DEFINE_STRING_CB(multimedia, obje_form_start, form) +DEFINE_STRING_CB(multimedia, obje_titl_start, title) +DEFINE_NULL_CB(multimedia, obje_blob_start) +DEFINE_STRING_END_CB(multimedia, obje_blob_end, data) +DEFINE_XREF_CB(multimedia, obje_obje_start, continued, multimedia) + +DEFINE_ADDFUNC2(multimedia, note_sub, note) +DEFINE_ADDFUNC2(multimedia, user_ref_number, ref) +DEFINE_ADDFUNC2(multimedia, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(multimedia, change_date, change_date) +DEFINE_ADDFUNC2_STR(multimedia, record_id) Gedcom_ctxt obje_blob_cont_start(_ELT_PARAMS_) { @@ -84,61 +77,35 @@ void multimedia_subscribe() gedcom_subscribe_to_element(ELT_OBJE_OBJE, obje_obje_start, def_elt_end); } -void multimedia_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct multimedia* obj = SAFE_CTXT_CAST(multimedia, ctxt); - if (obj) - LINK_CHAIN_ELT(note_sub, obj->note, note); -} - -void multimedia_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref) -{ - struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt); - if (obj) - LINK_CHAIN_ELT(user_ref_number, obj->ref, ref); -} - -void multimedia_set_record_id(Gom_ctxt ctxt, const char *rin) +void UNREFALLFUNC(multimedia)(struct multimedia *obj) { - struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt); if (obj) { - obj->record_id = strdup(rin); - if (! obj->record_id) MEMORY_ERROR; + UNREFALLFUNC(note_sub)(obj->note); + unref_xref_value(obj->continued); + UNREFALLFUNC(user_ref_number)(obj->ref); + UNREFALLFUNC(change_date)(obj->change_date); + UNREFALLFUNC(user_data)(obj->extra); } } -void multimedia_set_change_date(Gom_ctxt ctxt, struct change_date* chan) -{ - struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt); - if (obj) - obj->change_date = chan; -} - -void multimedia_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void multimedia_cleanup(struct multimedia* obj) +void CLEANFUNC(multimedia)(struct multimedia* obj) { if (obj) { SAFE_FREE(obj->xrefstr); SAFE_FREE(obj->form); SAFE_FREE(obj->title); - DESTROY_CHAIN_ELTS(note_sub, obj->note, note_sub_cleanup); + DESTROY_CHAIN_ELTS(note_sub, obj->note); SAFE_FREE(obj->data); - DESTROY_CHAIN_ELTS(user_ref_number, obj->ref, user_ref_cleanup); + DESTROY_CHAIN_ELTS(user_ref_number, obj->ref); SAFE_FREE(obj->record_id); - change_date_cleanup(obj->change_date); - DESTROY_CHAIN_ELTS(user_data, obj->extra, user_data_cleanup); + CLEANFUNC(change_date)(obj->change_date); + DESTROY_CHAIN_ELTS(user_data, obj->extra); } } void multimedias_cleanup() { - DESTROY_CHAIN_ELTS(multimedia, gom_first_multimedia, multimedia_cleanup); + DESTROY_CHAIN_ELTS(multimedia, gom_first_multimedia); } struct multimedia* gom_get_first_multimedia() @@ -146,13 +113,38 @@ struct multimedia* gom_get_first_multimedia() return gom_first_multimedia; } -struct multimedia* make_multimedia_record(const char* xrefstr) +int write_multimedia_recs(Gedcom_write_hndl hndl) { - struct multimedia* multi = NULL; - MAKE_CHAIN_ELT(multimedia, gom_first_multimedia, multi); - if (multi) { - multi->xrefstr = strdup(xrefstr); - if (! multi->xrefstr) MEMORY_ERROR; + int result = 0; + struct multimedia* obj; + + for (obj = gom_first_multimedia; obj; obj = obj->next) { + result |= gedcom_write_record_str(hndl, REC_OBJE, obj->xrefstr, NULL); + if (obj->form) + result |= gedcom_write_element_str(hndl, ELT_OBJE_FORM, 0, + REC_OBJE, obj->form); + if (obj->title) + result |= gedcom_write_element_str(hndl, ELT_OBJE_TITL, 0, + REC_OBJE, obj->title); + if (obj->note) + result |= write_note_subs(hndl, REC_OBJE, obj->note); + if (obj->data) + result |= gedcom_write_element_str(hndl, ELT_OBJE_BLOB, 0, + REC_OBJE, obj->data); + if (obj->continued) + result |= gedcom_write_element_xref(hndl, ELT_OBJE_OBJE, 0, + REC_OBJE, obj->continued); + if (obj->ref) + result |= write_user_refs(hndl, REC_OBJE, obj->ref); + if (obj->record_id) + result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_RIN, 0, + REC_OBJE, obj->record_id); + if (obj->change_date) + result |= write_change_date(hndl, REC_OBJE, obj->change_date); + if (obj->extra) + result |= write_user_data(hndl, obj->extra); } - return multi; + + return result; } +