From: Peter Verthez Date: Fri, 3 Jan 2003 18:47:31 +0000 (+0000) Subject: Added functions to add and remove records. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=72689522e287ca3b2231e7d8881f0fe5bea48f15;p=gedcom-parse.git Added functions to add and remove records. Factor out more common code (to func_template.h). --- diff --git a/gom/Makefile.am b/gom/Makefile.am index 7a3db99..13156a8 100644 --- a/gom/Makefile.am +++ b/gom/Makefile.am @@ -56,7 +56,8 @@ noinst_HEADERS = header.h \ source_event.h \ source_description.h \ user_rec.h \ - gom_internal.h + gom_internal.h \ + func_template.h libgedcom_gom_la_LDFLAGS = -export-dynamic -version-info $(LIBVERSION) \ -L../utf8/.libs diff --git a/gom/address.c b/gom/address.c index 6c0332a..916737a 100644 --- a/gom/address.c +++ b/gom/address.c @@ -48,7 +48,7 @@ Gedcom_ctxt sub_addr_start(_ELT_PARAMS_) memset (addr, 0, sizeof(struct address)); switch (ctxt->ctxt_type) { case ELT_HEAD_SOUR_CORP: - header_add_address(ctxt, addr); break; + ADDFUNC2_NOLIST(header,address)(ctxt, addr); break; case ELT_SUB_FAM_EVT: case ELT_SUB_FAM_EVT_EVEN: case ELT_SUB_INDIV_ATTR: @@ -57,11 +57,11 @@ Gedcom_ctxt sub_addr_start(_ELT_PARAMS_) case ELT_SUB_INDIV_GEN: case ELT_SUB_INDIV_ADOP: case ELT_SUB_INDIV_EVEN: - event_add_address(ctxt, addr); break; + ADDFUNC2_NOLIST(event,address)(ctxt, addr); break; case REC_REPO: - repository_add_address(ctxt, addr); break; + ADDFUNC2_NOLIST(repository,address)(ctxt, addr); break; case REC_SUBM: - submitter_add_address(ctxt, addr); break; + ADDFUNC2_NOLIST(submitter,address)(ctxt, addr); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -84,13 +84,15 @@ Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_END_CB(address, sub_addr_end, full_label) -STRING_CB(address, sub_addr_adr1_start, line1) -STRING_CB(address, sub_addr_adr2_start, line2) -STRING_CB(address, sub_addr_city_start, city) -STRING_CB(address, sub_addr_stae_start, state) -STRING_CB(address, sub_addr_post_start, postal) -STRING_CB(address, sub_addr_ctry_start, country) +DEFINE_STRING_END_CB(address, sub_addr_end, full_label) +DEFINE_STRING_CB(address, sub_addr_adr1_start, line1) +DEFINE_STRING_CB(address, sub_addr_adr2_start, line2) +DEFINE_STRING_CB(address, sub_addr_city_start, city) +DEFINE_STRING_CB(address, sub_addr_stae_start, state) +DEFINE_STRING_CB(address, sub_addr_post_start, postal) +DEFINE_STRING_CB(address, sub_addr_ctry_start, country) + +DEFINE_ADDFUNC2(address, user_data, extra) Gedcom_ctxt sub_phon_start(_ELT_PARAMS_) { @@ -144,14 +146,7 @@ void address_subscribe() gedcom_subscribe_to_element(ELT_SUB_PHON, sub_phon_start, def_elt_end); } -void address_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct address *obj = SAFE_CTXT_CAST(address, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void address_cleanup(struct address *address) +void CLEANFUNC(address)(struct address *address) { if (address) { SAFE_FREE(address->full_label); @@ -161,7 +156,7 @@ void address_cleanup(struct address *address) SAFE_FREE(address->state); SAFE_FREE(address->postal); SAFE_FREE(address->country); - DESTROY_CHAIN_ELTS(user_data, address->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, address->extra); } SAFE_FREE(address); } diff --git a/gom/address.h b/gom/address.h index cc814bb..bff2e3a 100644 --- a/gom/address.h +++ b/gom/address.h @@ -27,8 +27,9 @@ #include "gom.h" void address_subscribe(); -void address_cleanup(struct address *address); -void address_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_address(Gedcom_write_hndl hndl, int parent, struct address *address); +DECLARE_CLEANFUNC(address); +DECLARE_ADDFUNC2(address, user_data); + #endif /* __ADDRESS_H */ diff --git a/gom/association.c b/gom/association.c index 2a5bf39..7c7ec68 100644 --- a/gom/association.c +++ b/gom/association.c @@ -50,7 +50,7 @@ Gedcom_ctxt sub_assoc_start(_ELT_PARAMS_) switch (ctxt->ctxt_type) { case REC_INDI: - individual_add_association(ctxt, assoc); + ADDFUNC2(individual,association)(ctxt, assoc); default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -61,7 +61,11 @@ Gedcom_ctxt sub_assoc_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(association, sub_assoc_rela_start, relation) +DEFINE_STRING_CB(association, sub_assoc_rela_start, relation) + +DEFINE_ADDFUNC2(association, note_sub, note) +DEFINE_ADDFUNC2(association, source_citation, citation) +DEFINE_ADDFUNC2(association, user_data, extra) Gedcom_ctxt sub_assoc_type_start(_ELT_PARAMS_) { @@ -95,35 +99,14 @@ void association_subscribe() def_elt_end); } -void association_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct association *assoc = SAFE_CTXT_CAST(association, ctxt); - if (assoc) - LINK_CHAIN_ELT(note_sub, assoc->note, note); -} - -void association_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct association *assoc = SAFE_CTXT_CAST(association, ctxt); - if (assoc) - LINK_CHAIN_ELT(source_citation, assoc->citation, cit); -} - -void association_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct association *obj = SAFE_CTXT_CAST(association, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void association_cleanup(struct association* assoc) +void CLEANFUNC(association)(struct association* assoc) { if (assoc) { SAFE_FREE(assoc->type); SAFE_FREE(assoc->relation); - DESTROY_CHAIN_ELTS(note_sub, assoc->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(source_citation, assoc->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(user_data, assoc->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(note_sub, assoc->note); + DESTROY_CHAIN_ELTS(source_citation, assoc->citation); + DESTROY_CHAIN_ELTS(user_data, assoc->extra); } } diff --git a/gom/association.h b/gom/association.h index e688d09..c649066 100644 --- a/gom/association.h +++ b/gom/association.h @@ -28,11 +28,12 @@ #include "gom_internal.h" void association_subscribe(); -void association_cleanup(struct association* assoc); -void association_add_note(Gom_ctxt ctxt, struct note_sub* note); -void association_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void association_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_associations(Gedcom_write_hndl hndl, int parent, struct association *assoc); +DECLARE_CLEANFUNC(association); +DECLARE_ADDFUNC2(association, note_sub); +DECLARE_ADDFUNC2(association, source_citation); +DECLARE_ADDFUNC2(association, user_data); + #endif /* __ASSOCIATION_H */ diff --git a/gom/change_date.c b/gom/change_date.c index 2b703f8..0e56869 100644 --- a/gom/change_date.c +++ b/gom/change_date.c @@ -54,19 +54,19 @@ Gedcom_ctxt sub_chan_start(_ELT_PARAMS_) switch (ctxt->ctxt_type) { case REC_FAM: - family_set_change_date(ctxt, chan); break; + ADDFUNC2_NOLIST(family,change_date)(ctxt, chan); break; case REC_INDI: - individual_set_change_date(ctxt, chan); break; + ADDFUNC2_NOLIST(individual,change_date)(ctxt, chan); break; case REC_OBJE: - multimedia_set_change_date(ctxt, chan); break; + ADDFUNC2_NOLIST(multimedia,change_date)(ctxt, chan); break; case REC_NOTE: - note_set_change_date(ctxt, chan); break; + ADDFUNC2_NOLIST(note,change_date)(ctxt, chan); break; case REC_REPO: - repository_set_change_date(ctxt, chan); break; + ADDFUNC2_NOLIST(repository,change_date)(ctxt, chan); break; case REC_SOUR: - source_set_change_date(ctxt, chan); break; + ADDFUNC2_NOLIST(source,change_date)(ctxt, chan); break; case REC_SUBM: - submitter_set_change_date(ctxt, chan); break; + ADDFUNC2_NOLIST(submitter,change_date)(ctxt, chan); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -77,8 +77,11 @@ Gedcom_ctxt sub_chan_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -DATE_CB(change_date, sub_chan_date_start, date) -STRING_CB(change_date, sub_chan_time_start, time) +DEFINE_DATE_CB(change_date, sub_chan_date_start, date) +DEFINE_STRING_CB(change_date, sub_chan_time_start, time) + +DEFINE_ADDFUNC2(change_date, note_sub, note) +DEFINE_ADDFUNC2(change_date, user_data, extra) void change_date_subscribe() { @@ -89,27 +92,13 @@ void change_date_subscribe() def_elt_end); } -void change_date_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct change_date *chan = SAFE_CTXT_CAST(change_date, ctxt); - if (chan) - LINK_CHAIN_ELT(note_sub, chan->note, note); -} - -void change_date_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct change_date *obj = SAFE_CTXT_CAST(change_date, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void change_date_cleanup(struct change_date *chan) +void CLEANFUNC(change_date)(struct change_date *chan) { if (chan) { SAFE_FREE(chan->date); SAFE_FREE(chan->time); - DESTROY_CHAIN_ELTS(note_sub, chan->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_data, chan->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(note_sub, chan->note); + DESTROY_CHAIN_ELTS(user_data, chan->extra); } SAFE_FREE(chan); } diff --git a/gom/change_date.h b/gom/change_date.h index 2a0c484..b4dd028 100644 --- a/gom/change_date.h +++ b/gom/change_date.h @@ -28,10 +28,11 @@ #include "gom_internal.h" void change_date_subscribe(); -void change_date_cleanup(struct change_date *chan); -void change_date_add_note(Gom_ctxt ctxt, struct note_sub* note); -void change_date_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_change_date(Gedcom_write_hndl hndl, int parent, struct change_date *chan); +DECLARE_CLEANFUNC(change_date); +DECLARE_ADDFUNC2(change_date, note_sub); +DECLARE_ADDFUNC2(change_date, user_data); + #endif /* __CHANGE_DATE_H */ diff --git a/gom/event.c b/gom/event.c index 7d5f92e..2d05ee9 100644 --- a/gom/event.c +++ b/gom/event.c @@ -70,9 +70,9 @@ Gedcom_ctxt sub_evt_start(_ELT_PARAMS_) if (! err) { switch (ctxt->ctxt_type) { case REC_FAM: - family_add_event(ctxt, evt); break; + ADDFUNC2(family,event)(ctxt, evt); break; case REC_INDI: - individual_add_event(ctxt, evt); break; + ADDFUNC2(individual,event)(ctxt, evt); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -119,7 +119,7 @@ Gedcom_ctxt sub_attr_start(_ELT_PARAMS_) if (! err) { switch (ctxt->ctxt_type) { case REC_INDI: - individual_add_attribute(ctxt, evt); break; + ADDFUNC2_TOVAR(individual,event,attribute)(ctxt, evt); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -131,15 +131,23 @@ Gedcom_ctxt sub_attr_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(event, sub_evt_type_start, type) -DATE_CB(event, sub_evt_date_start, date) -AGE_CB(event, sub_evt_age_start, age) -STRING_CB(event, sub_evt_agnc_start, agency) -STRING_CB(event, sub_evt_caus_start, cause) -NULL_CB(event, sub_fam_evt_husb_wife_start) -XREF_CB(event, sub_evt_famc_start, family, make_family_record) -STRING_CB(event, sub_evt_famc_adop_start, adoption_parent) +DEFINE_STRING_CB(event, sub_evt_type_start, type) +DEFINE_DATE_CB(event, sub_evt_date_start, date) +DEFINE_AGE_CB(event, sub_evt_age_start, age) +DEFINE_STRING_CB(event, sub_evt_agnc_start, agency) +DEFINE_STRING_CB(event, sub_evt_caus_start, cause) +DEFINE_NULL_CB(event, sub_fam_evt_husb_wife_start) +DEFINE_XREF_CB(event, sub_evt_famc_start, family, family) +DEFINE_STRING_CB(event, sub_evt_famc_adop_start, adoption_parent) +DEFINE_ADDFUNC2(event, source_citation, citation) +DEFINE_ADDFUNC2(event, multimedia_link, mm_link) +DEFINE_ADDFUNC2(event, note_sub, note) +DEFINE_ADDFUNC2(event, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(event, place, place) +DEFINE_ADDFUNC2_NOLIST(event, address, address) +DEFINE_ADDFUNC2_STRN(event, phone, 3) + Gedcom_ctxt sub_fam_evt_age_start(_ELT_PARAMS_) { Gom_ctxt ctxt = (Gom_ctxt)parent; @@ -177,61 +185,6 @@ Gedcom_ctxt sub_fam_evt_age_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -void event_add_place(Gom_ctxt ctxt, struct place* place) -{ - struct event *evt = SAFE_CTXT_CAST(event, ctxt); - if (evt) - evt->place = place; -} - -void event_add_address(Gom_ctxt ctxt, struct address* address) -{ - struct event *evt = SAFE_CTXT_CAST(event, ctxt); - if (evt) - evt->address = address; -} - -void event_add_phone(Gom_ctxt ctxt, char *phone) -{ - struct event *evt = SAFE_CTXT_CAST(event, ctxt); - if (evt) { - int i = 0; - while (i<2 && evt->phone[i]) i++; - if (! evt->phone[i]) { - evt->phone[i] = strdup(phone); - if (! evt->phone[i]) MEMORY_ERROR; - } - } -} - -void event_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct event *evt = SAFE_CTXT_CAST(event, ctxt); - if (evt) - LINK_CHAIN_ELT(source_citation, evt->citation, cit); -} - -void event_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* mm) -{ - struct event *evt = SAFE_CTXT_CAST(event, ctxt); - if (evt) - LINK_CHAIN_ELT(multimedia_link, evt->mm_link, mm); -} - -void event_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct event *evt = SAFE_CTXT_CAST(event, ctxt); - if (evt) - LINK_CHAIN_ELT(note_sub, evt->note, note); -} - -void event_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct event *obj = SAFE_CTXT_CAST(event, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - void event_subscribe() { gedcom_subscribe_to_element(ELT_SUB_FAM_EVT, sub_evt_start, def_elt_end); @@ -273,28 +226,28 @@ void event_subscribe() sub_evt_caus_start, def_elt_end); } -void event_cleanup(struct event* evt) +void CLEANFUNC(event)(struct event* evt) { if (evt) { SAFE_FREE(evt->event_name); SAFE_FREE(evt->val); SAFE_FREE(evt->type); SAFE_FREE(evt->date); - place_cleanup(evt->place); - address_cleanup(evt->address); + CLEANFUNC(place)(evt->place); + CLEANFUNC(address)(evt->address); SAFE_FREE(evt->phone[0]); SAFE_FREE(evt->phone[1]); SAFE_FREE(evt->phone[2]); SAFE_FREE(evt->age); SAFE_FREE(evt->agency); SAFE_FREE(evt->cause); - DESTROY_CHAIN_ELTS(source_citation, evt->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(multimedia_link, evt->mm_link, multimedia_link_cleanup); - DESTROY_CHAIN_ELTS(note_sub, evt->note, note_sub_cleanup); + DESTROY_CHAIN_ELTS(source_citation, evt->citation); + DESTROY_CHAIN_ELTS(multimedia_link, evt->mm_link); + DESTROY_CHAIN_ELTS(note_sub, evt->note); SAFE_FREE(evt->husband_age); SAFE_FREE(evt->wife_age); SAFE_FREE(evt->adoption_parent); - DESTROY_CHAIN_ELTS(user_data, evt->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, evt->extra); } } diff --git a/gom/event.h b/gom/event.h index 6835dbd..2c3b278 100644 --- a/gom/event.h +++ b/gom/event.h @@ -34,15 +34,16 @@ typedef enum _EVT_TYPE { } EventType; void event_subscribe(); -void event_cleanup(struct event* evt); -void event_add_place(Gom_ctxt ctxt, struct place* place); -void event_add_address(Gom_ctxt ctxt, struct address* address); -void event_add_phone(Gom_ctxt ctxt, char *phone); -void event_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void event_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* mm); -void event_add_note(Gom_ctxt ctxt, struct note_sub* note); -void event_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_events(Gedcom_write_hndl hndl, int parent, EventType evt_type, struct event* evt); +DECLARE_CLEANFUNC(event); +DECLARE_ADDFUNC2(event, source_citation); +DECLARE_ADDFUNC2(event, multimedia_link); +DECLARE_ADDFUNC2(event, note_sub); +DECLARE_ADDFUNC2(event, user_data); +DECLARE_ADDFUNC2_NOLIST(event, place); +DECLARE_ADDFUNC2_NOLIST(event, address); +DECLARE_ADDFUNC2_STRN(event, phone); + #endif /* __EVENT_H */ diff --git a/gom/family.c b/gom/family.c index f997eb8..8389569 100644 --- a/gom/family.c +++ b/gom/family.c @@ -40,13 +40,28 @@ struct family* gom_first_family = NULL; -REC_CB(family, fam_start, make_family_record) -GET_REC_BY_XREF(family, XREF_FAM, gom_get_family_by_xref) -XREF_CB(family, fam_husb_start, husband, make_individual_record) -XREF_CB(family, fam_wife_start, wife, make_individual_record) -STRING_CB(family, fam_nchi_start, nr_of_children) -XREF_LIST_CB(family, fam_chil_start, children, make_individual_record) -XREF_LIST_CB(family, fam_subm_start, submitters, make_submitter_record) +DEFINE_MAKEFUNC(family, gom_first_family) +DEFINE_DESTROYFUNC(family, gom_first_family) +DEFINE_ADDFUNC(family, XREF_FAM) +DEFINE_DELETEFUNC(family) +DEFINE_GETXREFFUNC(family, XREF_FAM) + +DEFINE_REC_CB(family, fam_start) +DEFINE_XREF_CB(family, fam_husb_start, husband, individual) +DEFINE_XREF_CB(family, fam_wife_start, wife, individual) +DEFINE_STRING_CB(family, fam_nchi_start, nr_of_children) +DEFINE_XREF_LIST_CB(family, fam_chil_start, children, individual) +DEFINE_XREF_LIST_CB(family, fam_subm_start, submitters, submitter) + +DEFINE_ADDFUNC2(family, event, event) +DEFINE_ADDFUNC2(family, lds_event, lds_spouse_sealing) +DEFINE_ADDFUNC2(family, source_citation, citation) +DEFINE_ADDFUNC2(family, multimedia_link, mm_link) +DEFINE_ADDFUNC2(family, note_sub, note) +DEFINE_ADDFUNC2(family, user_ref_number, ref) +DEFINE_ADDFUNC2(family, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(family, change_date, change_date) +DEFINE_ADDFUNC2_STR(family, record_id) void family_subscribe() { @@ -58,93 +73,28 @@ void family_subscribe() gedcom_subscribe_to_element(ELT_FAM_SUBM, fam_subm_start, def_elt_end); } -void family_add_event(Gom_ctxt ctxt, struct event* evt) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) - LINK_CHAIN_ELT(event, fam->event, evt); -} - -void family_add_lss(Gom_ctxt ctxt, struct lds_event* lss) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) - LINK_CHAIN_ELT(lds_event, fam->lds_spouse_sealing, lss); -} - -void family_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) - LINK_CHAIN_ELT(source_citation, fam->citation, cit); -} - -void family_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) - LINK_CHAIN_ELT(multimedia_link, fam->mm_link, link); -} - -void family_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) - LINK_CHAIN_ELT(note_sub, fam->note, note); -} - -void family_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) - LINK_CHAIN_ELT(user_ref_number, fam->ref, ref); -} - -void family_set_record_id(Gom_ctxt ctxt, const char *rin) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) { - fam->record_id = strdup(rin); - if (! fam->record_id) MEMORY_ERROR; - } -} - -void family_set_change_date(Gom_ctxt ctxt, struct change_date* chan) -{ - struct family *fam = SAFE_CTXT_CAST(family, ctxt); - if (fam) - fam->change_date = chan; -} - -void family_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct family *obj = SAFE_CTXT_CAST(family, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void family_cleanup(struct family* fam) +void CLEANFUNC(family)(struct family* fam) { if (fam) { SAFE_FREE(fam->xrefstr); - DESTROY_CHAIN_ELTS(event, fam->event, event_cleanup); - DESTROY_CHAIN_ELTS(xref_list, fam->children, NULL_DESTROY); + DESTROY_CHAIN_ELTS(event, fam->event); + DESTROY_CHAIN_ELTS(xref_list, fam->children); SAFE_FREE(fam->nr_of_children); - DESTROY_CHAIN_ELTS(xref_list, fam->submitters, NULL_DESTROY); - DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing, lds_event_cleanup); - DESTROY_CHAIN_ELTS(source_citation, fam->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link, multimedia_link_cleanup); - DESTROY_CHAIN_ELTS(note_sub, fam->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_ref_number, fam->ref, user_ref_cleanup); + DESTROY_CHAIN_ELTS(xref_list, fam->submitters); + DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing); + DESTROY_CHAIN_ELTS(source_citation, fam->citation); + DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link); + DESTROY_CHAIN_ELTS(note_sub, fam->note); + DESTROY_CHAIN_ELTS(user_ref_number, fam->ref); SAFE_FREE(fam->record_id); - change_date_cleanup(fam->change_date); - DESTROY_CHAIN_ELTS(user_data, fam->extra, user_data_cleanup); + CLEANFUNC(change_date)(fam->change_date); + DESTROY_CHAIN_ELTS(user_data, fam->extra); } } void families_cleanup() { - DESTROY_CHAIN_ELTS(family, gom_first_family, family_cleanup); + DESTROY_CHAIN_ELTS(family, gom_first_family); } struct family* gom_get_first_family() @@ -152,17 +102,6 @@ struct family* gom_get_first_family() return gom_first_family; } -struct family* make_family_record(const char* xrefstr) -{ - struct family* fam = NULL; - MAKE_CHAIN_ELT(family, gom_first_family, fam); - if (fam) { - fam->xrefstr = strdup(xrefstr); - if (! fam->xrefstr) MEMORY_ERROR; - } - return fam; -} - int write_families(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/family.h b/gom/family.h index 7fdce9f..d061be5 100644 --- a/gom/family.h +++ b/gom/family.h @@ -29,16 +29,17 @@ void family_subscribe(); void families_cleanup(); -struct family* make_family_record(const char* xref); -void family_add_event(Gom_ctxt ctxt, struct event* evt); -void family_add_lss(Gom_ctxt ctxt, struct lds_event* lss); -void family_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void family_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link); -void family_add_note(Gom_ctxt ctxt, struct note_sub* note); -void family_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref); -void family_set_record_id(Gom_ctxt ctxt, const char *rin); -void family_set_change_date(Gom_ctxt ctxt, struct change_date* chan); -void family_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_families(Gedcom_write_hndl hndl); +DECLARE_MAKEFUNC(family); +DECLARE_ADDFUNC2(family, event); +DECLARE_ADDFUNC2(family, lds_event); +DECLARE_ADDFUNC2(family, source_citation); +DECLARE_ADDFUNC2(family, multimedia_link); +DECLARE_ADDFUNC2(family, note_sub); +DECLARE_ADDFUNC2(family, user_ref_number); +DECLARE_ADDFUNC2(family, user_data); +DECLARE_ADDFUNC2_NOLIST(family, change_date); +DECLARE_ADDFUNC2_STR(family, record_id); + #endif /* __FAMILY_H */ diff --git a/gom/family_link.c b/gom/family_link.c index 1ab6d4b..39a2140 100644 --- a/gom/family_link.c +++ b/gom/family_link.c @@ -49,7 +49,7 @@ Gedcom_ctxt sub_fam_link_start(_ELT_PARAMS_) switch (ctxt->ctxt_type) { case REC_INDI: - individual_add_family_link(ctxt, elt, link); break; + ADDFUNC2(individual,family_link)(ctxt, elt, link); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -87,6 +87,9 @@ Gedcom_ctxt sub_fam_link_pedi_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_ADDFUNC2(family_link, note_sub, note) +DEFINE_ADDFUNC2(family_link, user_data, extra) + void family_link_subscribe() { gedcom_subscribe_to_element(ELT_SUB_FAMC, sub_fam_link_start, @@ -97,33 +100,19 @@ void family_link_subscribe() def_elt_end); } -void family_link_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct family_link *link = SAFE_CTXT_CAST(family_link, ctxt); - if (link) - LINK_CHAIN_ELT(note_sub, link->note, note); -} - -void family_link_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct family_link *obj = SAFE_CTXT_CAST(family_link, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void pedigree_cleanup(struct pedigree* ped) +void CLEANFUNC(pedigree)(struct pedigree* ped) { if (ped) { SAFE_FREE(ped->pedigree); } } -void family_link_cleanup(struct family_link *link) +void CLEANFUNC(family_link)(struct family_link *link) { if (link) { - DESTROY_CHAIN_ELTS(pedigree, link->pedigree, pedigree_cleanup); - DESTROY_CHAIN_ELTS(note_sub, link->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_data, link->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(pedigree, link->pedigree); + DESTROY_CHAIN_ELTS(note_sub, link->note); + DESTROY_CHAIN_ELTS(user_data, link->extra); } } diff --git a/gom/family_link.h b/gom/family_link.h index 5444995..5a1cb1b 100644 --- a/gom/family_link.h +++ b/gom/family_link.h @@ -33,10 +33,11 @@ typedef enum _LINK_TYPE { } LinkType; void family_link_subscribe(); -void family_link_cleanup(struct family_link* link); -void family_link_add_note(Gom_ctxt ctxt, struct note_sub* note); -void family_link_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_family_links(Gedcom_write_hndl hndl, int parent, LinkType type, struct family_link *link); +DECLARE_CLEANFUNC(family_link); +DECLARE_ADDFUNC2(family_link, note_sub); +DECLARE_ADDFUNC2(family_link, user_data); + #endif /* __FAMILY_LINK_H */ diff --git a/gom/func_template.h b/gom/func_template.h new file mode 100644 index 0000000..df5c944 --- /dev/null +++ b/gom/func_template.h @@ -0,0 +1,421 @@ +/* General header for the Gedcom object model, defining function macros + Copyright (C) 2002 The Genes Development Team + This file is part of the Gedcom parser library. + Contributed by Peter Verthez , 2002. + + The Gedcom parser library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The Gedcom parser library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Gedcom parser library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* $Id$ */ +/* $Name$ */ + +#ifndef __FUNC_TEMPLATE_H +#define __FUNC_TEMPLATE_H + +#define MAKEFUNC(STRUCTTYPE) make_ ## STRUCTTYPE ## _record +#define DESTROYFUNC(STRUCTTYPE) destroy_ ## STRUCTTYPE ## _record +#define GETXREFFUNC(STRUCTTYPE) gom_get_ ## STRUCTTYPE ## _by_xref +#define CLEANFUNC(STRUCTTYPE) STRUCTTYPE ## _cleanup +#define ADDFUNC(STRUCTTYPE) gom_add_ ## STRUCTTYPE +#define DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE +#define ADDFUNC2(T1,T2) T1 ## _add_ ## T2 +#define ADDFUNC2_TOVAR(T1,T2,F) T1 ## _add_ ## T2 ## _to_ ## F +#define ADDFUNC2_NOLIST(T1,T2) ADDFUNC2(T1,T2) +#define ADDFUNC2_STR(T1,F) ADDFUNC2(T1,F) +#define ADDFUNC2_STRN(T1,F) ADDFUNC2(T1,F) + +#define DECLARE_MAKEFUNC(STRUCTTYPE) \ + struct STRUCTTYPE* MAKEFUNC(STRUCTTYPE)(const char* xref) + +#define DECLARE_CLEANFUNC(STRUCTTYPE) \ + void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) + +#define DECLARE_ADDFUNC2(STRUCTTYPE,T2) \ + void ADDFUNC2(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* obj) + +#define DECLARE_ADDFUNC2_TOVAR(STRUCTTYPE,T2,F) \ + void ADDFUNC2_TOVAR(STRUCTTYPE,T2,F)(Gom_ctxt ctxt, struct T2* obj) + +#define DECLARE_ADDFUNC2_NOLIST(STRUCTTYPE,T2) \ + void ADDFUNC2_NOLIST(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* obj) + +#define DECLARE_ADDFUNC2_STR(STRUCTTYPE,F) \ + void ADDFUNC2_STR(STRUCTTYPE,F)(Gom_ctxt ctxt, const char* str) + +#define DECLARE_ADDFUNC2_STRN(STRUCTTYPE,F) \ + void ADDFUNC2_STRN(STRUCTTYPE,F)(Gom_ctxt ctxt, const char* str) + +/* Doubly-linked list, but last rec->next is NULL (doesn't go to first rec) */ +#define LINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ + { \ + struct STRUCTTYPE *_local_obj = VAL; \ + if (! FIRSTVAL) { \ + VAL->next = NULL; \ + VAL->previous = _local_obj; \ + FIRSTVAL = VAL; \ + } \ + else { \ + VAL->next = NULL; \ + FIRSTVAL->previous->next = VAL; \ + VAL->previous = FIRSTVAL->previous; \ + FIRSTVAL->previous = VAL; \ + } \ + } + +#define UNLINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ + { \ + struct STRUCTTYPE *_local_obj = VAL; \ + if (VAL == FIRSTVAL) \ + FIRSTVAL = _local_obj->next; \ + else \ + VAL->previous->next = VAL->next; \ + if (VAL->next) \ + VAL->next->previous = VAL->previous; \ + } + +#define MAKE_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ + { \ + VAL = (struct STRUCTTYPE*) malloc(sizeof(struct STRUCTTYPE)); \ + if (! VAL) \ + MEMORY_ERROR; \ + else { \ + memset (VAL, 0, sizeof(struct STRUCTTYPE)); \ + LINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ + } \ + } + +#define DESTROY_CHAIN_ELTS(STRUCTTYPE, FIRSTVAL) \ + { \ + if (FIRSTVAL) { \ + struct STRUCTTYPE *runner, *next; \ + runner = FIRSTVAL; \ + while (runner) { \ + next = runner->next; \ + CLEANFUNC(STRUCTTYPE)(runner); \ + SAFE_FREE(runner); \ + runner = next; \ + } \ + } \ + } + +/* General functions */ +#define DEFINE_MAKEFUNC(STRUCTTYPE,FIRSTVAL) \ + struct STRUCTTYPE* MAKEFUNC(STRUCTTYPE)(const char* xrefstr) { \ + struct STRUCTTYPE* obj = NULL; \ + if (xrefstr) { \ + MAKE_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, obj); \ + if (obj) { \ + obj->xrefstr = strdup(xrefstr); \ + if (!obj->xrefstr) MEMORY_ERROR; \ + } \ + } \ + return obj; \ + } + +#define DEFINE_DESTROYFUNC(STRUCTTYPE,FIRSTVAL) \ + void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj); \ + void DESTROYFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) { \ + if (obj) { \ + CLEANFUNC(STRUCTTYPE)(obj); \ + UNLINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, obj); \ + free(obj); \ + } \ + } + +#define DEFINE_GETXREFFUNC(STRUCTTYPE,XREF_TYPE) \ + struct STRUCTTYPE *GETXREFFUNC(STRUCTTYPE)(const char *xrefstr) \ + { \ + struct xref_value* xr = gedcom_get_by_xref(xrefstr); \ + if (xr && (xr->type == XREF_TYPE) && xr->object) \ + return (struct STRUCTTYPE*)(xr->object); \ + else \ + return NULL; \ + } + +#define DEFINE_ADDFUNC(STRUCTTYPE,XREF_TYPE) \ + struct STRUCTTYPE *ADDFUNC(STRUCTTYPE)(const char* xrefstr) \ + { \ + struct STRUCTTYPE *obj = NULL; \ + struct xref_value* xrv = gedcom_get_by_xref(xrefstr); \ + if (xrv) \ + gom_xref_already_in_use(xrefstr); \ + else { \ + obj = MAKEFUNC(STRUCTTYPE)(xrefstr); \ + if (obj) { \ + xrv = gedcom_add_xref(XREF_TYPE, xrefstr, (Gedcom_ctxt)obj); \ + if (!xrv) { \ + DESTROYFUNC(STRUCTTYPE)(obj); \ + obj = NULL; \ + } \ + } \ + } \ + return obj; \ + } + +#define DEFINE_DELETEFUNC(STRUCTTYPE) \ + int DELETEFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) \ + { \ + int result = 1; \ + if (obj) { \ + result = gedcom_delete_xref(obj->xrefstr); \ + if (result == 0) \ + DESTROYFUNC(STRUCTTYPE)(obj); \ + } \ + return result; \ + } + +#define DEFINE_ADDFUNC2(STRUCTTYPE,T2,FIELD) \ + void ADDFUNC2(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* addobj) \ + { \ + struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ + if (obj) \ + LINK_CHAIN_ELT(T2, obj->FIELD, addobj); \ + } + +#define DEFINE_ADDFUNC2_TOVAR(STRUCTTYPE,T2,FIELD) \ + void ADDFUNC2_TOVAR(STRUCTTYPE,T2,FIELD)(Gom_ctxt ctxt, struct T2* addobj) \ + { \ + struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ + if (obj) \ + LINK_CHAIN_ELT(T2, obj->FIELD, addobj); \ + } + +#define DEFINE_ADDFUNC2_NOLIST(STRUCTTYPE,T2, FIELD) \ + void ADDFUNC2_NOLIST(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* addobj) \ + { \ + struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ + if (obj) \ + obj->FIELD = addobj; \ + } + +#define DEFINE_ADDFUNC2_STR(STRUCTTYPE,FIELD) \ +void ADDFUNC2_STR(STRUCTTYPE,FIELD)(Gom_ctxt ctxt, const char *str) \ +{ \ + struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ + if (obj) { \ + obj->FIELD = strdup(str); \ + if (! obj->FIELD) MEMORY_ERROR; \ + } \ +} + +#define DEFINE_ADDFUNC2_STRN(STRUCTTYPE,FIELD,N) \ +void ADDFUNC2_STRN(STRUCTTYPE,FIELD)(Gom_ctxt ctxt, const char *str) \ +{ \ + struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ + if (obj) { \ + int i = 0; \ + while (i < N-1 && obj->FIELD[i]) i++; \ + if (! obj->FIELD[i]) { \ + obj->FIELD[i] = strdup(str); \ + if (! obj->FIELD[i]) MEMORY_ERROR; \ + } \ + } \ +} + +/* Definition of callbacks */ +#define _REC_PARAMS_ Gedcom_rec rec UNUSED, int level UNUSED, \ + Gedcom_val xref UNUSED, char *tag UNUSED, \ + char *raw_value UNUSED, int parsed_tag UNUSED, \ + Gedcom_val parsed_value UNUSED + +#define _REC_END_PARAMS_ Gedcom_rec rec UNUSED, Gedcom_ctxt self UNUSED, \ + Gedcom_val parsed_value UNUSED + +#define _ELT_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, \ + int level UNUSED, char *tag UNUSED, \ + char *raw_value UNUSED, int parsed_tag UNUSED, \ + Gedcom_val parsed_value UNUSED + +#define _ELT_END_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, \ + Gedcom_ctxt self UNUSED, \ + Gedcom_val parsed_value UNUSED + +#define DEFINE_REC_CB(STRUCTTYPE,CB_NAME) \ + Gedcom_ctxt CB_NAME(_REC_PARAMS_) \ + { \ + struct xref_value* xr = GEDCOM_XREF_PTR(xref); \ + if (! xr->object) \ + xr->object = (Gedcom_ctxt) MAKEFUNC(STRUCTTYPE)(xr->string); \ + if (xr->object) \ + return (Gedcom_ctxt) MAKE_GOM_CTXT(rec, STRUCTTYPE, xr->object); \ + else \ + return NULL; \ + } + +#define DEFINE_STRING_CB(STRUCTTYPE,CB_NAME,FIELD) \ + Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ + { \ + Gom_ctxt result = NULL; \ + if (! parent) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj \ + = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ + if (obj) { \ + char *str = GEDCOM_STRING(parsed_value); \ + obj->FIELD = strdup(str); \ + if (! obj->FIELD) \ + MEMORY_ERROR; \ + else \ + result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ + } \ + } \ + return (Gedcom_ctxt)result; \ + } + +#define DEFINE_STRING_END_CB(STRUCTTYPE,CB_NAME,FIELD) \ + void CB_NAME(_ELT_END_PARAMS_) \ + { \ + Gom_ctxt ctxt = (Gom_ctxt)self; \ + if (! ctxt) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ + if (obj) { \ + char *str = GEDCOM_STRING(parsed_value); \ + char *newvalue = strdup(str); \ + if (! newvalue) \ + MEMORY_ERROR; \ + else \ + obj->FIELD = newvalue; \ + } \ + destroy_gom_ctxt(ctxt); \ + } \ + } + +#define DEFINE_STRING_END_REC_CB(STRUCTTYPE,CB_NAME,FIELD) \ + void CB_NAME(_REC_END_PARAMS_) \ + { \ + Gom_ctxt ctxt = (Gom_ctxt)self; \ + if (! ctxt) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ + if (obj) { \ + char *str = GEDCOM_STRING(parsed_value); \ + char *newvalue = strdup(str); \ + if (! newvalue) \ + MEMORY_ERROR; \ + else \ + obj->FIELD = newvalue; \ + } \ + destroy_gom_ctxt(ctxt); \ + } \ + } + +#define DEFINE_DATE_CB(STRUCTTYPE,CB_NAME,FIELD) \ + Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ + { \ + Gom_ctxt result = NULL; \ + if (! parent) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj \ + = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ + if (obj) { \ + struct date_value dv = GEDCOM_DATE(parsed_value); \ + obj->FIELD = gedcom_new_date_value(&dv); \ + if (! obj->FIELD) \ + MEMORY_ERROR; \ + else \ + result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ + } \ + } \ + return (Gedcom_ctxt)result; \ + } + +#define DEFINE_AGE_CB(STRUCTTYPE,CB_NAME,FIELD) \ + Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ + { \ + Gom_ctxt result = NULL; \ + if (! parent) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj \ + = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ + if (obj) { \ + struct age_value age = GEDCOM_AGE(parsed_value); \ + obj->FIELD = gedcom_new_age_value(&age); \ + if (! obj->FIELD) \ + MEMORY_ERROR; \ + else \ + result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ + } \ + } \ + return (Gedcom_ctxt)result; \ + } + +#define DEFINE_XREF_CB(STRUCTTYPE,CB_NAME,FIELD,LINKSTRTYPE) \ + Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ + { \ + Gom_ctxt result = NULL; \ + if (! parent) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj \ + = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ + struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value); \ + if (! xr->object) \ + xr->object = (Gedcom_ctxt) MAKEFUNC(LINKSTRTYPE)(xr->string); \ + if (obj) { \ + obj->FIELD = xr; \ + result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ + } \ + } \ + return (Gedcom_ctxt)result; \ + } + +#define DEFINE_XREF_LIST_CB(STRUCTTYPE,CB_NAME,FIELD,LINKSTRTYPE) \ + Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ + { \ + Gom_ctxt result = NULL; \ + if (! parent) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj \ + = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ + struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value); \ + struct xref_list *xrl; \ + if (! xr->object) \ + xr->object = (Gedcom_ctxt) MAKEFUNC(LINKSTRTYPE)(xr->string); \ + if (obj) { \ + MAKE_CHAIN_ELT(xref_list, obj->FIELD, xrl); \ + if (xrl) { \ + xrl->xref = xr; \ + result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ + } \ + } \ + } \ + return (Gedcom_ctxt)result; \ + } + +#define DEFINE_NULL_CB(STRUCTTYPE,CB_NAME) \ + Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ + { \ + Gom_ctxt result = NULL; \ + if (! parent) \ + NO_CONTEXT; \ + else { \ + struct STRUCTTYPE *obj \ + = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ + if (obj) \ + result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ + } \ + return (Gedcom_ctxt)result; \ + } + + + +#endif /* __FUNC_TEMPLATE_H */ diff --git a/gom/gom.c b/gom/gom.c index 302fc06..adf6cab 100644 --- a/gom/gom.c +++ b/gom/gom.c @@ -187,6 +187,11 @@ void gom_mem_error(const char *filename, int line) gedcom_error(_("Could not allocate memory at %s, %d"), filename, line); } +void gom_xref_already_in_use(const char *xrefstr) +{ + gedcom_error(_("Cross-reference key '%s' is already in use"), xrefstr); +} + void gom_unexpected_context(const char* file, int line, OBJ_TYPE found) { gedcom_warning(_("Internal error: Unexpected context at %s, line %d: %d"), diff --git a/gom/gom_internal.h b/gom/gom_internal.h index 3b482f2..5b707a5 100644 --- a/gom/gom_internal.h +++ b/gom/gom_internal.h @@ -75,6 +75,7 @@ void gom_cast_error(const char* file, int line, OBJ_TYPE expected, OBJ_TYPE found); void gom_no_context(const char* file, int line); void gom_unexpected_context(const char* file, int line, OBJ_TYPE found); +void gom_xref_already_in_use(const char *xrefstr); int gom_write_xref_list(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, @@ -113,249 +114,10 @@ void set_xref_type(struct xref_value *xr, const char* str); int update_date(struct date_value** dv, struct tm* tm_ptr); int update_time(char** tv, struct tm* tm_ptr); -/* Doubly-linked list, but last rec->next is NULL (doesn't go to first rec) */ -#define LINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ - { \ - struct STRUCTTYPE *_local_obj = VAL; \ - if (! FIRSTVAL) { \ - VAL->next = NULL; \ - VAL->previous = _local_obj; \ - FIRSTVAL = VAL; \ - } \ - else { \ - VAL->next = NULL; \ - FIRSTVAL->previous->next = VAL; \ - VAL->previous = FIRSTVAL->previous; \ - FIRSTVAL->previous = VAL; \ - } \ - } - -#define MAKE_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ - { \ - VAL = (struct STRUCTTYPE*) malloc(sizeof(struct STRUCTTYPE)); \ - if (! VAL) \ - MEMORY_ERROR; \ - else { \ - memset (VAL, 0, sizeof(struct STRUCTTYPE)); \ - LINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ - } \ - } - void NULL_DESTROY(void* anything); -#define DESTROY_CHAIN_ELTS(STRUCTTYPE, FIRSTVAL, DESTROYFUNC) \ - { \ - if (FIRSTVAL) { \ - struct STRUCTTYPE *runner, *next; \ - runner = FIRSTVAL; \ - while (runner) { \ - next = runner->next; \ - DESTROYFUNC(runner); \ - SAFE_FREE(runner); \ - runner = next; \ - } \ - } \ - } - -#define _REC_PARAMS_ Gedcom_rec rec UNUSED, int level UNUSED, \ - Gedcom_val xref UNUSED, char *tag UNUSED, \ - char *raw_value UNUSED, int parsed_tag UNUSED, \ - Gedcom_val parsed_value UNUSED - -#define _REC_END_PARAMS_ Gedcom_rec rec UNUSED, Gedcom_ctxt self UNUSED, \ - Gedcom_val parsed_value UNUSED - -#define _ELT_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, \ - int level UNUSED, char *tag UNUSED, \ - char *raw_value UNUSED, int parsed_tag UNUSED, \ - Gedcom_val parsed_value UNUSED - -#define _ELT_END_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, \ - Gedcom_ctxt self UNUSED, \ - Gedcom_val parsed_value UNUSED - -#define REC_CB(STRUCTTYPE,CB_NAME,FUNC) \ - Gedcom_ctxt CB_NAME(_REC_PARAMS_) \ - { \ - struct xref_value* xr = GEDCOM_XREF_PTR(xref); \ - if (! xr->object) \ - xr->object = (Gedcom_ctxt) FUNC(xr->string); \ - if (xr->object) \ - return (Gedcom_ctxt) MAKE_GOM_CTXT(rec, STRUCTTYPE, xr->object); \ - else \ - return NULL; \ - } - -#define GET_REC_BY_XREF(STRUCTTYPE,XREF_TYPE,FUNC_NAME) \ - struct STRUCTTYPE *FUNC_NAME(const char *xrefstr) \ - { \ - struct xref_value* xr = gedcom_get_by_xref(xrefstr); \ - if (xr && (xr->type == XREF_TYPE) && xr->object) \ - return (struct STRUCTTYPE*)(xr->object); \ - else \ - return NULL; \ - } - -#define STRING_CB(STRUCTTYPE,CB_NAME,FIELD) \ - Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ - { \ - Gom_ctxt result = NULL; \ - if (! parent) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj \ - = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ - if (obj) { \ - char *str = GEDCOM_STRING(parsed_value); \ - obj->FIELD = strdup(str); \ - if (! obj->FIELD) \ - MEMORY_ERROR; \ - else \ - result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ - } \ - } \ - return (Gedcom_ctxt)result; \ - } - -#define STRING_END_CB(STRUCTTYPE,CB_NAME,FIELD) \ - void CB_NAME(_ELT_END_PARAMS_) \ - { \ - Gom_ctxt ctxt = (Gom_ctxt)self; \ - if (! ctxt) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ - if (obj) { \ - char *str = GEDCOM_STRING(parsed_value); \ - char *newvalue = strdup(str); \ - if (! newvalue) \ - MEMORY_ERROR; \ - else \ - obj->FIELD = newvalue; \ - } \ - destroy_gom_ctxt(ctxt); \ - } \ - } - -#define STRING_END_REC_CB(STRUCTTYPE,CB_NAME,FIELD) \ - void CB_NAME(_REC_END_PARAMS_) \ - { \ - Gom_ctxt ctxt = (Gom_ctxt)self; \ - if (! ctxt) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt); \ - if (obj) { \ - char *str = GEDCOM_STRING(parsed_value); \ - char *newvalue = strdup(str); \ - if (! newvalue) \ - MEMORY_ERROR; \ - else \ - obj->FIELD = newvalue; \ - } \ - destroy_gom_ctxt(ctxt); \ - } \ - } - -#define DATE_CB(STRUCTTYPE,CB_NAME,FIELD) \ - Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ - { \ - Gom_ctxt result = NULL; \ - if (! parent) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj \ - = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ - if (obj) { \ - struct date_value dv = GEDCOM_DATE(parsed_value); \ - obj->FIELD = gedcom_new_date_value(&dv); \ - if (! obj->FIELD) \ - MEMORY_ERROR; \ - else \ - result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ - } \ - } \ - return (Gedcom_ctxt)result; \ - } +#define xref_list_cleanup NULL_DESTROY -#define AGE_CB(STRUCTTYPE,CB_NAME,FIELD) \ - Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ - { \ - Gom_ctxt result = NULL; \ - if (! parent) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj \ - = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ - if (obj) { \ - struct age_value age = GEDCOM_AGE(parsed_value); \ - obj->FIELD = gedcom_new_age_value(&age); \ - if (! obj->FIELD) \ - MEMORY_ERROR; \ - else \ - result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ - } \ - } \ - return (Gedcom_ctxt)result; \ - } - -#define XREF_CB(STRUCTTYPE,CB_NAME,FIELD,FUNC) \ - Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ - { \ - Gom_ctxt result = NULL; \ - if (! parent) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj \ - = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ - struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value); \ - if (! xr->object) \ - xr->object = (Gedcom_ctxt) FUNC(xr->string); \ - if (obj) { \ - obj->FIELD = xr; \ - result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ - } \ - } \ - return (Gedcom_ctxt)result; \ - } - -#define XREF_LIST_CB(STRUCTTYPE,CB_NAME,FIELD,FUNC) \ - Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ - { \ - Gom_ctxt result = NULL; \ - if (! parent) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj \ - = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ - struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value); \ - struct xref_list *xrl; \ - if (! xr->object) \ - xr->object = (Gedcom_ctxt) FUNC(xr->string); \ - if (obj) { \ - MAKE_CHAIN_ELT(xref_list, obj->FIELD, xrl); \ - if (xrl) { \ - xrl->xref = xr; \ - result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ - } \ - } \ - } \ - return (Gedcom_ctxt)result; \ - } - -#define NULL_CB(STRUCTTYPE,CB_NAME) \ - Gedcom_ctxt CB_NAME(_ELT_PARAMS_) \ - { \ - Gom_ctxt result = NULL; \ - if (! parent) \ - NO_CONTEXT; \ - else { \ - struct STRUCTTYPE *obj \ - = SAFE_CTXT_CAST(STRUCTTYPE, (Gom_ctxt)parent); \ - if (obj) \ - result = MAKE_GOM_CTXT(elt, STRUCTTYPE, obj); \ - } \ - return (Gedcom_ctxt)result; \ - } +#include "func_template.h" #endif /* __GOM_INTERNAL_H */ diff --git a/gom/header.c b/gom/header.c index 122c780..5dc6b9f 100644 --- a/gom/header.c +++ b/gom/header.c @@ -39,38 +39,34 @@ Gedcom_ctxt head_start(_REC_PARAMS_) return (Gedcom_ctxt) MAKE_GOM_CTXT(rec, header, &gom_header); } -STRING_CB(header, head_sour_start, source.id) -STRING_CB(header, head_sour_name_start, source.name) -STRING_CB(header, head_sour_vers_start, source.version) -STRING_CB(header, head_sour_corp_start, source.corporation.name) -STRING_CB(header, head_sour_data_start, source.data.name) -DATE_CB(header, head_sour_data_date_start, source.data.date) -STRING_CB(header, head_sour_data_copr_start, source.data.copyright) -STRING_CB(header, head_dest_start, destination) -XREF_CB(header, head_subm_start, submitter, make_submitter_record) -XREF_CB(header, head_subn_start, submission, make_submission_record) -DATE_CB(header, head_date_start, date) -STRING_CB(header, head_date_time_start, time) -STRING_CB(header, head_file_start, filename) -STRING_CB(header, head_copr_start, copyright) -NULL_CB(header, head_gedc_start) -STRING_CB(header, head_gedc_vers_start, gedcom.version) -STRING_CB(header, head_gedc_form_start, gedcom.form) -STRING_CB(header, head_char_start, charset.name) -STRING_CB(header, head_char_vers_start, charset.version) -STRING_CB(header, head_lang_start, language) -NULL_CB(header, head_plac_start) -STRING_CB(header, head_plac_form_start, place_hierarchy) -NULL_CB(header, head_note_start) /* the end callback will fill the value */ -STRING_END_CB(header, head_note_end, note) - -void header_add_address(Gom_ctxt ctxt, struct address* addr) -{ - struct header *head = SAFE_CTXT_CAST(header, ctxt); - if (head) - head->source.corporation.address = addr; -} +DEFINE_STRING_CB(header, head_sour_start, source.id) +DEFINE_STRING_CB(header, head_sour_name_start, source.name) +DEFINE_STRING_CB(header, head_sour_vers_start, source.version) +DEFINE_STRING_CB(header, head_sour_corp_start, source.corporation.name) +DEFINE_STRING_CB(header, head_sour_data_start, source.data.name) +DEFINE_DATE_CB(header, head_sour_data_date_start, source.data.date) +DEFINE_STRING_CB(header, head_sour_data_copr_start, source.data.copyright) +DEFINE_STRING_CB(header, head_dest_start, destination) +DEFINE_XREF_CB(header, head_subm_start, submitter, submitter) +DEFINE_XREF_CB(header, head_subn_start, submission, submission) +DEFINE_DATE_CB(header, head_date_start, date) +DEFINE_STRING_CB(header, head_date_time_start, time) +DEFINE_STRING_CB(header, head_file_start, filename) +DEFINE_STRING_CB(header, head_copr_start, copyright) +DEFINE_NULL_CB(header, head_gedc_start) +DEFINE_STRING_CB(header, head_gedc_vers_start, gedcom.version) +DEFINE_STRING_CB(header, head_gedc_form_start, gedcom.form) +DEFINE_STRING_CB(header, head_char_start, charset.name) +DEFINE_STRING_CB(header, head_char_vers_start, charset.version) +DEFINE_STRING_CB(header, head_lang_start, language) +DEFINE_NULL_CB(header, head_plac_start) +DEFINE_STRING_CB(header, head_plac_form_start, place_hierarchy) +DEFINE_NULL_CB(header, head_note_start) /* the end cb will fill the value */ +DEFINE_STRING_END_CB(header, head_note_end, note) +DEFINE_ADDFUNC2_NOLIST(header, address, source.corporation.address) +DEFINE_ADDFUNC2(header, user_data, extra) + void header_add_phone(Gom_ctxt ctxt, const char* phone) { struct header *head = SAFE_CTXT_CAST(header, ctxt); @@ -85,13 +81,6 @@ void header_add_phone(Gom_ctxt ctxt, const char* phone) } } -void header_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct header *head = SAFE_CTXT_CAST(header, ctxt); - if (head) - LINK_CHAIN_ELT(user_data, head->extra, data); -} - void header_subscribe() { gedcom_subscribe_to_record(REC_HEAD, head_start, def_rec_end); @@ -137,7 +126,7 @@ void header_cleanup() SAFE_FREE(gom_header.source.name); SAFE_FREE(gom_header.source.version); SAFE_FREE(gom_header.source.corporation.name); - address_cleanup(gom_header.source.corporation.address); + CLEANFUNC(address)(gom_header.source.corporation.address); SAFE_FREE(gom_header.source.corporation.phone[0]); SAFE_FREE(gom_header.source.corporation.phone[1]); SAFE_FREE(gom_header.source.corporation.phone[2]); @@ -156,7 +145,7 @@ void header_cleanup() SAFE_FREE(gom_header.language); SAFE_FREE(gom_header.place_hierarchy); SAFE_FREE(gom_header.note); - DESTROY_CHAIN_ELTS(user_data, gom_header.extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, gom_header.extra); } struct header* gom_get_header() diff --git a/gom/header.h b/gom/header.h index 689fd85..8b2788c 100644 --- a/gom/header.h +++ b/gom/header.h @@ -29,9 +29,11 @@ void header_subscribe(); void header_cleanup(); -void header_add_address(Gom_ctxt header, struct address* addr); -void header_add_phone (Gom_ctxt header, const char* phone); -void header_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_header(Gedcom_write_hndl hndl); +DECLARE_ADDFUNC2(header, user_data); +DECLARE_ADDFUNC2_NOLIST(header, address); + +void header_add_phone (Gom_ctxt header, const char* phone); + #endif /* __HEADER_H */ diff --git a/gom/individual.c b/gom/individual.c index 6e8c3fc..103ad31 100644 --- a/gom/individual.c +++ b/gom/individual.c @@ -42,18 +42,34 @@ struct individual* gom_first_individual = NULL; -REC_CB(individual, indi_start, make_individual_record) -GET_REC_BY_XREF(individual, XREF_INDI, gom_get_individual_by_xref) -STRING_CB(individual, indi_resn_start, restriction_notice) -STRING_CB(individual, indi_sex_start, sex) -XREF_LIST_CB(individual, indi_subm_start, submitters, make_submitter_record) -XREF_LIST_CB(individual, indi_alia_start, alias, make_individual_record) -XREF_LIST_CB(individual, indi_anci_start, ancestor_interest, - make_submitter_record) -XREF_LIST_CB(individual, indi_desi_start, descendant_interest, - make_submitter_record) -STRING_CB(individual, indi_rfn_start, record_file_nr) -STRING_CB(individual, indi_afn_start, ancestral_file_nr) +DEFINE_MAKEFUNC(individual, gom_first_individual) +DEFINE_DESTROYFUNC(individual, gom_first_individual) +DEFINE_ADDFUNC(individual, XREF_INDI) +DEFINE_DELETEFUNC(individual) +DEFINE_GETXREFFUNC(individual, XREF_INDI) + +DEFINE_REC_CB(individual, indi_start) +DEFINE_STRING_CB(individual, indi_resn_start, restriction_notice) +DEFINE_STRING_CB(individual, indi_sex_start, sex) +DEFINE_XREF_LIST_CB(individual, indi_subm_start, submitters, submitter) +DEFINE_XREF_LIST_CB(individual, indi_alia_start, alias, individual) +DEFINE_XREF_LIST_CB(individual, indi_anci_start, ancestor_interest, submitter) +DEFINE_XREF_LIST_CB(individual, indi_desi_start, descendant_interest,submitter) +DEFINE_STRING_CB(individual, indi_rfn_start, record_file_nr) +DEFINE_STRING_CB(individual, indi_afn_start, ancestral_file_nr) + +DEFINE_ADDFUNC2(individual, event, event) +DEFINE_ADDFUNC2_TOVAR(individual, event, attribute) +DEFINE_ADDFUNC2(individual, personal_name, name) +DEFINE_ADDFUNC2(individual, lds_event, lds_individual_ordinance) +DEFINE_ADDFUNC2(individual, association, association) +DEFINE_ADDFUNC2(individual, source_citation, citation) +DEFINE_ADDFUNC2(individual, multimedia_link, mm_link) +DEFINE_ADDFUNC2(individual, note_sub, note) +DEFINE_ADDFUNC2(individual, user_ref_number, ref) +DEFINE_ADDFUNC2(individual, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(individual, change_date, change_date) +DEFINE_ADDFUNC2_STR(individual, record_id) void individual_subscribe() { @@ -68,34 +84,6 @@ void individual_subscribe() gedcom_subscribe_to_element(ELT_INDI_AFN, indi_afn_start, def_elt_end); } -void individual_add_event(Gom_ctxt ctxt, struct event* evt) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(event, indiv->event, evt); -} - -void individual_add_attribute(Gom_ctxt ctxt, struct event* evt) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(event, indiv->attribute, evt); -} - -void individual_add_name(Gom_ctxt ctxt, struct personal_name* name) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(personal_name, indiv->name, name); -} - -void individual_add_lio(Gom_ctxt ctxt, struct lds_event* evt) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(lds_event, indiv->lds_individual_ordinance, evt); -} - void individual_add_family_link(Gom_ctxt ctxt, int ctxt_type, struct family_link* link) { @@ -114,98 +102,38 @@ void individual_add_family_link(Gom_ctxt ctxt, int ctxt_type, } } -void individual_add_association(Gom_ctxt ctxt, struct association* assoc) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(association, indiv->association, assoc); -} - -void individual_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(source_citation, indiv->citation, cit); -} - -void individual_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(multimedia_link, indiv->mm_link, link); -} - -void individual_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(note_sub, indiv->note, note); -} - -void individual_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - LINK_CHAIN_ELT(user_ref_number, indiv->ref, ref); -} - -void individual_set_record_id(Gom_ctxt ctxt, const char *rin) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) { - indiv->record_id = strdup(rin); - if (! indiv->record_id) MEMORY_ERROR; - } -} - -void individual_set_change_date(Gom_ctxt ctxt, struct change_date* chan) -{ - struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - if (indiv) - indiv->change_date = chan; -} - -void individual_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct individual *obj = SAFE_CTXT_CAST(individual, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void individual_cleanup(struct individual* indiv) +void CLEANFUNC(individual)(struct individual* indiv) { if (indiv) { SAFE_FREE(indiv->xrefstr); SAFE_FREE(indiv->restriction_notice); - DESTROY_CHAIN_ELTS(personal_name, indiv->name, name_cleanup); + DESTROY_CHAIN_ELTS(personal_name, indiv->name); SAFE_FREE(indiv->sex); - DESTROY_CHAIN_ELTS(event, indiv->event, event_cleanup); - DESTROY_CHAIN_ELTS(event, indiv->attribute, event_cleanup); - DESTROY_CHAIN_ELTS(lds_event, indiv->lds_individual_ordinance, - lds_event_cleanup); - DESTROY_CHAIN_ELTS(family_link,indiv->child_to_family,family_link_cleanup); - DESTROY_CHAIN_ELTS(family_link,indiv->spouse_to_family, - family_link_cleanup); - DESTROY_CHAIN_ELTS(xref_list, indiv->submitters, NULL_DESTROY); - DESTROY_CHAIN_ELTS(association, indiv->association, association_cleanup); - DESTROY_CHAIN_ELTS(xref_list, indiv->alias, NULL_DESTROY); - DESTROY_CHAIN_ELTS(xref_list, indiv->ancestor_interest, NULL_DESTROY); - DESTROY_CHAIN_ELTS(xref_list, indiv->descendant_interest, NULL_DESTROY); - DESTROY_CHAIN_ELTS(source_citation, indiv->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(multimedia_link,indiv->mm_link,multimedia_link_cleanup); - DESTROY_CHAIN_ELTS(note_sub, indiv->note, note_sub_cleanup); + DESTROY_CHAIN_ELTS(event, indiv->event); + DESTROY_CHAIN_ELTS(event, indiv->attribute); + DESTROY_CHAIN_ELTS(lds_event, indiv->lds_individual_ordinance); + DESTROY_CHAIN_ELTS(family_link, indiv->child_to_family); + DESTROY_CHAIN_ELTS(family_link, indiv->spouse_to_family); + DESTROY_CHAIN_ELTS(xref_list, indiv->submitters); + DESTROY_CHAIN_ELTS(association, indiv->association); + DESTROY_CHAIN_ELTS(xref_list, indiv->alias); + DESTROY_CHAIN_ELTS(xref_list, indiv->ancestor_interest); + DESTROY_CHAIN_ELTS(xref_list, indiv->descendant_interest); + DESTROY_CHAIN_ELTS(source_citation, indiv->citation); + DESTROY_CHAIN_ELTS(multimedia_link, indiv->mm_link); + DESTROY_CHAIN_ELTS(note_sub, indiv->note); SAFE_FREE(indiv->record_file_nr); SAFE_FREE(indiv->ancestral_file_nr); - DESTROY_CHAIN_ELTS(user_ref_number, indiv->ref, user_ref_cleanup); + DESTROY_CHAIN_ELTS(user_ref_number, indiv->ref); SAFE_FREE(indiv->record_id); - change_date_cleanup(indiv->change_date); - DESTROY_CHAIN_ELTS(user_data, indiv->extra, user_data_cleanup); + CLEANFUNC(change_date)(indiv->change_date); + DESTROY_CHAIN_ELTS(user_data, indiv->extra); } } void individuals_cleanup() { - DESTROY_CHAIN_ELTS(individual, gom_first_individual, individual_cleanup); + DESTROY_CHAIN_ELTS(individual, gom_first_individual); } struct individual* gom_get_first_individual() @@ -213,17 +141,6 @@ struct individual* gom_get_first_individual() return gom_first_individual; } -struct individual* make_individual_record(const char* xrefstr) -{ - struct individual* indiv = NULL; - MAKE_CHAIN_ELT(individual, gom_first_individual, indiv); - if (indiv) { - indiv->xrefstr = strdup(xrefstr); - if (! indiv->xrefstr) MEMORY_ERROR; - } - return indiv; -} - int write_individuals(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/individual.h b/gom/individual.h index 51a233e..6762f48 100644 --- a/gom/individual.h +++ b/gom/individual.h @@ -29,21 +29,23 @@ void individual_subscribe(); void individuals_cleanup(); -struct individual* make_individual_record(const char* xref); -void individual_add_event(Gom_ctxt ctxt, struct event* evt); -void individual_add_attribute(Gom_ctxt ctxt, struct event* evt); -void individual_add_name(Gom_ctxt ctxt, struct personal_name* name); -void individual_add_lio(Gom_ctxt ctxt, struct lds_event* evt); +int write_individuals(Gedcom_write_hndl hndl); + +DECLARE_MAKEFUNC(individual); +DECLARE_ADDFUNC2(individual, event); +DECLARE_ADDFUNC2(individual, personal_name); +DECLARE_ADDFUNC2(individual, lds_event); +DECLARE_ADDFUNC2(individual, association); +DECLARE_ADDFUNC2(individual, source_citation); +DECLARE_ADDFUNC2(individual, multimedia_link); +DECLARE_ADDFUNC2(individual, note_sub); +DECLARE_ADDFUNC2(individual, user_ref_number); +DECLARE_ADDFUNC2(individual, user_data); +DECLARE_ADDFUNC2_TOVAR(individual, event, attribute); +DECLARE_ADDFUNC2_NOLIST(individual, change_date); +DECLARE_ADDFUNC2_STR(individual, record_id); + void individual_add_family_link(Gom_ctxt ctxt, int ctxt_type, struct family_link* link); -void individual_add_association(Gom_ctxt ctxt, struct association* assoc); -void individual_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void individual_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link); -void individual_add_note(Gom_ctxt ctxt, struct note_sub* note); -void individual_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref); -void individual_set_record_id(Gom_ctxt ctxt, const char *rin); -void individual_set_change_date(Gom_ctxt ctxt, struct change_date* chan); -void individual_add_user_data(Gom_ctxt ctxt, struct user_data* data); -int write_individuals(Gedcom_write_hndl hndl); #endif /* __INDIVIDUAL_H */ diff --git a/gom/lds_event.c b/gom/lds_event.c index ac8db42..c498729 100644 --- a/gom/lds_event.c +++ b/gom/lds_event.c @@ -56,9 +56,9 @@ Gedcom_ctxt sub_lds_event_start(_ELT_PARAMS_) else { switch (ctxt->ctxt_type) { case REC_FAM: - family_add_lss(ctxt, lds_evt); break; + ADDFUNC2(family,lds_event)(ctxt, lds_evt); break; case REC_INDI: - individual_add_lio(ctxt, lds_evt); break; + ADDFUNC2(individual,lds_event)(ctxt, lds_evt); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -70,11 +70,15 @@ Gedcom_ctxt sub_lds_event_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(lds_event, sub_lds_event_stat_start, date_status) -DATE_CB(lds_event, sub_lds_event_date_start, date) -STRING_CB(lds_event, sub_lds_event_temp_start, temple_code) -STRING_CB(lds_event, sub_lds_event_plac_start, place_living_ordinance) -XREF_CB(lds_event, sub_lds_event_famc_start, family, make_family_record) +DEFINE_STRING_CB(lds_event, sub_lds_event_stat_start, date_status) +DEFINE_DATE_CB(lds_event, sub_lds_event_date_start, date) +DEFINE_STRING_CB(lds_event, sub_lds_event_temp_start, temple_code) +DEFINE_STRING_CB(lds_event, sub_lds_event_plac_start, place_living_ordinance) +DEFINE_XREF_CB(lds_event, sub_lds_event_famc_start, family, family) + +DEFINE_ADDFUNC2(lds_event, note_sub, note) +DEFINE_ADDFUNC2(lds_event, source_citation, citation) +DEFINE_ADDFUNC2(lds_event, user_data, extra) void lds_event_subscribe() { @@ -104,28 +108,7 @@ void lds_event_subscribe() sub_lds_event_famc_start, def_elt_end); } -void lds_event_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct lds_event *lds = SAFE_CTXT_CAST(lds_event, ctxt); - if (lds) - LINK_CHAIN_ELT(note_sub, lds->note, note); -} - -void lds_event_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct lds_event *lds = SAFE_CTXT_CAST(lds_event, ctxt); - if (lds) - LINK_CHAIN_ELT(source_citation, lds->citation, cit); -} - -void lds_event_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct lds_event *obj = SAFE_CTXT_CAST(lds_event, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void lds_event_cleanup(struct lds_event* lds) +void CLEANFUNC(lds_event)(struct lds_event* lds) { if (lds) { SAFE_FREE(lds->event_name); @@ -133,9 +116,9 @@ void lds_event_cleanup(struct lds_event* lds) SAFE_FREE(lds->date); SAFE_FREE(lds->temple_code); SAFE_FREE(lds->place_living_ordinance); - DESTROY_CHAIN_ELTS(source_citation, lds->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(note_sub, lds->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_data, lds->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(source_citation, lds->citation); + DESTROY_CHAIN_ELTS(note_sub, lds->note); + DESTROY_CHAIN_ELTS(user_data, lds->extra); } } diff --git a/gom/lds_event.h b/gom/lds_event.h index 48da41a..e313249 100644 --- a/gom/lds_event.h +++ b/gom/lds_event.h @@ -29,11 +29,12 @@ #include "gom_internal.h" void lds_event_subscribe(); -void lds_event_cleanup(struct lds_event* mm); -void lds_event_add_note(Gom_ctxt ctxt, struct note_sub* note); -void lds_event_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void lds_event_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_lds_events(Gedcom_write_hndl hndl, int parent, struct lds_event *lds); +DECLARE_CLEANFUNC(lds_event); +DECLARE_ADDFUNC2(lds_event, note_sub); +DECLARE_ADDFUNC2(lds_event, source_citation); +DECLARE_ADDFUNC2(lds_event, user_data); + #endif /* __LDS_EVENT_H */ diff --git a/gom/multimedia.c b/gom/multimedia.c index 5fb331c..38ffa3f 100644 --- a/gom/multimedia.c +++ b/gom/multimedia.c @@ -34,13 +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) -STRING_END_CB(multimedia, obje_blob_end, data) -XREF_CB(multimedia, obje_obje_start, continued, make_multimedia_record) +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_) { @@ -66,61 +77,24 @@ 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) -{ - struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt); - if (obj) { - obj->record_id = strdup(rin); - if (! obj->record_id) MEMORY_ERROR; - } -} - -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() @@ -128,17 +102,6 @@ struct multimedia* gom_get_first_multimedia() return gom_first_multimedia; } -struct multimedia* make_multimedia_record(const char* xrefstr) -{ - struct multimedia* multi = NULL; - MAKE_CHAIN_ELT(multimedia, gom_first_multimedia, multi); - if (multi) { - multi->xrefstr = strdup(xrefstr); - if (! multi->xrefstr) MEMORY_ERROR; - } - return multi; -} - int write_multimedia_recs(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/multimedia.h b/gom/multimedia.h index 00353df..720b53c 100644 --- a/gom/multimedia.h +++ b/gom/multimedia.h @@ -29,12 +29,13 @@ void multimedia_subscribe(); void multimedias_cleanup(); -struct multimedia* make_multimedia_record(const char* xref); -void multimedia_add_note(Gom_ctxt ctxt, struct note_sub* note); -void multimedia_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref); -void multimedia_set_record_id(Gom_ctxt ctxt, const char *rin); -void multimedia_set_change_date(Gom_ctxt ctxt, struct change_date* chan); -void multimedia_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_multimedia_recs(Gedcom_write_hndl hndl); +DECLARE_MAKEFUNC(multimedia); +DECLARE_ADDFUNC2(multimedia, note_sub); +DECLARE_ADDFUNC2(multimedia, user_ref_number); +DECLARE_ADDFUNC2(multimedia, user_data); +DECLARE_ADDFUNC2_NOLIST(multimedia, change_date); +DECLARE_ADDFUNC2_STR(multimedia, record_id); + #endif /* __MULTIMEDIA_H */ diff --git a/gom/multimedia_link.c b/gom/multimedia_link.c index f6044ff..147b838 100644 --- a/gom/multimedia_link.c +++ b/gom/multimedia_link.c @@ -62,17 +62,17 @@ Gedcom_ctxt sub_obje_start(_ELT_PARAMS_) case ELT_SUB_INDIV_GEN: case ELT_SUB_INDIV_ADOP: case ELT_SUB_INDIV_EVEN: - event_add_mm_link(ctxt, mm); break; + ADDFUNC2(event,multimedia_link)(ctxt, mm); break; case ELT_SUB_SOUR: - citation_add_mm_link(ctxt, mm); break; + ADDFUNC2(source_citation,multimedia_link)(ctxt, mm); break; case REC_FAM: - family_add_mm_link(ctxt, mm); break; + ADDFUNC2(family,multimedia_link)(ctxt, mm); break; case REC_INDI: - individual_add_mm_link(ctxt, mm); break; + ADDFUNC2(individual,multimedia_link)(ctxt, mm); break; case REC_SOUR: - source_add_mm_link(ctxt, mm); break; + ADDFUNC2(source,multimedia_link)(ctxt, mm); break; case REC_SUBM: - submitter_add_mm_link(ctxt, mm); break; + ADDFUNC2(submitter,multimedia_link)(ctxt, mm); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -83,9 +83,12 @@ Gedcom_ctxt sub_obje_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(multimedia_link, sub_obje_form_start, form) -STRING_CB(multimedia_link, sub_obje_titl_start, title) -STRING_CB(multimedia_link, sub_obje_file_start, file) +DEFINE_STRING_CB(multimedia_link, sub_obje_form_start, form) +DEFINE_STRING_CB(multimedia_link, sub_obje_titl_start, title) +DEFINE_STRING_CB(multimedia_link, sub_obje_file_start, file) + +DEFINE_ADDFUNC2(multimedia_link, note_sub, note) +DEFINE_ADDFUNC2(multimedia_link, user_data, extra) void multimedia_link_subscribe() { @@ -99,28 +102,14 @@ void multimedia_link_subscribe() sub_obje_file_start, def_elt_end); } -void multimedia_link_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct multimedia_link *mm = SAFE_CTXT_CAST(multimedia_link, ctxt); - if (mm) - LINK_CHAIN_ELT(note_sub, mm->note, note); -} - -void multimedia_link_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct multimedia_link *obj = SAFE_CTXT_CAST(multimedia_link, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void multimedia_link_cleanup(struct multimedia_link* mm) +void CLEANFUNC(multimedia_link)(struct multimedia_link* mm) { if (mm) { SAFE_FREE(mm->form); SAFE_FREE(mm->title); SAFE_FREE(mm->file); - DESTROY_CHAIN_ELTS(note_sub, mm->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_data, mm->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(note_sub, mm->note); + DESTROY_CHAIN_ELTS(user_data, mm->extra); } } diff --git a/gom/multimedia_link.h b/gom/multimedia_link.h index 4ab2684..cb396fd 100644 --- a/gom/multimedia_link.h +++ b/gom/multimedia_link.h @@ -29,10 +29,11 @@ #include "gom_internal.h" void multimedia_link_subscribe(); -void multimedia_link_cleanup(struct multimedia_link* mm); -void multimedia_link_add_note(Gom_ctxt ctxt, struct note_sub* note); -void multimedia_link_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_multimedia_links(Gedcom_write_hndl hndl, int parent, struct multimedia_link* mm); +DECLARE_CLEANFUNC(multimedia_link); +DECLARE_ADDFUNC2(multimedia_link, note_sub); +DECLARE_ADDFUNC2(multimedia_link, user_data); + #endif /* __MULTIMEDIA_LINK_H */ diff --git a/gom/note.c b/gom/note.c index 7f74a30..3c8bc69 100644 --- a/gom/note.c +++ b/gom/note.c @@ -43,7 +43,7 @@ Gedcom_ctxt note_start(_REC_PARAMS_) struct xref_value* xr = GEDCOM_XREF_PTR(xref); struct note* note = (struct note*) xr->object; if (! note) { - note = make_note_record(xr->string); + note = MAKEFUNC(note)(xr->string); xr->object = (Gedcom_ctxt) note; } if (note) @@ -51,8 +51,19 @@ Gedcom_ctxt note_start(_REC_PARAMS_) return (Gedcom_ctxt)result; } -STRING_END_REC_CB(note, note_end, text) -GET_REC_BY_XREF(note, XREF_NOTE, gom_get_note_by_xref) +DEFINE_MAKEFUNC(note, gom_first_note) +DEFINE_DESTROYFUNC(note, gom_first_note) +DEFINE_ADDFUNC(note, XREF_NOTE) +DEFINE_DELETEFUNC(note) +DEFINE_GETXREFFUNC(note, XREF_NOTE) + +DEFINE_STRING_END_REC_CB(note, note_end, text) + +DEFINE_ADDFUNC2(note, source_citation, citation) +DEFINE_ADDFUNC2(note, user_ref_number, ref) +DEFINE_ADDFUNC2(note, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(note, change_date, change_date) +DEFINE_ADDFUNC2_STR(note, record_id) Gedcom_ctxt sub_cont_conc_start(_ELT_PARAMS_) { @@ -74,59 +85,22 @@ void note_subscribe() gedcom_subscribe_to_element(ELT_SUB_CONC, sub_cont_conc_start, def_elt_end); } -void note_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct note *note = SAFE_CTXT_CAST(note, ctxt); - if (note) - LINK_CHAIN_ELT(source_citation, note->citation, cit); -} - -void note_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref) -{ - struct note *note = SAFE_CTXT_CAST(note, ctxt); - if (note) - LINK_CHAIN_ELT(user_ref_number, note->ref, ref); -} - -void note_set_record_id(Gom_ctxt ctxt, const char *rin) -{ - struct note *note = SAFE_CTXT_CAST(note, ctxt); - if (note) { - note->record_id = strdup(rin); - if (! note->record_id) MEMORY_ERROR; - } -} - -void note_set_change_date(Gom_ctxt ctxt, struct change_date* chan) -{ - struct note *note = SAFE_CTXT_CAST(note, ctxt); - if (note) - note->change_date = chan; -} - -void note_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct note *obj = SAFE_CTXT_CAST(note, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void note_cleanup(struct note* note) +void CLEANFUNC(note)(struct note* note) { if (note) { SAFE_FREE(note->xrefstr); SAFE_FREE(note->text); - DESTROY_CHAIN_ELTS(source_citation, note->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(user_ref_number, note->ref, user_ref_cleanup); + DESTROY_CHAIN_ELTS(source_citation, note->citation); + DESTROY_CHAIN_ELTS(user_ref_number, note->ref); SAFE_FREE(note->record_id); - change_date_cleanup(note->change_date); - DESTROY_CHAIN_ELTS(user_data, note->extra, user_data_cleanup); + CLEANFUNC(change_date)(note->change_date); + DESTROY_CHAIN_ELTS(user_data, note->extra); } } void notes_cleanup() { - DESTROY_CHAIN_ELTS(note, gom_first_note, note_cleanup); + DESTROY_CHAIN_ELTS(note, gom_first_note); } struct note* gom_get_first_note() @@ -134,17 +108,6 @@ struct note* gom_get_first_note() return gom_first_note; } -struct note* make_note_record(const char* xrefstr) -{ - struct note* note = NULL; - MAKE_CHAIN_ELT(note, gom_first_note, note); - if (note) { - note->xrefstr = strdup(xrefstr); - if (! note->xrefstr) MEMORY_ERROR; - } - return note; -} - int write_notes(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/note.h b/gom/note.h index a2f6eda..a8f54c5 100644 --- a/gom/note.h +++ b/gom/note.h @@ -29,12 +29,13 @@ void note_subscribe(); void notes_cleanup(); -struct note* make_note_record(const char* xref); -void note_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void note_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref); -void note_set_record_id(Gom_ctxt ctxt, const char *rin); -void note_set_change_date(Gom_ctxt ctxt, struct change_date* chan); -void note_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_notes(Gedcom_write_hndl hndl); +DECLARE_MAKEFUNC(note); +DECLARE_ADDFUNC2(note, source_citation); +DECLARE_ADDFUNC2(note, user_ref_number); +DECLARE_ADDFUNC2(note, user_data); +DECLARE_ADDFUNC2_NOLIST(note, change_date); +DECLARE_ADDFUNC2_STR(note, record_id); + #endif /* __NOTE_H */ diff --git a/gom/note_sub.c b/gom/note_sub.c index 63ef644..5af12ca 100644 --- a/gom/note_sub.c +++ b/gom/note_sub.c @@ -62,7 +62,7 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) switch (ctxt->ctxt_type) { case ELT_SUB_PLAC: - place_add_note(ctxt, note); break; + ADDFUNC2(place,note_sub)(ctxt, note); break; case ELT_SUB_FAM_EVT: case ELT_SUB_FAM_EVT_EVEN: case ELT_SUB_INDIV_ATTR: @@ -71,38 +71,38 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) case ELT_SUB_INDIV_GEN: case ELT_SUB_INDIV_ADOP: case ELT_SUB_INDIV_EVEN: - event_add_note(ctxt, note); break; + ADDFUNC2(event,note_sub)(ctxt, note); break; case ELT_SUB_SOUR: - citation_add_note(ctxt, note); break; + ADDFUNC2(source_citation,note_sub)(ctxt, note); break; case ELT_SUB_MULTIM_OBJE: - multimedia_link_add_note(ctxt, note); break; + ADDFUNC2(multimedia_link,note_sub)(ctxt, note); break; case ELT_SUB_LSS_SLGS: case ELT_SUB_LIO_BAPL: case ELT_SUB_LIO_SLGC: - lds_event_add_note(ctxt, note); break; + ADDFUNC2(lds_event,note_sub)(ctxt, note); break; case REC_FAM: - family_add_note(ctxt, note); break; + ADDFUNC2(family,note_sub)(ctxt, note); break; case ELT_SUB_CHAN: - change_date_add_note(ctxt, note); break; + ADDFUNC2(change_date,note_sub)(ctxt, note); break; case ELT_SUB_PERS_NAME: - name_add_note(ctxt, note); break; + ADDFUNC2(personal_name,note_sub)(ctxt, note); break; case ELT_SUB_FAMC: case ELT_SUB_FAMS: - family_link_add_note(ctxt, note); break; + ADDFUNC2(family_link,note_sub)(ctxt, note); break; case ELT_SUB_ASSO: - association_add_note(ctxt, note); break; + ADDFUNC2(association,note_sub)(ctxt, note); break; case REC_INDI: - individual_add_note(ctxt, note); break; + ADDFUNC2(individual,note_sub)(ctxt, note); break; case REC_OBJE: - multimedia_add_note(ctxt, note); break; + ADDFUNC2(multimedia,note_sub)(ctxt, note); break; case REC_REPO: - repository_add_note(ctxt, note); break; + ADDFUNC2(repository,note_sub)(ctxt, note); break; case ELT_SOUR_DATA: source_add_note_to_data(ctxt, note); break; case ELT_SUB_REPO: source_add_note_to_repo(ctxt, note); break; case REC_SOUR: - source_add_note(ctxt, note); break; + ADDFUNC2(source,note_sub)(ctxt, note); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -113,33 +113,22 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_END_CB(note_sub, sub_note_end, text) +DEFINE_STRING_END_CB(note_sub, sub_note_end, text) + +DEFINE_ADDFUNC2(note_sub, source_citation, citation) +DEFINE_ADDFUNC2(note_sub, user_data, extra) void note_sub_subscribe() { gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end); } -void note_sub_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct note_sub *note = SAFE_CTXT_CAST(note_sub, ctxt); - if (note) - LINK_CHAIN_ELT(source_citation, note->citation, cit); -} - -void note_sub_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct note_sub *obj = SAFE_CTXT_CAST(note_sub, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data);; -} - -void note_sub_cleanup(struct note_sub* note) +void CLEANFUNC(note_sub)(struct note_sub* note) { if (note) { SAFE_FREE(note->text); - DESTROY_CHAIN_ELTS(source_citation, note->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(user_data, note->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(source_citation, note->citation); + DESTROY_CHAIN_ELTS(user_data, note->extra); } } diff --git a/gom/note_sub.h b/gom/note_sub.h index b543eb0..43eca9f 100644 --- a/gom/note_sub.h +++ b/gom/note_sub.h @@ -28,9 +28,10 @@ #include "gom_internal.h" void note_sub_subscribe(); -void note_sub_cleanup(struct note_sub* note); -void note_sub_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void note_sub_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_note_subs(Gedcom_write_hndl hndl, int parent, struct note_sub* note); +DECLARE_CLEANFUNC(note_sub); +DECLARE_ADDFUNC2(note_sub, source_citation); +DECLARE_ADDFUNC2(note_sub, user_data); + #endif /* __NOTE_SUB_H */ diff --git a/gom/personal_name.c b/gom/personal_name.c index 6345b29..fce4ca7 100644 --- a/gom/personal_name.c +++ b/gom/personal_name.c @@ -53,7 +53,7 @@ Gedcom_ctxt sub_name_start(_ELT_PARAMS_) else { switch (ctxt->ctxt_type) { case REC_INDI: - individual_add_name(ctxt, name); break; + ADDFUNC2(individual,personal_name)(ctxt, name); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -65,33 +65,16 @@ Gedcom_ctxt sub_name_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(personal_name, sub_name_npfx_start, prefix) -STRING_CB(personal_name, sub_name_givn_start, given) -STRING_CB(personal_name, sub_name_nick_start, nickname) -STRING_CB(personal_name, sub_name_spfx_start, surname_prefix) -STRING_CB(personal_name, sub_name_surn_start, surname) -STRING_CB(personal_name, sub_name_nsfx_start, suffix) +DEFINE_STRING_CB(personal_name, sub_name_npfx_start, prefix) +DEFINE_STRING_CB(personal_name, sub_name_givn_start, given) +DEFINE_STRING_CB(personal_name, sub_name_nick_start, nickname) +DEFINE_STRING_CB(personal_name, sub_name_spfx_start, surname_prefix) +DEFINE_STRING_CB(personal_name, sub_name_surn_start, surname) +DEFINE_STRING_CB(personal_name, sub_name_nsfx_start, suffix) -void name_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct personal_name *name = SAFE_CTXT_CAST(personal_name, ctxt); - if (name) - LINK_CHAIN_ELT(source_citation, name->citation, cit); -} - -void name_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct personal_name *name = SAFE_CTXT_CAST(personal_name, ctxt); - if (name) - LINK_CHAIN_ELT(note_sub, name->note, note); -} - -void name_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct personal_name *obj = SAFE_CTXT_CAST(personal_name, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} +DEFINE_ADDFUNC2(personal_name, source_citation, citation) +DEFINE_ADDFUNC2(personal_name, note_sub, note) +DEFINE_ADDFUNC2(personal_name, user_data, extra) void name_subscribe() { @@ -110,7 +93,7 @@ void name_subscribe() def_elt_end); } -void name_cleanup(struct personal_name* name) +void CLEANFUNC(personal_name)(struct personal_name* name) { if (name) { SAFE_FREE(name->name); @@ -120,9 +103,9 @@ void name_cleanup(struct personal_name* name) SAFE_FREE(name->surname_prefix); SAFE_FREE(name->surname); SAFE_FREE(name->suffix); - DESTROY_CHAIN_ELTS(source_citation, name->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(note_sub, name->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_data, name->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(source_citation, name->citation); + DESTROY_CHAIN_ELTS(note_sub, name->note); + DESTROY_CHAIN_ELTS(user_data, name->extra); } } diff --git a/gom/personal_name.h b/gom/personal_name.h index 85587d1..b2dcce0 100644 --- a/gom/personal_name.h +++ b/gom/personal_name.h @@ -28,11 +28,12 @@ #include "gom_internal.h" void name_subscribe(); -void name_cleanup(struct personal_name* name); -void name_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void name_add_note(Gom_ctxt ctxt, struct note_sub* note); -void name_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_names(Gedcom_write_hndl hndl, int parent, struct personal_name *name); +DECLARE_CLEANFUNC(personal_name); +DECLARE_ADDFUNC2(personal_name, source_citation); +DECLARE_ADDFUNC2(personal_name, note_sub); +DECLARE_ADDFUNC2(personal_name, user_data); + #endif /* __PERSONAL_NAME_H */ diff --git a/gom/place.c b/gom/place.c index 7385a56..8ceb152 100644 --- a/gom/place.c +++ b/gom/place.c @@ -62,7 +62,7 @@ Gedcom_ctxt sub_place_start(_ELT_PARAMS_) case ELT_SUB_INDIV_GEN: case ELT_SUB_INDIV_ADOP: case ELT_SUB_INDIV_EVEN: - event_add_place(ctxt, place); break; + ADDFUNC2_NOLIST(event,place)(ctxt, place); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -74,28 +74,11 @@ Gedcom_ctxt sub_place_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(place, sub_place_form_start, place_hierarchy) +DEFINE_STRING_CB(place, sub_place_form_start, place_hierarchy) -void place_add_citation(Gom_ctxt ctxt, struct source_citation* cit) -{ - struct place *place = SAFE_CTXT_CAST(place, ctxt); - if (place) - LINK_CHAIN_ELT(source_citation, place->citation, cit); -} - -void place_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct place *place = SAFE_CTXT_CAST(place, ctxt); - if (place) - LINK_CHAIN_ELT(note_sub, place->note, note); -} - -void place_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct place *obj = SAFE_CTXT_CAST(place, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} +DEFINE_ADDFUNC2(place, source_citation, citation) +DEFINE_ADDFUNC2(place, note_sub, note) +DEFINE_ADDFUNC2(place, user_data, extra) void place_subscribe() { @@ -104,14 +87,14 @@ void place_subscribe() sub_place_form_start, def_elt_end); } -void place_cleanup(struct place* place) +void CLEANFUNC(place)(struct place* place) { if (place) { SAFE_FREE(place->value); SAFE_FREE(place->place_hierarchy); - DESTROY_CHAIN_ELTS(source_citation, place->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(note_sub, place->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_data, place->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(source_citation, place->citation); + DESTROY_CHAIN_ELTS(note_sub, place->note); + DESTROY_CHAIN_ELTS(user_data, place->extra); } SAFE_FREE(place); } diff --git a/gom/place.h b/gom/place.h index a2ca02d..81291d3 100644 --- a/gom/place.h +++ b/gom/place.h @@ -28,10 +28,11 @@ #include "gom_internal.h" void place_subscribe(); -void place_cleanup(struct place* place); -void place_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void place_add_note(Gom_ctxt ctxt, struct note_sub* note); -void place_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_place(Gedcom_write_hndl hndl, int parent, struct place* place); +DECLARE_CLEANFUNC(place); +DECLARE_ADDFUNC2(place, source_citation); +DECLARE_ADDFUNC2(place, note_sub); +DECLARE_ADDFUNC2(place, user_data); + #endif /* __PLACE_H */ diff --git a/gom/repository.c b/gom/repository.c index 3df7388..9d383fa 100644 --- a/gom/repository.c +++ b/gom/repository.c @@ -35,9 +35,22 @@ struct repository* gom_first_repository = NULL; -REC_CB(repository, repo_start, make_repository_record) -GET_REC_BY_XREF(repository, XREF_REPO, gom_get_repository_by_xref) -STRING_CB(repository, repo_name_start, name) +DEFINE_MAKEFUNC(repository, gom_first_repository) +DEFINE_DESTROYFUNC(repository, gom_first_repository) +DEFINE_ADDFUNC(repository, XREF_REPO) +DEFINE_DELETEFUNC(repository) +DEFINE_GETXREFFUNC(repository, XREF_REPO) + +DEFINE_REC_CB(repository, repo_start) +DEFINE_STRING_CB(repository, repo_name_start, name) + +DEFINE_ADDFUNC2(repository, note_sub, note) +DEFINE_ADDFUNC2(repository, user_ref_number, ref) +DEFINE_ADDFUNC2(repository, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(repository, address, address) +DEFINE_ADDFUNC2_NOLIST(repository, change_date, change_date) +DEFINE_ADDFUNC2_STRN(repository, phone, 3) +DEFINE_ADDFUNC2_STR(repository, record_id) void repository_subscribe() { @@ -45,83 +58,26 @@ void repository_subscribe() gedcom_subscribe_to_element(ELT_REPO_NAME, repo_name_start, def_elt_end); } -void repository_add_address(Gom_ctxt ctxt, struct address* address) -{ - struct repository *repo = SAFE_CTXT_CAST(repository, ctxt); - if (repo) - repo->address = address; -} - -void repository_add_phone(Gom_ctxt ctxt, const char *phone) -{ - struct repository *repo = SAFE_CTXT_CAST(repository, ctxt); - if (repo) { - int i = 0; - while (i<2 && repo->phone[i]) i++; - if (! repo->phone[i]) { - repo->phone[i] = strdup(phone); - if (! repo->phone[i]) MEMORY_ERROR; - } - } -} - -void repository_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct repository *repo = SAFE_CTXT_CAST(repository, ctxt); - if (repo) - LINK_CHAIN_ELT(note_sub, repo->note, note); -} - -void repository_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref) -{ - struct repository *repo = SAFE_CTXT_CAST(repository, ctxt); - if (repo) - LINK_CHAIN_ELT(user_ref_number, repo->ref, ref); -} - -void repository_set_record_id(Gom_ctxt ctxt, const char *rin) -{ - struct repository *repo = SAFE_CTXT_CAST(repository, ctxt); - if (repo) { - repo->record_id = strdup(rin); - if (! repo->record_id) MEMORY_ERROR; - } -} - -void repository_set_change_date(Gom_ctxt ctxt, struct change_date* chan) -{ - struct repository *repo = SAFE_CTXT_CAST(repository, ctxt); - if (repo) - repo->change_date = chan; -} - -void repository_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct repository *obj = SAFE_CTXT_CAST(repository, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void repository_cleanup(struct repository* repo) +void CLEANFUNC(repository)(struct repository* repo) { if (repo) { SAFE_FREE(repo->xrefstr); SAFE_FREE(repo->name); - address_cleanup(repo->address); + CLEANFUNC(address)(repo->address); SAFE_FREE(repo->phone[0]); SAFE_FREE(repo->phone[1]); SAFE_FREE(repo->phone[2]); - DESTROY_CHAIN_ELTS(note_sub, repo->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_ref_number, repo->ref, user_ref_cleanup); + DESTROY_CHAIN_ELTS(note_sub, repo->note); + DESTROY_CHAIN_ELTS(user_ref_number, repo->ref); SAFE_FREE(repo->record_id); - change_date_cleanup(repo->change_date); - DESTROY_CHAIN_ELTS(user_data, repo->extra, user_data_cleanup); + CLEANFUNC(change_date)(repo->change_date); + DESTROY_CHAIN_ELTS(user_data, repo->extra); } } void repositories_cleanup() { - DESTROY_CHAIN_ELTS(repository, gom_first_repository, repository_cleanup); + DESTROY_CHAIN_ELTS(repository, gom_first_repository); } struct repository* gom_get_first_repository() @@ -129,17 +85,6 @@ struct repository* gom_get_first_repository() return gom_first_repository; } -struct repository* make_repository_record(const char* xrefstr) -{ - struct repository* repo = NULL; - MAKE_CHAIN_ELT(repository, gom_first_repository, repo); - if (repo) { - repo->xrefstr = strdup(xrefstr); - if (! repo->xrefstr) MEMORY_ERROR; - } - return repo; -} - int write_repositories(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/repository.h b/gom/repository.h index 066d740..ddecc69 100644 --- a/gom/repository.h +++ b/gom/repository.h @@ -29,14 +29,15 @@ void repository_subscribe(); void repositories_cleanup(); -struct repository* make_repository_record(const char* xref); -void repository_add_address(Gom_ctxt ctxt, struct address* address); -void repository_add_phone(Gom_ctxt ctxt, const char *phone); -void repository_add_note(Gom_ctxt ctxt, struct note_sub* note); -void repository_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref); -void repository_set_record_id(Gom_ctxt ctxt, const char *rin); -void repository_set_change_date(Gom_ctxt ctxt, struct change_date* chan); -void repository_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_repositories(Gedcom_write_hndl hndl); +DECLARE_MAKEFUNC(repository); +DECLARE_ADDFUNC2(repository, note_sub); +DECLARE_ADDFUNC2(repository, user_ref_number); +DECLARE_ADDFUNC2(repository, user_data); +DECLARE_ADDFUNC2_NOLIST(repository, address); +DECLARE_ADDFUNC2_NOLIST(repository, change_date); +DECLARE_ADDFUNC2_STRN(repository, phone); +DECLARE_ADDFUNC2_STR(repository, record_id); + #endif /* __REPOSITORY_H */ diff --git a/gom/source.c b/gom/source.c index 024fa23..c13acb3 100644 --- a/gom/source.c +++ b/gom/source.c @@ -38,20 +38,34 @@ struct source* gom_first_source = NULL; -REC_CB(source, sour_start, make_source_record) -GET_REC_BY_XREF(source, XREF_SOUR, gom_get_source_by_xref) -NULL_CB(source, sour_data_start) -STRING_CB(source, sour_data_agnc_start, data.agency) -NULL_CB(source, sour_auth_start) /* value set by end callback */ -STRING_END_CB(source, sour_auth_end, author) -NULL_CB(source, sour_titl_start) /* value set by end callback */ -STRING_END_CB(source, sour_titl_end, title) -STRING_CB(source, sour_abbr_start, abbreviation) -NULL_CB(source, sour_publ_start) /* value set by end callback */ -STRING_END_CB(source, sour_publ_end, publication) -NULL_CB(source, sour_text_start) /* value set by end callback */ -STRING_END_CB(source, sour_text_end, text) -XREF_CB(source, sour_repo_start, repository.link, make_repository_record) +DEFINE_MAKEFUNC(source, gom_first_source) +DEFINE_DESTROYFUNC(source, gom_first_source) +DEFINE_ADDFUNC(source, XREF_SOUR) +DEFINE_DELETEFUNC(source) +DEFINE_GETXREFFUNC(source, XREF_SOUR) + +DEFINE_REC_CB(source, sour_start) +DEFINE_NULL_CB(source, sour_data_start) +DEFINE_STRING_CB(source, sour_data_agnc_start, data.agency) +DEFINE_NULL_CB(source, sour_auth_start) /* value set by end callback */ +DEFINE_STRING_END_CB(source, sour_auth_end, author) +DEFINE_NULL_CB(source, sour_titl_start) /* value set by end callback */ +DEFINE_STRING_END_CB(source, sour_titl_end, title) +DEFINE_STRING_CB(source, sour_abbr_start, abbreviation) +DEFINE_NULL_CB(source, sour_publ_start) /* value set by end callback */ +DEFINE_STRING_END_CB(source, sour_publ_end, publication) +DEFINE_NULL_CB(source, sour_text_start) /* value set by end callback */ +DEFINE_STRING_END_CB(source, sour_text_end, text) +DEFINE_XREF_CB(source, sour_repo_start, repository.link, repository) + +DEFINE_ADDFUNC2(source, source_event, data.event) +DEFINE_ADDFUNC2(source, source_description, repository.description) +DEFINE_ADDFUNC2(source, multimedia_link, mm_link) +DEFINE_ADDFUNC2(source, note_sub, note) +DEFINE_ADDFUNC2(source, user_ref_number, ref) +DEFINE_ADDFUNC2(source, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(source, change_date, change_date) +DEFINE_ADDFUNC2_STR(source, record_id) void source_subscribe() { @@ -67,13 +81,6 @@ void source_subscribe() gedcom_subscribe_to_element(ELT_SUB_REPO, sour_repo_start, def_elt_end); } -void source_add_event(Gom_ctxt ctxt, struct source_event* evt) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) - LINK_CHAIN_ELT(source_event, sour->data.event, evt); -} - void source_add_note_to_data(Gom_ctxt ctxt, struct note_sub* note) { struct source *sour = SAFE_CTXT_CAST(source, ctxt); @@ -88,84 +95,32 @@ void source_add_note_to_repo(Gom_ctxt ctxt, struct note_sub* note) LINK_CHAIN_ELT(note_sub, sour->repository.note, note); } -void source_add_description(Gom_ctxt ctxt, struct source_description* desc) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) - LINK_CHAIN_ELT(source_description, sour->repository.description, desc); -} - -void source_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) - LINK_CHAIN_ELT(multimedia_link, sour->mm_link, link); -} - -void source_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) - LINK_CHAIN_ELT(note_sub, sour->note, note); -} - -void source_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) - LINK_CHAIN_ELT(user_ref_number, sour->ref, ref); -} - -void source_set_record_id(Gom_ctxt ctxt, const char *rin) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) { - sour->record_id = strdup(rin); - if (! sour->record_id) MEMORY_ERROR; - } -} - -void source_set_change_date(Gom_ctxt ctxt, struct change_date* chan) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) - sour->change_date = chan; -} - -void source_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct source *obj = SAFE_CTXT_CAST(source, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void source_cleanup(struct source* sour) +void CLEANFUNC(source)(struct source* sour) { if (sour) { SAFE_FREE(sour->xrefstr); - DESTROY_CHAIN_ELTS(source_event, sour->data.event, source_event_cleanup); + DESTROY_CHAIN_ELTS(source_event, sour->data.event); SAFE_FREE(sour->data.agency) - DESTROY_CHAIN_ELTS(note_sub, sour->data.note, note_sub_cleanup); + DESTROY_CHAIN_ELTS(note_sub, sour->data.note); SAFE_FREE(sour->author); SAFE_FREE(sour->title); SAFE_FREE(sour->abbreviation); SAFE_FREE(sour->publication); SAFE_FREE(sour->text); - DESTROY_CHAIN_ELTS(note_sub, sour->repository.note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(source_description, sour->repository.description, - source_description_cleanup); - DESTROY_CHAIN_ELTS(multimedia_link, sour->mm_link,multimedia_link_cleanup); - DESTROY_CHAIN_ELTS(note_sub, sour->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_ref_number, sour->ref, user_ref_cleanup); + DESTROY_CHAIN_ELTS(note_sub, sour->repository.note); + DESTROY_CHAIN_ELTS(source_description, sour->repository.description); + DESTROY_CHAIN_ELTS(multimedia_link, sour->mm_link); + DESTROY_CHAIN_ELTS(note_sub, sour->note); + DESTROY_CHAIN_ELTS(user_ref_number, sour->ref); SAFE_FREE(sour->record_id); - change_date_cleanup(sour->change_date); - DESTROY_CHAIN_ELTS(user_data, sour->extra, user_data_cleanup); + CLEANFUNC(change_date)(sour->change_date); + DESTROY_CHAIN_ELTS(user_data, sour->extra); } } void sources_cleanup() { - DESTROY_CHAIN_ELTS(source, gom_first_source, source_cleanup); + DESTROY_CHAIN_ELTS(source, gom_first_source); } struct source* gom_get_first_source() @@ -173,17 +128,6 @@ struct source* gom_get_first_source() return gom_first_source; } -struct source* make_source_record(const char* xrefstr) -{ - struct source* src = NULL; - MAKE_CHAIN_ELT(source, gom_first_source, src); - if (src) { - src->xrefstr = strdup(xrefstr); - if (! src->xrefstr) MEMORY_ERROR; - } - return src; -} - int write_sources(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/source.h b/gom/source.h index 15af0d3..3e9c987 100644 --- a/gom/source.h +++ b/gom/source.h @@ -29,17 +29,19 @@ void source_subscribe(); void sources_cleanup(); -struct source* make_source_record(const char* xref); -void source_add_event(Gom_ctxt ctxt, struct source_event* evt); +int write_sources(Gedcom_write_hndl hndl); + +DECLARE_MAKEFUNC(source); +DECLARE_ADDFUNC2(source, source_event); +DECLARE_ADDFUNC2(source, source_description); +DECLARE_ADDFUNC2(source, multimedia_link); +DECLARE_ADDFUNC2(source, note_sub); +DECLARE_ADDFUNC2(source, user_ref_number); +DECLARE_ADDFUNC2(source, user_data); +DECLARE_ADDFUNC2_NOLIST(source, change_date); +DECLARE_ADDFUNC2_STR(source, record_id); + void source_add_note_to_data(Gom_ctxt ctxt, struct note_sub* note); void source_add_note_to_repo(Gom_ctxt ctxt, struct note_sub* note); -void source_add_description(Gom_ctxt ctxt, struct source_description* desc); -void source_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link); -void source_add_note(Gom_ctxt ctxt, struct note_sub* note); -void source_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref); -void source_set_record_id(Gom_ctxt ctxt, const char *rin); -void source_set_change_date(Gom_ctxt ctxt, struct change_date* chan); -void source_add_user_data(Gom_ctxt ctxt, struct user_data* data); -int write_sources(Gedcom_write_hndl hndl); #endif /* __SOURCE_H */ diff --git a/gom/source_citation.c b/gom/source_citation.c index 17c2b6d..8e186cc 100644 --- a/gom/source_citation.c +++ b/gom/source_citation.c @@ -59,7 +59,7 @@ Gedcom_ctxt sub_citation_start(_ELT_PARAMS_) switch (ctxt->ctxt_type) { case ELT_SUB_PLAC: - place_add_citation(ctxt, cit); break; + ADDFUNC2(place,source_citation)(ctxt, cit); break; case ELT_SUB_FAM_EVT: case ELT_SUB_FAM_EVT_EVEN: case ELT_SUB_INDIV_ATTR: @@ -68,23 +68,23 @@ Gedcom_ctxt sub_citation_start(_ELT_PARAMS_) case ELT_SUB_INDIV_GEN: case ELT_SUB_INDIV_ADOP: case ELT_SUB_INDIV_EVEN: - event_add_citation(ctxt, cit); break; + ADDFUNC2(event,source_citation)(ctxt, cit); break; case ELT_SUB_NOTE: - note_sub_add_citation(ctxt, cit); break; + ADDFUNC2(note_sub,source_citation)(ctxt, cit); break; case ELT_SUB_LSS_SLGS: case ELT_SUB_LIO_BAPL: case ELT_SUB_LIO_SLGC: - lds_event_add_citation(ctxt, cit); break; + ADDFUNC2(lds_event,source_citation)(ctxt, cit); break; case REC_FAM: - family_add_citation(ctxt, cit); break; + ADDFUNC2(family,source_citation)(ctxt, cit); break; case ELT_SUB_PERS_NAME: - name_add_citation(ctxt, cit); break; + ADDFUNC2(personal_name,source_citation)(ctxt, cit); break; case REC_INDI: - individual_add_citation(ctxt, cit); break; + ADDFUNC2(individual,source_citation)(ctxt, cit); break; case ELT_SUB_ASSO: - association_add_citation(ctxt, cit); break; + ADDFUNC2(association,source_citation)(ctxt, cit); break; case REC_NOTE: - note_add_citation(ctxt, cit); break; + ADDFUNC2(note,source_citation)(ctxt, cit); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -137,13 +137,17 @@ Gedcom_ctxt sub_cit_text_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(source_citation, sub_cit_page_start, page) -STRING_CB(source_citation, sub_cit_even_start, event) -STRING_CB(source_citation, sub_cit_even_role_start, role) -NULL_CB(source_citation, sub_cit_data_start) -DATE_CB(source_citation, sub_cit_data_date_start, date) -STRING_CB(source_citation, sub_cit_quay_start, quality) -STRING_END_CB(text, sub_cit_text_end, text) +DEFINE_STRING_CB(source_citation, sub_cit_page_start, page) +DEFINE_STRING_CB(source_citation, sub_cit_even_start, event) +DEFINE_STRING_CB(source_citation, sub_cit_even_role_start, role) +DEFINE_NULL_CB(source_citation, sub_cit_data_start) +DEFINE_DATE_CB(source_citation, sub_cit_data_date_start, date) +DEFINE_STRING_CB(source_citation, sub_cit_quay_start, quality) +DEFINE_STRING_END_CB(text, sub_cit_text_end, text) + +DEFINE_ADDFUNC2(source_citation, note_sub, note) +DEFINE_ADDFUNC2(source_citation, multimedia_link, mm_link) +DEFINE_ADDFUNC2(source_citation, user_data, extra) void citation_subscribe() { @@ -165,35 +169,14 @@ void citation_subscribe() def_elt_end); } -void citation_add_note(Gom_ctxt ctxt, struct note_sub* note) -{ - struct source_citation *cit = SAFE_CTXT_CAST(source_citation, ctxt); - if (cit) - LINK_CHAIN_ELT(note_sub, cit->note, note); -} - -void citation_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* mm) -{ - struct source_citation *cit = SAFE_CTXT_CAST(source_citation, ctxt); - if (cit) - LINK_CHAIN_ELT(multimedia_link, cit->mm_link, mm); -} - -void citation_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct source_citation *obj = SAFE_CTXT_CAST(source_citation, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void text_cleanup(struct text* t) +void CLEANFUNC(text)(struct text* t) { if (t) { SAFE_FREE(t->text); } } -void citation_cleanup(struct source_citation* cit) +void CLEANFUNC(source_citation)(struct source_citation* cit) { if (cit) { SAFE_FREE(cit->description); @@ -201,11 +184,11 @@ void citation_cleanup(struct source_citation* cit) SAFE_FREE(cit->event); SAFE_FREE(cit->role); SAFE_FREE(cit->date); - DESTROY_CHAIN_ELTS(text, cit->text, text_cleanup); + DESTROY_CHAIN_ELTS(text, cit->text); SAFE_FREE(cit->quality); - DESTROY_CHAIN_ELTS(multimedia_link, cit->mm_link, multimedia_link_cleanup); - DESTROY_CHAIN_ELTS(note_sub, cit->note, note_sub_cleanup); - DESTROY_CHAIN_ELTS(user_data, cit->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(multimedia_link, cit->mm_link); + DESTROY_CHAIN_ELTS(note_sub, cit->note); + DESTROY_CHAIN_ELTS(user_data, cit->extra); } } diff --git a/gom/source_citation.h b/gom/source_citation.h index 530c22e..f08c054 100644 --- a/gom/source_citation.h +++ b/gom/source_citation.h @@ -29,11 +29,12 @@ #include "gom_internal.h" void citation_subscribe(); -void citation_cleanup(struct source_citation* cit); -void citation_add_note(Gom_ctxt ctxt, struct note_sub* note); -void citation_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* mm); -void citation_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_citations(Gedcom_write_hndl hndl, int parent, struct source_citation* cit); +DECLARE_CLEANFUNC(source_citation); +DECLARE_ADDFUNC2(source_citation, note_sub); +DECLARE_ADDFUNC2(source_citation, multimedia_link); +DECLARE_ADDFUNC2(source_citation, user_data); + #endif /* __SOURCE_CITATION_H */ diff --git a/gom/source_description.c b/gom/source_description.c index b03e397..34ca521 100644 --- a/gom/source_description.c +++ b/gom/source_description.c @@ -53,7 +53,7 @@ Gedcom_ctxt sub_sour_caln_start(_ELT_PARAMS_) else { switch (ctxt->ctxt_type) { case ELT_SUB_REPO: - source_add_description(ctxt, desc); break; + ADDFUNC2(source,source_description)(ctxt, desc); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -65,7 +65,9 @@ Gedcom_ctxt sub_sour_caln_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(source_description, sub_sour_caln_medi_start, media) +DEFINE_STRING_CB(source_description, sub_sour_caln_medi_start, media) + +DEFINE_ADDFUNC2(source_description, user_data, extra) void source_description_subscribe() { @@ -75,19 +77,12 @@ void source_description_subscribe() sub_sour_caln_medi_start, def_elt_end); } -void source_description_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct source_description *obj = SAFE_CTXT_CAST(source_description, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void source_description_cleanup(struct source_description* desc) +void CLEANFUNC(source_description)(struct source_description* desc) { if (desc) { SAFE_FREE(desc->call_number); SAFE_FREE(desc->media); - DESTROY_CHAIN_ELTS(user_data, desc->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, desc->extra); } } diff --git a/gom/source_description.h b/gom/source_description.h index 087842a..0a96081 100644 --- a/gom/source_description.h +++ b/gom/source_description.h @@ -29,9 +29,10 @@ #include "gom_internal.h" void source_description_subscribe(); -void source_description_cleanup(struct source_description* desc); -void source_description_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_source_descriptions(Gedcom_write_hndl hndl, int parent, struct source_description *desc); +DECLARE_CLEANFUNC(source_description); +DECLARE_ADDFUNC2(source_description, user_data); + #endif /* __SOURCE_DESCRIPTION_H */ diff --git a/gom/source_event.c b/gom/source_event.c index ce2f873..51a4b60 100644 --- a/gom/source_event.c +++ b/gom/source_event.c @@ -53,7 +53,7 @@ Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_) else { switch (ctxt->ctxt_type) { case ELT_SOUR_DATA: - source_add_event(ctxt, evt); break; + ADDFUNC2(source,source_event)(ctxt, evt); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -65,8 +65,10 @@ Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -DATE_CB(source_event, sub_sour_even_date_start, date_period) -STRING_CB(source_event, sub_sour_even_plac_start, jurisdiction) +DEFINE_DATE_CB(source_event, sub_sour_even_date_start, date_period) +DEFINE_STRING_CB(source_event, sub_sour_even_plac_start, jurisdiction) + +DEFINE_ADDFUNC2(source_event, user_data, extra) void source_event_subscribe() { @@ -78,20 +80,13 @@ void source_event_subscribe() sub_sour_even_plac_start, def_elt_end); } -void source_event_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct source_event *obj = SAFE_CTXT_CAST(source_event, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void source_event_cleanup(struct source_event* evt) +void CLEANFUNC(source_event)(struct source_event* evt) { if (evt) { SAFE_FREE(evt->recorded_events); SAFE_FREE(evt->date_period); SAFE_FREE(evt->jurisdiction); - DESTROY_CHAIN_ELTS(user_data, evt->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, evt->extra); } } diff --git a/gom/source_event.h b/gom/source_event.h index 39e5399..0c2e9e3 100644 --- a/gom/source_event.h +++ b/gom/source_event.h @@ -28,9 +28,10 @@ #include "gom_internal.h" void source_event_subscribe(); -void source_event_cleanup(struct source_event* evt); -void source_event_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_source_events(Gedcom_write_hndl hndl, int parent, struct source_event *evt); +DECLARE_CLEANFUNC(source_event); +DECLARE_ADDFUNC2(source_event, user_data); + #endif /* __SOURCE_EVENT_H */ diff --git a/gom/submission.c b/gom/submission.c index 32b57b8..3ecee29 100644 --- a/gom/submission.c +++ b/gom/submission.c @@ -32,14 +32,16 @@ struct submission* gom_submission = NULL; -REC_CB(submission, subn_start, make_submission_record) -XREF_CB(submission, subn_subm_start, submitter, make_submitter_record) -STRING_CB(submission, subn_famf_start, family_file) -STRING_CB(submission, subn_temp_start, temple_code) -STRING_CB(submission, subn_ance_start, nr_of_ancestor_gens) -STRING_CB(submission, subn_desc_start, nr_of_descendant_gens) -STRING_CB(submission, subn_ordi_start, ordinance_process_flag) -STRING_CB(submission, subn_rin_start, record_id) +DEFINE_REC_CB(submission, subn_start) +DEFINE_XREF_CB(submission, subn_subm_start, submitter, submitter) +DEFINE_STRING_CB(submission, subn_famf_start, family_file) +DEFINE_STRING_CB(submission, subn_temp_start, temple_code) +DEFINE_STRING_CB(submission, subn_ance_start, nr_of_ancestor_gens) +DEFINE_STRING_CB(submission, subn_desc_start, nr_of_descendant_gens) +DEFINE_STRING_CB(submission, subn_ordi_start, ordinance_process_flag) +DEFINE_STRING_CB(submission, subn_rin_start, record_id) + +DEFINE_ADDFUNC2(submission, user_data, extra) void submission_subscribe() { @@ -53,13 +55,6 @@ void submission_subscribe() gedcom_subscribe_to_element(ELT_SUBN_RIN, subn_rin_start, def_elt_end); } -void submission_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct submission *obj = SAFE_CTXT_CAST(submission, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - void submission_cleanup() { if (gom_submission) { @@ -70,7 +65,7 @@ void submission_cleanup() SAFE_FREE(gom_submission->nr_of_descendant_gens); SAFE_FREE(gom_submission->ordinance_process_flag); SAFE_FREE(gom_submission->record_id); - DESTROY_CHAIN_ELTS(user_data, gom_submission->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, gom_submission->extra); SAFE_FREE(gom_submission); } } @@ -80,7 +75,7 @@ struct submission* gom_get_submission() return gom_submission; } -struct submission* make_submission_record(const char* xref) +struct submission* MAKEFUNC(submission)(const char* xref) { if (! gom_submission) { gom_submission = (struct submission*)malloc(sizeof(struct submission)); @@ -96,6 +91,48 @@ struct submission* make_submission_record(const char* xref) return gom_submission; } +void DESTROYFUNC(submission)() +{ + if (gom_submission) { + submission_cleanup(); + free(gom_submission); + gom_submission = NULL; + } +} + +struct submission* ADDFUNC(submission)(const char* xrefstr) +{ + if (!gom_submission) { + struct xref_value* xrv = gedcom_get_by_xref(xrefstr); + if (xrv) + gom_xref_already_in_use(xrefstr); + else { + gom_submission = MAKEFUNC(submission)(xrefstr); + if (gom_submission) { + xrv = gedcom_add_xref(XREF_SUBN, xrefstr, gom_submission); + if (!xrv) { + DESTROYFUNC(submission)(gom_submission); + gom_submission = NULL; + } + } + } + return gom_submission; + } + else + return NULL; +} + +int DELETEFUNC(submission)() +{ + int result = 1; + if (gom_submission) { + result = gedcom_delete_xref(gom_submission->xrefstr); + if (result == 0) + DESTROYFUNC(submission)(); + } + return result; +} + int write_submission(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/submission.h b/gom/submission.h index 12c2bb4..a2c4bec 100644 --- a/gom/submission.h +++ b/gom/submission.h @@ -29,8 +29,9 @@ void submission_subscribe(); void submission_cleanup(); -struct submission* make_submission_record(const char* xref); -void submission_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_submission(Gedcom_write_hndl hndl); +DECLARE_MAKEFUNC(submission); +DECLARE_ADDFUNC2(submission, user_data); + #endif /* __SUBMISSION_H */ diff --git a/gom/submitter.c b/gom/submitter.c index 44ec48f..29de511 100644 --- a/gom/submitter.c +++ b/gom/submitter.c @@ -34,11 +34,22 @@ struct submitter* gom_first_submitter = NULL; -REC_CB(submitter, subm_start, make_submitter_record) -GET_REC_BY_XREF(submitter, XREF_SUBM, gom_get_submitter_by_xref) -STRING_CB(submitter, subm_name_start, name) -STRING_CB(submitter, subm_rfn_start, record_file_nr) -STRING_CB(submitter, subm_rin_start, record_id) +DEFINE_MAKEFUNC(submitter, gom_first_submitter) +DEFINE_DESTROYFUNC(submitter, gom_first_submitter) +DEFINE_ADDFUNC(submitter, XREF_SUBM) +DEFINE_DELETEFUNC(submitter) +DEFINE_GETXREFFUNC(submitter, XREF_SUBM) + +DEFINE_REC_CB(submitter, subm_start) +DEFINE_STRING_CB(submitter, subm_name_start, name) +DEFINE_STRING_CB(submitter, subm_rfn_start, record_file_nr) +DEFINE_STRING_CB(submitter, subm_rin_start, record_id) + +DEFINE_ADDFUNC2(submitter, multimedia_link, mm_link) +DEFINE_ADDFUNC2(submitter, user_data, extra) +DEFINE_ADDFUNC2_NOLIST(submitter, address, address) +DEFINE_ADDFUNC2_NOLIST(submitter, change_date, change_date) +DEFINE_ADDFUNC2_STRN(submitter, phone, 3) Gedcom_ctxt subm_lang_start(_ELT_PARAMS_) { @@ -80,70 +91,29 @@ void submitter_subscribe() gedcom_subscribe_to_element(ELT_SUBM_RIN, subm_rin_start, def_elt_end); } -void submitter_add_address(Gom_ctxt ctxt, struct address* address) -{ - struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt); - if (subm) - subm->address = address; -} - -void submitter_add_phone(Gom_ctxt ctxt, const char *phone) -{ - struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt); - if (subm) { - int i = 0; - while (i<2 && subm->phone[i]) i++; - if (! subm->phone[i]) { - subm->phone[i] = strdup(phone); - if (! subm->phone[i]) MEMORY_ERROR; - } - } -} - -void submitter_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link) -{ - struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt); - if (subm) - LINK_CHAIN_ELT(multimedia_link, subm->mm_link, link); -} - -void submitter_set_change_date(Gom_ctxt ctxt, struct change_date* chan) -{ - struct submitter *subm = SAFE_CTXT_CAST(submitter, ctxt); - if (subm) - subm->change_date = chan; -} - -void submitter_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct submitter *obj = SAFE_CTXT_CAST(submitter, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void submitter_cleanup(struct submitter* rec) +void CLEANFUNC(submitter)(struct submitter* rec) { if (rec) { SAFE_FREE(rec->xrefstr); SAFE_FREE(rec->name); - address_cleanup(rec->address); + CLEANFUNC(address)(rec->address); SAFE_FREE(rec->phone[0]); SAFE_FREE(rec->phone[1]); SAFE_FREE(rec->phone[2]); - DESTROY_CHAIN_ELTS(multimedia_link, rec->mm_link, multimedia_link_cleanup); + DESTROY_CHAIN_ELTS(multimedia_link, rec->mm_link); SAFE_FREE(rec->language[0]); SAFE_FREE(rec->language[1]); SAFE_FREE(rec->language[2]); SAFE_FREE(rec->record_file_nr); SAFE_FREE(rec->record_id); - change_date_cleanup(rec->change_date); - DESTROY_CHAIN_ELTS(user_data, rec->extra, user_data_cleanup); + CLEANFUNC(change_date)(rec->change_date); + DESTROY_CHAIN_ELTS(user_data, rec->extra); } } void submitters_cleanup() { - DESTROY_CHAIN_ELTS(submitter, gom_first_submitter, submitter_cleanup); + DESTROY_CHAIN_ELTS(submitter, gom_first_submitter); } struct submitter* gom_get_first_submitter() @@ -151,17 +121,6 @@ struct submitter* gom_get_first_submitter() return gom_first_submitter; } -struct submitter* make_submitter_record(const char* xrefstr) -{ - struct submitter* subm = NULL; - MAKE_CHAIN_ELT(submitter, gom_first_submitter, subm); - if (subm) { - subm->xrefstr = strdup(xrefstr); - if (!subm->xrefstr) MEMORY_ERROR; - } - return subm; -} - int write_submitters(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/submitter.h b/gom/submitter.h index 7763b8a..bca221b 100644 --- a/gom/submitter.h +++ b/gom/submitter.h @@ -29,12 +29,13 @@ void submitter_subscribe(); void submitters_cleanup(); -struct submitter* make_submitter_record(const char* xref); -void submitter_add_address(Gom_ctxt ctxt, struct address* address); -void submitter_add_phone(Gom_ctxt ctxt, const char *phone); -void submitter_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link); -void submitter_set_change_date(Gom_ctxt ctxt, struct change_date* chan); -void submitter_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_submitters(Gedcom_write_hndl hndl); +DECLARE_MAKEFUNC(submitter); +DECLARE_ADDFUNC2(submitter, multimedia_link); +DECLARE_ADDFUNC2(submitter, user_data); +DECLARE_ADDFUNC2_NOLIST(submitter, address); +DECLARE_ADDFUNC2_NOLIST(submitter, change_date); +DECLARE_ADDFUNC2_STRN(submitter, phone); + #endif /* __SUBMITTER_H */ diff --git a/gom/user_rec.c b/gom/user_rec.c index 4ea975e..90ffb0b 100644 --- a/gom/user_rec.c +++ b/gom/user_rec.c @@ -65,7 +65,7 @@ Gedcom_ctxt user_rec_start(_REC_PARAMS_) xr = GEDCOM_XREF_PTR(xref); if (xr) { if (! xr->object) { - user = make_user_record(xr->string); + user = MAKEFUNC(user_rec)(xr->string); xr->object = (Gedcom_ctxt) user; } ctxt = xr->object; @@ -74,7 +74,7 @@ Gedcom_ctxt user_rec_start(_REC_PARAMS_) } } else { - user = make_user_record(NULL); + user = MAKEFUNC(user_rec)(NULL); ctxt = (Gedcom_ctxt) user; } @@ -101,7 +101,48 @@ Gedcom_ctxt user_rec_start(_REC_PARAMS_) return (Gedcom_ctxt)result; } -GET_REC_BY_XREF(user_rec, XREF_USER, gom_get_user_rec_by_xref) +DEFINE_DESTROYFUNC(user_rec, gom_first_user_rec) +DEFINE_DELETEFUNC(user_rec) +DEFINE_GETXREFFUNC(user_rec, XREF_USER) + +DEFINE_ADDFUNC2(user_rec, user_data, extra) + +/* Specific function, because xrefstr not mandatory here */ +struct user_rec* MAKEFUNC(user_rec)(const char* xrefstr) +{ + struct user_rec* rec = NULL; + MAKE_CHAIN_ELT(user_rec, gom_first_user_rec, rec); + if (rec && xrefstr) { + rec->xrefstr = strdup(xrefstr); + if (! rec->xrefstr) MEMORY_ERROR; + } + return rec; +} + +struct user_rec* ADDFUNC(user_rec)(const char* xrefstr, const char* tag) +{ + struct user_rec *obj = NULL; + struct xref_value* xrv = gedcom_get_by_xref(xrefstr); + if (tag && tag[0] == '_') { + if (xrv) + gom_xref_already_in_use(xrefstr); + else { + obj = MAKEFUNC(user_rec)(xrefstr); + if (obj) { + obj->tag = strdup(tag); + if (! obj->tag) + MEMORY_ERROR; + else + xrv = gedcom_add_xref(XREF_USER, xrefstr, (Gedcom_ctxt)obj); + if (!xrv) { + DESTROYFUNC(user_rec)(obj); + obj = NULL; + } + } + } + } + return obj; +} Gedcom_ctxt user_elt_start(_ELT_PARAMS_) { @@ -142,53 +183,53 @@ Gedcom_ctxt user_elt_start(_ELT_PARAMS_) if (! err) { switch (ctxt->obj_type) { case T_header: - header_add_user_data(ctxt, data); break; + ADDFUNC2(header,user_data)(ctxt, data); break; case T_submission: - submission_add_user_data(ctxt, data); break; + ADDFUNC2(submission,user_data)(ctxt, data); break; case T_submitter: - submitter_add_user_data(ctxt, data); break; + ADDFUNC2(submitter,user_data)(ctxt, data); break; case T_family: - family_add_user_data(ctxt, data); break; + ADDFUNC2(family,user_data)(ctxt, data); break; case T_individual: - individual_add_user_data(ctxt, data); break; + ADDFUNC2(individual,user_data)(ctxt, data); break; case T_multimedia: - multimedia_add_user_data(ctxt, data); break; + ADDFUNC2(multimedia,user_data)(ctxt, data); break; case T_note: - note_add_user_data(ctxt, data); break; + ADDFUNC2(note,user_data)(ctxt, data); break; case T_repository: - repository_add_user_data(ctxt, data); break; + ADDFUNC2(repository,user_data)(ctxt, data); break; case T_source: - source_add_user_data(ctxt, data); break; + ADDFUNC2(source,user_data)(ctxt, data); break; case T_user_rec: - user_rec_add_user_data(ctxt, data); break; + ADDFUNC2(user_rec,user_data)(ctxt, data); break; case T_address: - address_add_user_data(ctxt, data); break; + ADDFUNC2(address,user_data)(ctxt, data); break; case T_event: - event_add_user_data(ctxt, data); break; + ADDFUNC2(event,user_data)(ctxt, data); break; case T_place: - place_add_user_data(ctxt, data); break; + ADDFUNC2(place,user_data)(ctxt, data); break; case T_source_citation: - citation_add_user_data(ctxt, data); break; + ADDFUNC2(source_citation,user_data)(ctxt, data); break; case T_note_sub: - note_sub_add_user_data(ctxt, data); break; + ADDFUNC2(note_sub,user_data)(ctxt, data); break; case T_multimedia_link: - multimedia_link_add_user_data(ctxt, data); break; + ADDFUNC2(multimedia_link,user_data)(ctxt, data); break; case T_lds_event: - lds_event_add_user_data(ctxt, data); break; + ADDFUNC2(lds_event,user_data)(ctxt, data); break; case T_user_ref_number: - user_ref_add_user_data(ctxt, data); break; + ADDFUNC2(user_ref_number,user_data)(ctxt, data); break; case T_change_date: - change_date_add_user_data(ctxt, data); break; + ADDFUNC2(change_date,user_data)(ctxt, data); break; case T_personal_name: - name_add_user_data(ctxt, data); break; + ADDFUNC2(personal_name,user_data)(ctxt, data); break; case T_family_link: - family_link_add_user_data(ctxt, data); break; + ADDFUNC2(family_link,user_data)(ctxt, data); break; case T_association: - association_add_user_data(ctxt, data); break; + ADDFUNC2(association,user_data)(ctxt, data); break; case T_source_event: - source_event_add_user_data(ctxt, data); break; + ADDFUNC2(source_event,user_data)(ctxt, data); break; case T_source_description: - source_description_add_user_data(ctxt, data); break; + ADDFUNC2(source_description,user_data)(ctxt, data); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -206,14 +247,7 @@ void user_rec_subscribe() gedcom_subscribe_to_element(ELT_USER, user_elt_start, def_elt_end); } -void user_rec_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct user_rec *obj = SAFE_CTXT_CAST(user_rec, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void user_data_cleanup(struct user_data* data) +void CLEANFUNC(user_data)(struct user_data* data) { if (data) { SAFE_FREE(data->tag); @@ -221,19 +255,19 @@ void user_data_cleanup(struct user_data* data) } } -void user_rec_cleanup(struct user_rec* rec) +void CLEANFUNC(user_rec)(struct user_rec* rec) { if (rec) { SAFE_FREE(rec->xrefstr); SAFE_FREE(rec->tag); SAFE_FREE(rec->str_value); - DESTROY_CHAIN_ELTS(user_data, rec->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, rec->extra); } } void user_recs_cleanup() { - DESTROY_CHAIN_ELTS(user_rec, gom_first_user_rec, user_rec_cleanup); + DESTROY_CHAIN_ELTS(user_rec, gom_first_user_rec); } struct user_rec* gom_get_first_user_rec() @@ -241,17 +275,6 @@ struct user_rec* gom_get_first_user_rec() return gom_first_user_rec; } -struct user_rec* make_user_record(const char* xrefstr) -{ - struct user_rec* rec = NULL; - MAKE_CHAIN_ELT(user_rec, gom_first_user_rec, rec); - if (rec && xrefstr) { - rec->xrefstr = strdup(xrefstr); - if (! rec->xrefstr) MEMORY_ERROR; - } - return rec; -} - int write_user_recs(Gedcom_write_hndl hndl) { int result = 0; diff --git a/gom/user_rec.h b/gom/user_rec.h index 7e416d8..58f055e 100644 --- a/gom/user_rec.h +++ b/gom/user_rec.h @@ -29,10 +29,12 @@ void user_rec_subscribe(); void user_recs_cleanup(); -struct user_rec* make_user_record(const char* xref); -void user_data_cleanup(struct user_data* data); -void user_rec_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_user_recs(Gedcom_write_hndl hndl); int write_user_data(Gedcom_write_hndl hndl, struct user_data* data); +DECLARE_MAKEFUNC(user_rec); +DECLARE_ADDFUNC2(user_rec, user_data); + +DECLARE_CLEANFUNC(user_data); + #endif /* __USER_REC_H */ diff --git a/gom/user_ref.c b/gom/user_ref.c index 27f32bb..77b2b7d 100644 --- a/gom/user_ref.c +++ b/gom/user_ref.c @@ -58,17 +58,17 @@ Gedcom_ctxt sub_user_ref_start(_ELT_PARAMS_) else { switch (ctxt->ctxt_type) { case REC_FAM: - family_add_user_ref(ctxt, refn); break; + ADDFUNC2(family,user_ref_number)(ctxt, refn); break; case REC_INDI: - individual_add_user_ref(ctxt, refn); break; + ADDFUNC2(individual,user_ref_number)(ctxt, refn); break; case REC_OBJE: - multimedia_add_user_ref(ctxt, refn); break; + ADDFUNC2(multimedia,user_ref_number)(ctxt, refn); break; case REC_NOTE: - note_add_user_ref(ctxt, refn); break; + ADDFUNC2(note,user_ref_number)(ctxt, refn); break; case REC_REPO: - repository_add_user_ref(ctxt, refn); break; + ADDFUNC2(repository,user_ref_number)(ctxt, refn); break; case REC_SOUR: - source_add_user_ref(ctxt, refn); break; + ADDFUNC2(source,user_ref_number)(ctxt, refn); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -81,7 +81,9 @@ Gedcom_ctxt sub_user_ref_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_CB(user_ref_number, sub_user_ref_type_start, type) +DEFINE_STRING_CB(user_ref_number, sub_user_ref_type_start, type) + +DEFINE_ADDFUNC2(user_ref_number, user_data, extra) Gedcom_ctxt sub_user_rin_start(_ELT_PARAMS_) { @@ -95,17 +97,17 @@ Gedcom_ctxt sub_user_rin_start(_ELT_PARAMS_) switch (ctxt->ctxt_type) { case REC_FAM: - family_set_record_id(ctxt, str); break; + ADDFUNC2_STR(family,record_id)(ctxt, str); break; case REC_INDI: - individual_set_record_id(ctxt, str); break; + ADDFUNC2_STR(individual,record_id)(ctxt, str); break; case REC_OBJE: - multimedia_set_record_id(ctxt, str); break; + ADDFUNC2_STR(multimedia,record_id)(ctxt, str); break; case REC_NOTE: - note_set_record_id(ctxt, str); break; + ADDFUNC2_STR(note,record_id)(ctxt, str); break; case REC_REPO: - repository_set_record_id(ctxt, str); break; + ADDFUNC2_STR(repository,record_id)(ctxt, str); break; case REC_SOUR: - source_set_record_id(ctxt, str); break; + ADDFUNC2_STR(source,record_id)(ctxt, str); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -124,19 +126,12 @@ void user_ref_subscribe() def_elt_end); } -void user_ref_add_user_data(Gom_ctxt ctxt, struct user_data* data) -{ - struct user_ref_number *obj = SAFE_CTXT_CAST(user_ref_number, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); -} - -void user_ref_cleanup(struct user_ref_number* refn) +void CLEANFUNC(user_ref_number)(struct user_ref_number* refn) { if (refn) { SAFE_FREE(refn->value); SAFE_FREE(refn->type); - DESTROY_CHAIN_ELTS(user_data, refn->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(user_data, refn->extra); } } diff --git a/gom/user_ref.h b/gom/user_ref.h index 63e7962..191c2f3 100644 --- a/gom/user_ref.h +++ b/gom/user_ref.h @@ -28,9 +28,10 @@ #include "gom_internal.h" void user_ref_subscribe(); -void user_ref_cleanup(struct user_ref_number* refn); -void user_ref_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_user_refs(Gedcom_write_hndl hndl, int parent, struct user_ref_number *refn); +DECLARE_CLEANFUNC(user_ref_number); +DECLARE_ADDFUNC2(user_ref_number, user_data); + #endif /* __USER_REF_H */