X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Findividual.c;h=07e69b1b9af1550d1565446c8c6b9a0b6972095f;hb=505301d49e81bcd0e1827026cd4672b8722ac349;hp=df279d939118bc2f2cb1228446c6918e0142b975;hpb=7ea4ef8cae7b52f2bf66371a5e7b493cbd12900e;p=gedcom-parse.git diff --git a/gom/individual.c b/gom/individual.c index df279d9..07e69b1 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,13 @@ 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; }