X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fplace.c;h=8ceb152b94c6fcfc89aed9cee9a7710feba8f1d5;hb=f64619dc88514d184a094e41d34012eb136367a2;hp=a77ff91a88a48cdc9f6f63e6d91b0b9d654f0e10;hpb=7ea4ef8cae7b52f2bf66371a5e7b493cbd12900e;p=gedcom-parse.git diff --git a/gom/place.c b/gom/place.c index a77ff91..8ceb152 100644 --- a/gom/place.c +++ b/gom/place.c @@ -36,50 +36,49 @@ Gedcom_ctxt sub_place_start(_ELT_PARAMS_) { Gom_ctxt ctxt = (Gom_ctxt)parent; - struct place *place = NULL; + Gom_ctxt result = NULL; - if (ctxt) { - place = (struct place *)malloc(sizeof(struct place)); - memset (place, 0, sizeof(struct place)); - place->value = strdup(GEDCOM_STRING(parsed_value)); - - switch (ctxt->ctxt_type) { - case ELT_SUB_FAM_EVT: - case ELT_SUB_FAM_EVT_EVEN: - case ELT_SUB_INDIV_ATTR: - case ELT_SUB_INDIV_RESI: - case ELT_SUB_INDIV_BIRT: - case ELT_SUB_INDIV_GEN: - case ELT_SUB_INDIV_ADOP: - case ELT_SUB_INDIV_EVEN: - event_add_place(ctxt, place); break; - default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + if (! ctxt) + NO_CONTEXT; + else { + struct place *place = (struct place *)malloc(sizeof(struct place)); + if (! place) + MEMORY_ERROR; + else { + memset (place, 0, sizeof(struct place)); + place->value = strdup(GEDCOM_STRING(parsed_value)); + + if (!place->value) { + MEMORY_ERROR; + free(place); + } + else { + switch (ctxt->ctxt_type) { + case ELT_SUB_FAM_EVT: + case ELT_SUB_FAM_EVT_EVEN: + case ELT_SUB_INDIV_ATTR: + case ELT_SUB_INDIV_RESI: + case ELT_SUB_INDIV_BIRT: + case ELT_SUB_INDIV_GEN: + case ELT_SUB_INDIV_ADOP: + case ELT_SUB_INDIV_EVEN: + ADDFUNC2_NOLIST(event,place)(ctxt, place); break; + default: + UNEXPECTED_CONTEXT(ctxt->ctxt_type); + } + result = MAKE_GOM_CTXT(elt, place, place); + } } } - return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, place, place); + 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); - 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); - 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); - 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() { @@ -88,14 +87,35 @@ 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); } + +int write_place(Gedcom_write_hndl hndl, int parent, struct place* place) +{ + int result = 0; + + if (!place) return 1; + + result |= gedcom_write_element_str(hndl, ELT_SUB_PLAC, 0, + parent, place->value); + if (place->place_hierarchy) + result |= gedcom_write_element_str(hndl, ELT_SUB_PLAC_FORM, 0, + ELT_SUB_PLAC, place->place_hierarchy); + if (place->citation) + result |= write_citations(hndl, ELT_SUB_PLAC, place->citation); + if (place->note) + result |= write_note_subs(hndl, ELT_SUB_PLAC, place->note); + if (place->extra) + result |= write_user_data(hndl, place->extra); + + return result; +}