From cde148647135f1a06f5b5ebf769430a9615d86bc Mon Sep 17 00:00:00 2001 From: Dennis Schafroth Date: Fri, 5 Mar 2010 16:05:24 +0100 Subject: [PATCH] Fixed memory alloction errors. Added new function for turbo marcxml format. Handling decoding of subfield as hex number --- src/marc_read_xml.c | 8 +++----- src/marcdisp.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/marc_read_xml.c b/src/marc_read_xml.c index 650106c..f68906a 100644 --- a/src/marc_read_xml.c +++ b/src/marc_read_xml.c @@ -99,13 +99,13 @@ const char *tag_value_extract(const char *name, char tag_buffer[5]) { return 0; } -// pattern 2 && length < 5) { + if (length > 2 && length < 6) { if (name[0] != '-') { return 0; } @@ -314,7 +314,7 @@ static int yaz_marc_read_xml_fields(yaz_marc_t mt, const xmlNode *ptr) return 0; } -struct yaz_marc_node* yaz_marc_add_datafield_turbo_xml(yaz_marc_t mt, const char *tag_value); +struct yaz_marc_node* yaz_marc_add_datafield_turbo_xml(yaz_marc_t mt, char *tag_value); static int yaz_marc_read_turbo_xml_fields(yaz_marc_t mt, const xmlNode *ptr) { @@ -325,7 +325,6 @@ static int yaz_marc_read_turbo_xml_fields(yaz_marc_t mt, const xmlNode *ptr) { NMEM nmem = yaz_marc_get_nmem(mt); char *buffer = (char *) nmem_malloc(nmem, 5); - //Extract the tag value out of the rest of the element name const char *tag_value = tag_value_extract((const char *)(ptr->name+1), buffer); if (!tag_value) { @@ -334,7 +333,6 @@ static int yaz_marc_read_turbo_xml_fields(yaz_marc_t mt, const xmlNode *ptr) return -1; } yaz_marc_add_controlfield_turbo_xml(mt, tag_value, ptr->children); - //wrbuf_destroy(tag_value); } else if (!strncmp((const char *) ptr->name, "d",1)) { diff --git a/src/marcdisp.c b/src/marcdisp.c index bd03c00..75e6d3c 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -163,6 +163,16 @@ void yaz_marc_add_controlfield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, n->u.controlfield.tag = nmem_text_node_cdata(ptr_tag, mt->nmem); n->u.controlfield.data = nmem_text_node_cdata(ptr_data, mt->nmem); } + +void yaz_marc_add_controlfield_turbo_xml(yaz_marc_t mt, const char *tag, + const xmlNode *ptr_data) +{ + struct yaz_marc_node *n = yaz_marc_add_node(mt); + n->which = YAZ_MARC_CONTROLFIELD; + n->u.controlfield.tag = tag; + n->u.controlfield.data = nmem_text_node_cdata(ptr_data, mt->nmem); +} + #endif @@ -527,6 +537,7 @@ int yaz_marc_write_trailer(yaz_marc_t mt, WRBUF wr) switch(mt->output_format) { case YAZ_MARC_MARCXML: + case YAZ_MARC_TMARCXML: wrbuf_printf(wr, "\n"); break; case YAZ_MARC_XCHANGE: @@ -751,6 +762,7 @@ void add_marc_datafield_turbo_xml(yaz_marc_t mt, struct yaz_marc_node *n, xmlNod char field[10]; field[0] = 'd'; strncpy(field + 1, n->u.datafield.tag, 3); + field[4] = '\0'; ptr = xmlNewChild(record_ptr, ns_record, BAD_CAST field, 0); } if (n->u.datafield.indicator) @@ -883,6 +895,7 @@ int yaz_marc_write_turbo_xml(yaz_marc_t mt, xmlNode **root_ptr, char field[10]; field[0] = 'c'; strncpy(field + 1, n->u.controlfield.tag, 3); + field[4] = '\0'; ptr = xmlNewTextChild(record_ptr, ns_record, BAD_CAST field, BAD_CAST wrbuf_cstr(wr_cdata)); -- 1.7.10.4