X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fnote_sub.c;h=e523b32ba120dc0cece1800f11f24642d0922180;hb=f197c791489f1537db4aebc7ce29b6d4f9adc2b3;hp=63ef644150a4348dacc569cfbb20d502da1a11bb;hpb=082066d0c776403b70c366f9a7d1333c7a9fac15;p=gedcom-parse.git diff --git a/gom/note_sub.c b/gom/note_sub.c index 63ef644..e523b32 100644 --- a/gom/note_sub.c +++ b/gom/note_sub.c @@ -52,17 +52,14 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct note_sub *note = (struct note_sub *)malloc(sizeof(struct note_sub)); - if (! note) - MEMORY_ERROR; - else { - memset (note, 0, sizeof(struct note_sub)); + struct note_sub *note = SUB_MAKEFUNC(note_sub)(); + if (note) { if (GEDCOM_IS_XREF_PTR(parsed_value)) note->reference = GEDCOM_XREF_PTR(parsed_value); switch (ctxt->ctxt_type) { case ELT_SUB_PLAC: - place_add_note(ctxt, note); break; + ADDFUNC2(place,note_sub)(ctxt, note); break; case ELT_SUB_FAM_EVT: case ELT_SUB_FAM_EVT_EVEN: case ELT_SUB_INDIV_ATTR: @@ -71,38 +68,38 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) case ELT_SUB_INDIV_GEN: case ELT_SUB_INDIV_ADOP: case ELT_SUB_INDIV_EVEN: - event_add_note(ctxt, note); break; + ADDFUNC2(event,note_sub)(ctxt, note); break; case ELT_SUB_SOUR: - citation_add_note(ctxt, note); break; + ADDFUNC2(source_citation,note_sub)(ctxt, note); break; case ELT_SUB_MULTIM_OBJE: - multimedia_link_add_note(ctxt, note); break; + ADDFUNC2(multimedia_link,note_sub)(ctxt, note); break; case ELT_SUB_LSS_SLGS: case ELT_SUB_LIO_BAPL: case ELT_SUB_LIO_SLGC: - lds_event_add_note(ctxt, note); break; + ADDFUNC2(lds_event,note_sub)(ctxt, note); break; case REC_FAM: - family_add_note(ctxt, note); break; + ADDFUNC2(family,note_sub)(ctxt, note); break; case ELT_SUB_CHAN: - change_date_add_note(ctxt, note); break; + ADDFUNC2(change_date,note_sub)(ctxt, note); break; case ELT_SUB_PERS_NAME: - name_add_note(ctxt, note); break; + ADDFUNC2(personal_name,note_sub)(ctxt, note); break; case ELT_SUB_FAMC: case ELT_SUB_FAMS: - family_link_add_note(ctxt, note); break; + ADDFUNC2(family_link,note_sub)(ctxt, note); break; case ELT_SUB_ASSO: - association_add_note(ctxt, note); break; + ADDFUNC2(association,note_sub)(ctxt, note); break; case REC_INDI: - individual_add_note(ctxt, note); break; + ADDFUNC2(individual,note_sub)(ctxt, note); break; case REC_OBJE: - multimedia_add_note(ctxt, note); break; + ADDFUNC2(multimedia,note_sub)(ctxt, note); break; case REC_REPO: - repository_add_note(ctxt, note); break; + ADDFUNC2(repository,note_sub)(ctxt, note); break; case ELT_SOUR_DATA: source_add_note_to_data(ctxt, note); break; case ELT_SUB_REPO: source_add_note_to_repo(ctxt, note); break; case REC_SOUR: - source_add_note(ctxt, note); break; + ADDFUNC2(source,note_sub)(ctxt, note); break; default: UNEXPECTED_CONTEXT(ctxt->ctxt_type); } @@ -113,33 +110,55 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -STRING_END_CB(note_sub, sub_note_end, text) - -void note_sub_subscribe() +void sub_note_end(_ELT_END_PARAMS_) { - gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end); + if (GEDCOM_IS_STRING(parsed_value)) { + Gom_ctxt ctxt = (Gom_ctxt)self; + if (! ctxt) + NO_CONTEXT; + else { + struct note_sub *obj = SAFE_CTXT_CAST(note_sub, ctxt); + if (obj) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + obj->text = newvalue; + } + destroy_gom_ctxt(ctxt); + } + } } -void note_sub_add_citation(Gom_ctxt ctxt, struct source_citation* cit) +DEFINE_SUB_MAKEFUNC(note_sub) + +DEFINE_ADDFUNC2(note_sub, source_citation, citation) +DEFINE_ADDFUNC2(note_sub, user_data, extra) + +void note_sub_subscribe() { - struct note_sub *note = SAFE_CTXT_CAST(note_sub, ctxt); - if (note) - LINK_CHAIN_ELT(source_citation, note->citation, cit); + gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end); } -void note_sub_add_user_data(Gom_ctxt ctxt, struct user_data* data) +void UNREFALLFUNC(note_sub)(struct note_sub* obj) { - struct note_sub *obj = SAFE_CTXT_CAST(note_sub, ctxt); - if (obj) - LINK_CHAIN_ELT(user_data, obj->extra, data);; + if (obj) { + struct note_sub* runner; + for (runner = obj; runner; runner = runner->next) { + unref_xref_value(runner->reference); + UNREFALLFUNC(source_citation)(runner->citation); + UNREFALLFUNC(user_data)(runner->extra); + } + } } -void note_sub_cleanup(struct note_sub* note) +void CLEANFUNC(note_sub)(struct note_sub* note) { if (note) { SAFE_FREE(note->text); - DESTROY_CHAIN_ELTS(source_citation, note->citation, citation_cleanup); - DESTROY_CHAIN_ELTS(user_data, note->extra, user_data_cleanup); + DESTROY_CHAIN_ELTS(source_citation, note->citation); + DESTROY_CHAIN_ELTS(user_data, note->extra); } }