X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fnote_sub.c;h=f8dedefa46ff1496b7a7d6ee1d48e2060dbe0f08;hb=473f146038f88434e3edd070dfa42390bd0df60f;hp=5af12ca621fe3f83c92329b80f7568cdb0392bdc;hpb=72689522e287ca3b2231e7d8881f0fe5bea48f15;p=gedcom-parse.git diff --git a/gom/note_sub.c b/gom/note_sub.c index 5af12ca..f8dedef 100644 --- a/gom/note_sub.c +++ b/gom/note_sub.c @@ -52,15 +52,13 @@ 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) { + 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: @@ -104,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); } @@ -113,8 +111,33 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } -DEFINE_STRING_END_CB(note_sub, sub_note_end, text) +void sub_note_end(_ELT_END_PARAMS_) +{ + 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; + } + def_elt_end(elt, parent, self, parsed_value); + } + } +} +DEFINE_SUB_MAKEFUNC(note_sub) +DEFINE_SUB_ADDFUNC(note_sub) +DEFINE_SUB_FINDFUNC(note_sub) +DEFINE_SUB_REMOVEFUNC(note_sub) +DEFINE_SUB_MOVEFUNC(note_sub) + DEFINE_ADDFUNC2(note_sub, source_citation, citation) DEFINE_ADDFUNC2(note_sub, user_data, extra) @@ -123,6 +146,18 @@ void note_sub_subscribe() gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end); } +void UNREFALLFUNC(note_sub)(struct note_sub* obj) +{ + 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 CLEANFUNC(note_sub)(struct note_sub* note) { if (note) {