- 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);