X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Findividual.c;h=958cce8340f5dc797af86eb0d8140ec21ee5dbf9;hb=1568cb8ab16ecc1984d0d00b8ae8189c32508b08;hp=df279d939118bc2f2cb1228446c6918e0142b975;hpb=7ea4ef8cae7b52f2bf66371a5e7b493cbd12900e;p=gedcom-parse.git diff --git a/gom/individual.c b/gom/individual.c index df279d9..958cce8 100644 --- a/gom/individual.c +++ b/gom/individual.c @@ -71,117 +71,136 @@ void individual_subscribe() void individual_add_event(Gom_ctxt ctxt, struct event* evt) { struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - LINK_CHAIN_ELT(event, indiv->event, evt) + 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); - LINK_CHAIN_ELT(event, indiv->attribute, evt) + 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); - LINK_CHAIN_ELT(personal_name, indiv->name, name) + 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); - LINK_CHAIN_ELT(lds_event, indiv->lds_individual_ordinance, evt) + 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) { struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - switch (ctxt_type) { - case ELT_SUB_FAMC: - LINK_CHAIN_ELT(family_link, indiv->child_to_family, link) - break; - case ELT_SUB_FAMS: - LINK_CHAIN_ELT(family_link, indiv->spouse_to_family, link) - break; - default: - UNEXPECTED_CONTEXT(ctxt_type); + if (indiv) { + switch (ctxt_type) { + case ELT_SUB_FAMC: + LINK_CHAIN_ELT(family_link, indiv->child_to_family, link); + break; + case ELT_SUB_FAMS: + LINK_CHAIN_ELT(family_link, indiv->spouse_to_family, link); + break; + default: + UNEXPECTED_CONTEXT(ctxt_type); + } } } void individual_add_association(Gom_ctxt ctxt, struct association* assoc) { struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - LINK_CHAIN_ELT(association, indiv->association, assoc) + 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); - LINK_CHAIN_ELT(source_citation, indiv->citation, cit) + 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); - LINK_CHAIN_ELT(multimedia_link, indiv->mm_link, link) + 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); - LINK_CHAIN_ELT(note_sub, indiv->note, note) + 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); - LINK_CHAIN_ELT(user_ref_number, indiv->ref, ref) + if (indiv) + LINK_CHAIN_ELT(user_ref_number, indiv->ref, ref); } -void individual_set_record_id(Gom_ctxt ctxt, char *rin) +void individual_set_record_id(Gom_ctxt ctxt, const char *rin) { struct individual *indiv = SAFE_CTXT_CAST(individual, ctxt); - indiv->record_id = strdup(rin); + 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); - indiv->change_date = chan; + 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); - LINK_CHAIN_ELT(user_data, obj->extra, data) + if (obj) + LINK_CHAIN_ELT(user_data, obj->extra, data); } void individual_cleanup(struct individual* indiv) { - SAFE_FREE(indiv->xrefstr); - SAFE_FREE(indiv->restriction_notice); - DESTROY_CHAIN_ELTS(personal_name, indiv->name, name_cleanup) - 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) - SAFE_FREE(indiv->record_file_nr); - SAFE_FREE(indiv->ancestral_file_nr); - DESTROY_CHAIN_ELTS(user_ref_number, indiv->ref, user_ref_cleanup) - SAFE_FREE(indiv->record_id); - change_date_cleanup(indiv->change_date); - DESTROY_CHAIN_ELTS(user_data, indiv->extra, user_data_cleanup) + if (indiv) { + SAFE_FREE(indiv->xrefstr); + SAFE_FREE(indiv->restriction_notice); + DESTROY_CHAIN_ELTS(personal_name, indiv->name, name_cleanup); + 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); + SAFE_FREE(indiv->record_file_nr); + SAFE_FREE(indiv->ancestral_file_nr); + DESTROY_CHAIN_ELTS(user_ref_number, indiv->ref, user_ref_cleanup); + SAFE_FREE(indiv->record_id); + change_date_cleanup(indiv->change_date); + DESTROY_CHAIN_ELTS(user_data, indiv->extra, user_data_cleanup); + } } void individuals_cleanup() @@ -194,10 +213,80 @@ struct individual* gom_get_first_individual() return gom_first_individual; } -struct individual* make_individual_record(char* xrefstr) +struct individual* make_individual_record(const char* xrefstr) { - struct individual* indiv; + struct individual* indiv = NULL; MAKE_CHAIN_ELT(individual, gom_first_individual, indiv); - indiv->xrefstr = strdup(xrefstr); + if (indiv) { + indiv->xrefstr = strdup(xrefstr); + if (! indiv->xrefstr) MEMORY_ERROR; + } return indiv; } + +int write_individuals(Gedcom_write_hndl hndl) +{ + int result = 0; + struct individual* obj; + + for (obj = gom_first_individual; obj; obj = obj->next) { + result |= gedcom_write_record_str(hndl, REC_INDI, 0, + obj->xrefstr, NULL); + if (obj->restriction_notice) + result |= gedcom_write_element_str(hndl, ELT_INDI_RESN, 0, + REC_INDI, obj->restriction_notice); + if (obj->name) + result |= write_names(hndl, REC_INDI, obj->name); + if (obj->sex) + result |= gedcom_write_element_str(hndl, ELT_INDI_SEX, 0, + REC_INDI, obj->sex); + if (obj->event) + result |= write_events(hndl, REC_INDI, EVT_TYPE_INDIV_EVT, obj->event); + if (obj->attribute) + result |= write_events(hndl, REC_INDI, EVT_TYPE_INDIV_ATTR, + obj->attribute); + if (obj->lds_individual_ordinance) + result |= write_lds_events(hndl, REC_INDI, + obj->lds_individual_ordinance); + if (obj->child_to_family) + result |= write_family_links(hndl, REC_INDI, LINK_TYPE_CHILD, + obj->child_to_family); + if (obj->spouse_to_family) + result |= write_family_links(hndl, REC_INDI, LINK_TYPE_SPOUSE, + obj->spouse_to_family); + result |= gom_write_xref_list(hndl, ELT_INDI_SUBM, 0, + REC_INDI, obj->submitters); + if (obj->association) + result |= write_associations(hndl, REC_INDI, obj->association); + result |= gom_write_xref_list(hndl, ELT_INDI_ALIA, 0, + REC_INDI, obj->alias); + result |= gom_write_xref_list(hndl, ELT_INDI_ANCI, 0, + REC_INDI, obj->ancestor_interest); + result |= gom_write_xref_list(hndl, ELT_INDI_DESI, 0, + REC_INDI, obj->descendant_interest); + if (obj->citation) + result |= write_citations(hndl, REC_INDI, obj->citation); + if (obj->mm_link) + result |= write_multimedia_links(hndl, REC_INDI, obj->mm_link); + if (obj->note) + result |= write_note_subs(hndl, REC_INDI, obj->note); + if (obj->record_file_nr) + result |= gedcom_write_element_str(hndl, ELT_INDI_RFN, 0, + REC_INDI, obj->record_file_nr); + if (obj->ancestral_file_nr) + result |= gedcom_write_element_str(hndl, ELT_INDI_AFN, 0, + REC_INDI, obj->ancestral_file_nr); + if (obj->ref) + result |= write_user_refs(hndl, REC_INDI, obj->ref); + if (obj->record_id) + result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_RIN, 0, + REC_INDI, obj->record_id); + if (obj->change_date) + result |= write_change_date(hndl, REC_INDI, obj->change_date); + if (obj->extra) + result |= write_user_data(hndl, obj->extra); + } + + return result; +} +