X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fnote.c;h=0dd24430501862bc01cd71f800156e0f1c7caecf;hb=d069cfbd954ca8d53d780ce97d7da1d363bb51fe;hp=4443da29045f7cea460146b6f47d90e555905b1b;hpb=bdf47fdee469d5a1d7ddfd06a0e4b26f3b40b0f4;p=gedcom-parse.git diff --git a/gom/note.c b/gom/note.c index 4443da2..0dd2443 100644 --- a/gom/note.c +++ b/gom/note.c @@ -46,16 +46,12 @@ Gedcom_ctxt note_start(_REC_PARAMS_) note = make_note_record(xr->string); xr->object = (Gedcom_ctxt) note; } - if (note) { - note->text = strdup(GEDCOM_STRING(parsed_value)); - if (! note->text) - MEMORY_ERROR; - else - result = MAKE_GOM_CTXT(rec, note, xr->object); - } + if (note) + result = MAKE_GOM_CTXT(rec, note, xr->object); return (Gedcom_ctxt)result; } +STRING_END_REC_CB(note, note_end, text) GET_REC_BY_XREF(note, XREF_NOTE, gom_get_note_by_xref) Gedcom_ctxt sub_cont_conc_start(_ELT_PARAMS_) @@ -65,52 +61,19 @@ Gedcom_ctxt sub_cont_conc_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; - else { - char *str = GEDCOM_STRING(parsed_value); - NL_TYPE type = (elt == ELT_SUB_CONT ? WITH_NL : WITHOUT_NL); - switch (ctxt->ctxt_type) { - case ELT_HEAD_NOTE: - header_add_to_note(type, ctxt, str); break; - case ELT_SUB_SOUR: - citation_add_to_desc(type, ctxt, str); break; - case ELT_SUB_SOUR_TEXT: - citation_add_to_text(type, ctxt, str); break; - case ELT_SUB_NOTE: - note_sub_add_to_note(type, ctxt, str); break; - case REC_NOTE: - note_add_to_note(type, ctxt, str); break; - case ELT_SOUR_AUTH: - case ELT_SOUR_TITL: - case ELT_SOUR_PUBL: - case ELT_SOUR_TEXT: - source_add_to_value(type, ctxt, str); break; - default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); - } + else result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); - } + return (Gedcom_ctxt)result; } void note_subscribe() { - gedcom_subscribe_to_record(REC_NOTE, note_start, def_rec_end); + gedcom_subscribe_to_record(REC_NOTE, note_start, note_end); gedcom_subscribe_to_element(ELT_SUB_CONT, sub_cont_conc_start, def_elt_end); gedcom_subscribe_to_element(ELT_SUB_CONC, sub_cont_conc_start, def_elt_end); } -void note_add_to_note(NL_TYPE type, Gom_ctxt ctxt, char* str) -{ - struct note *note = SAFE_CTXT_CAST(note, ctxt); - if (note) { - char *newvalue = concat_strings (type, note->text, str); - if (newvalue) - note->text = newvalue; - else - MEMORY_ERROR; - } -} - void note_add_citation(Gom_ctxt ctxt, struct source_citation* cit) { struct note *note = SAFE_CTXT_CAST(note, ctxt); @@ -125,7 +88,7 @@ void note_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref) LINK_CHAIN_ELT(user_ref_number, note->ref, ref); } -void note_set_record_id(Gom_ctxt ctxt, char *rin) +void note_set_record_id(Gom_ctxt ctxt, const char *rin) { struct note *note = SAFE_CTXT_CAST(note, ctxt); if (note) { @@ -171,7 +134,7 @@ struct note* gom_get_first_note() return gom_first_note; } -struct note* make_note_record(char* xrefstr) +struct note* make_note_record(const char* xrefstr) { struct note* note = NULL; MAKE_CHAIN_ELT(note, gom_first_note, note); @@ -181,3 +144,28 @@ struct note* make_note_record(char* xrefstr) } return note; } + +int write_notes(Gedcom_write_hndl hndl) +{ + int result = 0; + struct note* obj; + + for (obj = gom_first_note; obj; obj = obj->next) { + result |= gedcom_write_record_str(hndl, REC_NOTE, 0, + obj->xrefstr, obj->text); + if (obj->citation) + result |= write_citations(hndl, REC_NOTE, obj->citation); + if (obj->ref) + result |= write_user_refs(hndl, REC_NOTE, obj->ref); + if (obj->record_id) + result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_RIN, 0, + REC_NOTE, obj->record_id); + if (obj->change_date) + result |= write_change_date(hndl, REC_NOTE, obj->change_date); + if (obj->extra) + result |= write_user_data(hndl, obj->extra); + } + + return result; +} +