From: Peter Verthez Date: Sun, 9 Feb 2003 14:19:46 +0000 (+0000) Subject: Improved context handling, to allow elements out of context. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=866835ac8928d7e40919c2ca59799cb37023856f;p=gedcom-parse.git Improved context handling, to allow elements out of context. --- diff --git a/gom/Makefile.am b/gom/Makefile.am index 13156a8..227a9c2 100644 --- a/gom/Makefile.am +++ b/gom/Makefile.am @@ -31,7 +31,8 @@ libgedcom_gom_la_SOURCES = gom.c \ source_event.c \ source_description.c \ user_rec.c \ - gom_modify.c + gom_modify.c \ + gom_internal.c noinst_HEADERS = header.h \ submission.h \ submitter.h \ diff --git a/gom/address.c b/gom/address.c index 553fa12..58d1175 100644 --- a/gom/address.c +++ b/gom/address.c @@ -43,7 +43,8 @@ Gedcom_ctxt sub_addr_start(_ELT_PARAMS_) else { struct address *addr = SUB_MAKEFUNC(address)(); if (addr) { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case ELT_HEAD_SOUR_CORP: ADDFUNC2_NOLIST(header,address)(ctxt, addr); break; case ELT_SUB_FAM_EVT: @@ -60,7 +61,7 @@ Gedcom_ctxt sub_addr_start(_ELT_PARAMS_) case REC_SUBM: ADDFUNC2_NOLIST(submitter,address)(ctxt, addr); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, address, addr); } @@ -76,7 +77,7 @@ Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - result = make_gom_ctxt(elt, ctxt->ctxt_type, ctxt->ctxt_ptr); + result = dup_gom_ctxt(ctxt, elt); } return (Gedcom_ctxt)result; } @@ -104,7 +105,8 @@ Gedcom_ctxt sub_phon_start(_ELT_PARAMS_) NO_CONTEXT; else { char *str = GEDCOM_STRING(parsed_value); - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case ELT_HEAD_SOUR_CORP: header_add_phone(ctxt, str); break; case ELT_SUB_FAM_EVT: @@ -120,9 +122,9 @@ Gedcom_ctxt sub_phon_start(_ELT_PARAMS_) case REC_SUBM: submitter_add_phone(ctxt, str); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } - result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); + result = dup_gom_ctxt(ctxt, elt); } return (Gedcom_ctxt)result; } diff --git a/gom/association.c b/gom/association.c index 9e39209..dc45c06 100644 --- a/gom/association.c +++ b/gom/association.c @@ -42,13 +42,14 @@ Gedcom_ctxt sub_assoc_start(_ELT_PARAMS_) else { struct association *assoc = SUB_MAKEFUNC(association)(); if (assoc) { + int type = ctxt_type(ctxt); assoc->to = GEDCOM_XREF_PTR(parsed_value); - - switch (ctxt->ctxt_type) { + + switch (type) { case REC_INDI: ADDFUNC2(individual,association)(ctxt, assoc); default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, association, assoc); } diff --git a/gom/change_date.c b/gom/change_date.c index 417dbf0..605039d 100644 --- a/gom/change_date.c +++ b/gom/change_date.c @@ -48,7 +48,8 @@ Gedcom_ctxt sub_chan_start(_ELT_PARAMS_) else { struct change_date *chan = SUB_MAKEFUNC(change_date)(); if (chan) { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case REC_FAM: ADDFUNC2_NOLIST(family,change_date)(ctxt, chan); break; case REC_INDI: @@ -64,7 +65,7 @@ Gedcom_ctxt sub_chan_start(_ELT_PARAMS_) case REC_SUBM: ADDFUNC2_NOLIST(submitter,change_date)(ctxt, chan); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, change_date, chan); } diff --git a/gom/event.c b/gom/event.c index 3b45643..b585a68 100644 --- a/gom/event.c +++ b/gom/event.c @@ -65,13 +65,14 @@ Gedcom_ctxt sub_evt_start(_ELT_PARAMS_) } if (! err) { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case REC_FAM: ADDFUNC2(family,event)(ctxt, evt); break; case REC_INDI: ADDFUNC2(individual,event)(ctxt, evt); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, event, evt); } @@ -111,11 +112,12 @@ Gedcom_ctxt sub_attr_start(_ELT_PARAMS_) } if (! err) { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case REC_INDI: ADDFUNC2_TOVAR(individual,event,attribute)(ctxt, evt); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, event, evt); } @@ -160,7 +162,8 @@ Gedcom_ctxt sub_fam_evt_age_start(_ELT_PARAMS_) if (evt) { int err = 0; struct age_value age = GEDCOM_AGE(parsed_value); - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case ELT_SUB_FAM_EVT_HUSB: evt->husband_age = gedcom_new_age_value(&age); if (! evt->husband_age) { @@ -176,7 +179,7 @@ Gedcom_ctxt sub_fam_evt_age_start(_ELT_PARAMS_) } break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } if (! err) result = MAKE_GOM_CTXT(elt, event, evt); diff --git a/gom/family_link.c b/gom/family_link.c index 4ea3fc1..fe3f679 100644 --- a/gom/family_link.c +++ b/gom/family_link.c @@ -41,13 +41,14 @@ Gedcom_ctxt sub_fam_link_start(_ELT_PARAMS_) else { struct family_link *link = SUB_MAKEFUNC(family_link)(); if (link) { + int type = ctxt_type(ctxt); link->family = GEDCOM_XREF_PTR(parsed_value); - switch (ctxt->ctxt_type) { + switch (type) { case REC_INDI: ADDFUNC2(individual,family_link)(ctxt, elt, link); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, family_link, link); } diff --git a/gom/func_template.h b/gom/func_template.h index d5b22c5..dd17527 100644 --- a/gom/func_template.h +++ b/gom/func_template.h @@ -438,7 +438,7 @@ void ADDFUNC2_STRN(STRUCTTYPE,FIELD)(Gom_ctxt ctxt, const char *str) \ else \ obj->FIELD = newvalue; \ } \ - destroy_gom_ctxt(ctxt); \ + def_elt_end(elt, parent, self, parsed_value); \ } \ } @@ -458,7 +458,7 @@ void ADDFUNC2_STRN(STRUCTTYPE,FIELD)(Gom_ctxt ctxt, const char *str) \ else \ obj->FIELD = newvalue; \ } \ - destroy_gom_ctxt(ctxt); \ + def_rec_end(rec, self, parsed_value); \ } \ } diff --git a/gom/gom.c b/gom/gom.c index 3e60415..6e27ab7 100644 --- a/gom/gom.c +++ b/gom/gom.c @@ -174,6 +174,26 @@ void gom_default_callback (Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, level, tag, raw_value); } +void gom_mem_error(const char *filename, int line) +{ + gedcom_error(_("Could not allocate memory at %s, %d"), filename, line); +} + +void gom_xref_already_in_use(const char *xrefstr) +{ + gedcom_error(_("Cross-reference key '%s' is already in use"), xrefstr); +} + +void gom_move_error(const char* type) +{ + gedcom_warning(_("Could not move struct of type %s"), type); +} + +void gom_find_error(const char* type) +{ + gedcom_warning(_("Could not find struct of type %s in chain"), type); +} + void set_xref_type(struct xref_value* xr, const char *str) { if (!strcasecmp(str, "FAM")) diff --git a/gom/gom_internal.c b/gom/gom_internal.c index 359ec87..48e9d62 100644 --- a/gom/gom_internal.c +++ b/gom/gom_internal.c @@ -37,6 +37,24 @@ const char* ctxt_names[] = "association", "source_event", "source_description" }; +/* Assumptions for context: + - In case of error, NULL is passed as context + - If not NULL, the ctxt_ptr of the context is not NULL also + - UNEXPECTED_CONTEXT is not treated as an error, but as a warning + + The context chain keeps contexts until the end of the record, so that + elements out of context can be handled. +*/ + +struct Gom_ctxt_struct { + int ctxt_type; + OBJ_TYPE obj_type; + void* ctxt_ptr; + struct Gom_ctxt_struct* next; +}; + +struct Gom_ctxt_struct* ctxt_chain = NULL; + Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr) { Gom_ctxt ctxt = (Gom_ctxt)malloc(sizeof(struct Gom_ctxt_struct)); @@ -46,10 +64,35 @@ Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr) ctxt->ctxt_type = ctxt_type; ctxt->obj_type = obj_type; ctxt->ctxt_ptr = ctxt_ptr; + ctxt->next = ctxt_chain; + ctxt_chain = ctxt; } return ctxt; } +Gom_ctxt dup_gom_ctxt(Gom_ctxt ctxt, int ctxt_type) +{ + return make_gom_ctxt(ctxt_type, ctxt->obj_type, ctxt->ctxt_ptr); +} + +int ctxt_type(Gom_ctxt ctxt) +{ + return ctxt->ctxt_type; +} + +OBJ_TYPE ctxt_obj_type(Gom_ctxt ctxt) +{ + return ctxt->obj_type; +} + +void* safe_ctxt_cast(Gom_ctxt ctxt, OBJ_TYPE type, const char* file, int line) +{ + if (ctxt->obj_type != type) { + gom_cast_error(file, line, type, ctxt->obj_type); + } + return ctxt->ctxt_ptr; +} + void NULL_DESTROY(void* anything UNUSED) { } @@ -74,16 +117,6 @@ void gom_cast_error(const char* file, int line, abort(); } -void gom_mem_error(const char *filename, int line) -{ - gedcom_error(_("Could not allocate memory at %s, %d"), filename, line); -} - -void gom_xref_already_in_use(const char *xrefstr) -{ - gedcom_error(_("Cross-reference key '%s' is already in use"), xrefstr); -} - void gom_unexpected_context(const char* file, int line, OBJ_TYPE found) { const char* found_name = ""; @@ -99,27 +132,18 @@ void gom_no_context(const char* file, int line) file, line); } -void gom_move_error(const char* type) -{ - gedcom_warning(_("Could not move struct of type %s"), type); -} - -void gom_find_error(const char* type) -{ - gedcom_warning(_("Could not find struct of type %s in chain"), type); -} - -void def_rec_end(Gedcom_rec rec UNUSED, Gedcom_ctxt self, +void def_rec_end(Gedcom_rec rec UNUSED, Gedcom_ctxt self UNUSED, Gedcom_val parsed_value UNUSED) { - Gom_ctxt ctxt = (Gom_ctxt)self; - destroy_gom_ctxt(ctxt); + Gom_ctxt ctxt; + while (ctxt_chain) { + ctxt = ctxt_chain; + ctxt_chain = ctxt->next; + destroy_gom_ctxt(ctxt); + } } -/* TODO: do this in a way so that elements out of context can be handled */ void def_elt_end(Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, - Gedcom_ctxt self, Gedcom_val parsed_value UNUSED) + Gedcom_ctxt self UNUSED, Gedcom_val parsed_value UNUSED) { - Gom_ctxt ctxt = (Gom_ctxt)self; - destroy_gom_ctxt(ctxt); } diff --git a/gom/gom_internal.h b/gom/gom_internal.h index 9f1e6ea..3c604a2 100644 --- a/gom/gom_internal.h +++ b/gom/gom_internal.h @@ -57,22 +57,15 @@ typedef enum { T_LAST } OBJ_TYPE; -/* Assumptions for context: - - In case of error, NULL is passed as context - - If not NULL, the ctxt_ptr of the context is not NULL also - - UNEXPECTED_CONTEXT is not treated as an error, but as a warning -*/ - -struct Gom_ctxt_struct { - int ctxt_type; - OBJ_TYPE obj_type; - void* ctxt_ptr; -}; - +struct Gom_ctxt_struct; typedef struct Gom_ctxt_struct *Gom_ctxt; Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr); -void destroy_gom_ctxt(Gom_ctxt ctxt); +Gom_ctxt dup_gom_ctxt(Gom_ctxt ctxt, int ctxt_type); +void* safe_ctxt_cast(Gom_ctxt ctxt, OBJ_TYPE type, const char* file, int line); +int ctxt_type(Gom_ctxt ctxt); +OBJ_TYPE ctxt_obj_type(Gom_ctxt ctxt); + void gom_cast_error(const char* file, int line, OBJ_TYPE expected, OBJ_TYPE found); void gom_no_context(const char* file, int line); @@ -90,10 +83,7 @@ int gom_write_xref_list(Gedcom_write_hndl hndl, make_gom_ctxt(CTXT_TYPE, T_ ## STRUCTTYPE, CTXT_PTR) #define SAFE_CTXT_CAST(STRUCTTYPE, VAL) \ - (((VAL)->obj_type == T_ ## STRUCTTYPE) ? \ - (VAL)->ctxt_ptr : \ - (gom_cast_error(__FILE__, __LINE__, T_ ## STRUCTTYPE, (VAL)->obj_type), \ - (VAL)->ctxt_ptr)) + safe_ctxt_cast(VAL, T_ ## STRUCTTYPE, __FILE__, __LINE__) #define SAFE_FREE(PTR) \ if (PTR) { \ diff --git a/gom/lds_event.c b/gom/lds_event.c index 799e23d..5e287e4 100644 --- a/gom/lds_event.c +++ b/gom/lds_event.c @@ -50,13 +50,14 @@ Gedcom_ctxt sub_lds_event_start(_ELT_PARAMS_) free(lds_evt); } else { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case REC_FAM: ADDFUNC2(family,lds_event)(ctxt, lds_evt); break; case REC_INDI: ADDFUNC2(individual,lds_event)(ctxt, lds_evt); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, lds_event, lds_evt); } diff --git a/gom/multimedia.c b/gom/multimedia.c index 9dbf90b..b7514e4 100644 --- a/gom/multimedia.c +++ b/gom/multimedia.c @@ -61,7 +61,7 @@ Gedcom_ctxt obje_blob_cont_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else - result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); + result = dup_gom_ctxt(ctxt, elt); return (Gedcom_ctxt)result; } diff --git a/gom/multimedia_link.c b/gom/multimedia_link.c index fda4feb..b2ee559 100644 --- a/gom/multimedia_link.c +++ b/gom/multimedia_link.c @@ -46,10 +46,11 @@ Gedcom_ctxt sub_obje_start(_ELT_PARAMS_) else { struct multimedia_link *mm = SUB_MAKEFUNC(multimedia_link)(); if (mm) { + int type = ctxt_type(ctxt); if (GEDCOM_IS_XREF_PTR(parsed_value)) mm->reference = GEDCOM_XREF_PTR(parsed_value); - switch (ctxt->ctxt_type) { + switch (type) { case ELT_SUB_FAM_EVT: case ELT_SUB_FAM_EVT_EVEN: case ELT_SUB_INDIV_ATTR: @@ -70,7 +71,7 @@ Gedcom_ctxt sub_obje_start(_ELT_PARAMS_) case REC_SUBM: ADDFUNC2(submitter,multimedia_link)(ctxt, mm); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, multimedia_link, mm); } diff --git a/gom/note.c b/gom/note.c index 6d0dc8a..2f1cba2 100644 --- a/gom/note.c +++ b/gom/note.c @@ -73,7 +73,7 @@ Gedcom_ctxt sub_cont_conc_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else - result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); + result = dup_gom_ctxt(ctxt, elt); return (Gedcom_ctxt)result; } diff --git a/gom/note_sub.c b/gom/note_sub.c index 7facc41..f8dedef 100644 --- a/gom/note_sub.c +++ b/gom/note_sub.c @@ -54,10 +54,11 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) else { struct note_sub *note = SUB_MAKEFUNC(note_sub)(); if (note) { + int type = ctxt_type(ctxt); if (GEDCOM_IS_XREF_PTR(parsed_value)) note->reference = GEDCOM_XREF_PTR(parsed_value); - switch (ctxt->ctxt_type) { + switch (type) { case ELT_SUB_PLAC: ADDFUNC2(place,note_sub)(ctxt, note); break; case ELT_SUB_FAM_EVT: @@ -101,7 +102,7 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) case REC_SOUR: ADDFUNC2(source,note_sub)(ctxt, note); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, note_sub, note); } diff --git a/gom/personal_name.c b/gom/personal_name.c index 686422f..02de333 100644 --- a/gom/personal_name.c +++ b/gom/personal_name.c @@ -47,11 +47,12 @@ Gedcom_ctxt sub_name_start(_ELT_PARAMS_) free(name); } else { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case REC_INDI: ADDFUNC2(individual,personal_name)(ctxt, name); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, personal_name, name); } diff --git a/gom/place.c b/gom/place.c index 38ff377..779ea87 100644 --- a/gom/place.c +++ b/gom/place.c @@ -50,7 +50,8 @@ Gedcom_ctxt sub_place_start(_ELT_PARAMS_) free(place); } else { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case ELT_SUB_FAM_EVT: case ELT_SUB_FAM_EVT_EVEN: case ELT_SUB_INDIV_ATTR: @@ -61,7 +62,7 @@ Gedcom_ctxt sub_place_start(_ELT_PARAMS_) case ELT_SUB_INDIV_EVEN: ADDFUNC2_NOLIST(event,place)(ctxt, place); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, place, place); } diff --git a/gom/source_citation.c b/gom/source_citation.c index 45dc842..406972a 100644 --- a/gom/source_citation.c +++ b/gom/source_citation.c @@ -49,10 +49,11 @@ Gedcom_ctxt sub_citation_start(_ELT_PARAMS_) else { struct source_citation *cit = SUB_MAKEFUNC(source_citation)(); if (cit) { + int type = ctxt_type(ctxt); if (GEDCOM_IS_XREF_PTR(parsed_value)) cit->reference = GEDCOM_XREF_PTR(parsed_value); - switch (ctxt->ctxt_type) { + switch (type) { case ELT_SUB_PLAC: ADDFUNC2(place,source_citation)(ctxt, cit); break; case ELT_SUB_FAM_EVT: @@ -81,7 +82,7 @@ Gedcom_ctxt sub_citation_start(_ELT_PARAMS_) case REC_NOTE: ADDFUNC2(note,source_citation)(ctxt, cit); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, source_citation, cit); } diff --git a/gom/source_description.c b/gom/source_description.c index 65e98ac..02d093f 100644 --- a/gom/source_description.c +++ b/gom/source_description.c @@ -47,11 +47,12 @@ Gedcom_ctxt sub_sour_caln_start(_ELT_PARAMS_) free(desc); } else { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case ELT_SUB_REPO: ADDFUNC2(source,source_description)(ctxt, desc); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, source_description, desc); } diff --git a/gom/source_event.c b/gom/source_event.c index 319dbb7..a7756c3 100644 --- a/gom/source_event.c +++ b/gom/source_event.c @@ -47,11 +47,12 @@ Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_) free(evt); } else { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case ELT_SOUR_DATA: ADDFUNC2(source,source_event)(ctxt, evt); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, source_event, evt); } diff --git a/gom/user_rec.c b/gom/user_rec.c index ba1dc5e..9531cf1 100644 --- a/gom/user_rec.c +++ b/gom/user_rec.c @@ -181,7 +181,7 @@ Gedcom_ctxt user_elt_start(_ELT_PARAMS_) data->xref_value = GEDCOM_XREF_PTR(parsed_value); if (! err) { - switch (ctxt->obj_type) { + switch (ctxt_obj_type(ctxt)) { case T_header: ADDFUNC2(header,user_data)(ctxt, data); break; case T_submission: @@ -231,9 +231,9 @@ Gedcom_ctxt user_elt_start(_ELT_PARAMS_) case T_source_description: ADDFUNC2(source_description,user_data)(ctxt, data); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(ctxt_type(ctxt)); } - result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); + result = dup_gom_ctxt(ctxt, elt); } } } diff --git a/gom/user_ref.c b/gom/user_ref.c index 1dac775..c43874f 100644 --- a/gom/user_ref.c +++ b/gom/user_ref.c @@ -51,7 +51,8 @@ Gedcom_ctxt sub_user_ref_start(_ELT_PARAMS_) free(refn); } else { - switch (ctxt->ctxt_type) { + int type = ctxt_type(ctxt); + switch (type) { case REC_FAM: ADDFUNC2(family,user_ref_number)(ctxt, refn); break; case REC_INDI: @@ -65,7 +66,7 @@ Gedcom_ctxt sub_user_ref_start(_ELT_PARAMS_) case REC_SOUR: ADDFUNC2(source,user_ref_number)(ctxt, refn); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } result = MAKE_GOM_CTXT(elt, user_ref_number, refn); @@ -95,8 +96,9 @@ Gedcom_ctxt sub_user_rin_start(_ELT_PARAMS_) NO_CONTEXT; else { char *str = GEDCOM_STRING(parsed_value); + int type = ctxt_type(ctxt); - switch (ctxt->ctxt_type) { + switch (type) { case REC_FAM: ADDFUNC2_STR(family,record_id)(ctxt, str); break; case REC_INDI: @@ -110,9 +112,9 @@ Gedcom_ctxt sub_user_rin_start(_ELT_PARAMS_) case REC_SOUR: ADDFUNC2_STR(source,record_id)(ctxt, str); break; default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); + UNEXPECTED_CONTEXT(type); } - result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); + result = dup_gom_ctxt(ctxt, elt); } return (Gedcom_ctxt)result; }