X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Ffamily_link.c;h=39a2140c865b452b3f213231b947ad28a3f6c3fb;hb=72689522e287ca3b2231e7d8881f0fe5bea48f15;hp=4c5fa9b0f357d666610c8970ba8b5cd9edc45830;hpb=bdf47fdee469d5a1d7ddfd06a0e4b26f3b40b0f4;p=gedcom-parse.git diff --git a/gom/family_link.c b/gom/family_link.c index 4c5fa9b..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,32 +100,58 @@ void family_link_subscribe() def_elt_end); } -void family_link_add_note(Gom_ctxt ctxt, struct note_sub* note) +void CLEANFUNC(pedigree)(struct pedigree* ped) { - struct family_link *link = SAFE_CTXT_CAST(family_link, ctxt); - if (link) - LINK_CHAIN_ELT(note_sub, link->note, note); + if (ped) { + SAFE_FREE(ped->pedigree); + } } -void family_link_add_user_data(Gom_ctxt ctxt, struct user_data* data) +void CLEANFUNC(family_link)(struct family_link *link) { - struct family_link *obj = SAFE_CTXT_CAST(family_link, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data); + if (link) { + DESTROY_CHAIN_ELTS(pedigree, link->pedigree); + DESTROY_CHAIN_ELTS(note_sub, link->note); + DESTROY_CHAIN_ELTS(user_data, link->extra); + } } -void pedigree_cleanup(struct pedigree* ped) +int write_pedigrees(Gedcom_write_hndl hndl, int parent, struct pedigree* ped) { - if (ped) { - SAFE_FREE(ped->pedigree); + int result = 0; + struct pedigree* obj; + + if (!ped) return 1; + + for (obj = ped; obj; obj = obj->next) { + result |= gedcom_write_element_str(hndl, ELT_SUB_FAMC_PEDI, 0, parent, + obj->pedigree); + if (obj->extra) + result |= write_user_data(hndl, obj->extra); } + + return result; } -void family_link_cleanup(struct family_link *link) +int write_family_links(Gedcom_write_hndl hndl, int parent, LinkType type, + 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); + int result = 0; + struct family_link* obj; + int elt = (type == LINK_TYPE_CHILD ? ELT_SUB_FAMC : ELT_SUB_FAMS); + + if (!link) return 1; + + for (obj = link; obj; obj = obj->next) { + result |= gedcom_write_element_xref(hndl, elt, 0, parent, + obj->family); + if (obj->pedigree) + result |= write_pedigrees(hndl, elt, obj->pedigree); + if (obj->note) + result |= write_note_subs(hndl, elt, obj->note); + if (obj->extra) + result |= write_user_data(hndl, obj->extra); } + + return result; }