X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmarcdisp.c;h=e7df01ec1aa2cbd13a54dabfac6662ae32522e15;hb=3ee7ef4088b265faffbdcabe3eb13d5f04a3b832;hp=ea4b2bcedbcb0f76ca0dc8c76bc09ffad106c431;hpb=626ee9b09c95c3585c432623c042872b0d1fea92;p=yaz-moved-to-github.git diff --git a/src/marcdisp.c b/src/marcdisp.c index ea4b2bc..e7df01e 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.26 2006-04-19 10:05:03 adam Exp $ + * $Id: marcdisp.c,v 1.30 2006-05-23 13:17:30 adam Exp $ */ /** @@ -132,25 +132,6 @@ void yaz_marc_add_comment(yaz_marc_t mt, char *comment) n->u.comment = nmem_strdup(mt->nmem, comment); } -#if HAVE_XML2 -static char *yaz_marc_get_xml_text(const xmlNode *ptr_cdata, NMEM nmem) -{ - char *cdata; - int len = 0; - const xmlNode *ptr; - - for (ptr = ptr_cdata; ptr; ptr = ptr->next) - if (ptr->type == XML_TEXT_NODE) - len += xmlStrlen(ptr->content); - cdata = (char *) nmem_malloc(nmem, len+1); - *cdata = '\0'; - for (ptr = ptr_cdata; ptr; ptr = ptr->next) - if (ptr->type == XML_TEXT_NODE) - strcat(cdata, (const char *) ptr->content); - return cdata; -} -#endif - void yaz_marc_cprintf(yaz_marc_t mt, const char *fmt, ...) { va_list ap; @@ -206,8 +187,8 @@ void yaz_marc_add_controlfield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, { struct yaz_marc_node *n = yaz_marc_add_node(mt); n->which = YAZ_MARC_CONTROLFIELD; - n->u.controlfield.tag = yaz_marc_get_xml_text(ptr_tag, mt->nmem); - n->u.controlfield.data = yaz_marc_get_xml_text(ptr_data, mt->nmem); + n->u.controlfield.tag = nmem_text_node_cdata(ptr_tag, mt->nmem); + n->u.controlfield.data = nmem_text_node_cdata(ptr_data, mt->nmem); } #endif @@ -231,7 +212,7 @@ void yaz_marc_add_datafield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, { struct yaz_marc_node *n = yaz_marc_add_node(mt); n->which = YAZ_MARC_DATAFIELD; - n->u.datafield.tag = yaz_marc_get_xml_text(ptr_tag, mt->nmem); + n->u.datafield.tag = nmem_text_node_cdata(ptr_tag, mt->nmem); n->u.datafield.indicator = nmem_strdupn(mt->nmem, indicator, indicator_len); n->u.datafield.subfields = 0; @@ -370,16 +351,6 @@ void yaz_marc_endline_str(yaz_marc_t mt, const char *s) mt->endline_str[sizeof(mt->endline_str)-1] = '\0'; } -static void marc_cdata (yaz_marc_t mt, const char *buf, size_t len, WRBUF wr) -{ - if (mt->xml == YAZ_MARC_ISO2709) - wrbuf_iconv_write(wr, mt->iconv_cd, buf, len); - else if (mt->xml == YAZ_MARC_LINE) - wrbuf_iconv_write(wr, mt->iconv_cd, buf, len); - else - wrbuf_iconv_write_cdata(wr, mt->iconv_cd, buf, len); -} - /* try to guess how many bytes the identifier really is! */ static size_t cdata_one_character(yaz_marc_t mt, const char *buf) { @@ -484,15 +455,24 @@ int yaz_marc_write_mode(yaz_marc_t mt, WRBUF wr) case YAZ_MARC_MARCXML: return yaz_marc_write_marcxml(mt, wr); case YAZ_MARC_XCHANGE: - return yaz_marc_write_marcxchange(mt, wr); + return yaz_marc_write_marcxchange(mt, wr, 0, 0); /* no format, type */ case YAZ_MARC_ISO2709: return yaz_marc_write_iso2709(mt, wr); } return -1; } +/** \brief common MARC XML/Xchange writer + \param mt handle + \param wr WRBUF output + \param ns XMLNS for the elements + \param format record format (e.g. "MARC21") + \param type record type (e.g. "Bibliographic") +*/ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, - const char *ns) + const char *ns, + const char *format, + const char *type) { struct yaz_marc_node *n; int identifier_length; @@ -510,7 +490,12 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, if (!atoi_n_check(leader+11, 1, &identifier_length)) return -1; - wrbuf_printf(wr, "\n", ns); + wrbuf_printf(wr, "\n"); for (n = mt->nodes; n; n = n->next) { struct yaz_marc_subfield *s; @@ -563,7 +548,9 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, wrbuf_printf(wr, "\n"); break; case YAZ_MARC_COMMENT: - wrbuf_printf(wr, "\n", n->u.comment); + wrbuf_printf(wr, "\n"); break; case YAZ_MARC_LEADER: wrbuf_printf(wr, " "); @@ -579,13 +566,18 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wr) { - return yaz_marc_write_marcxml_ns(mt, wr, "http://www.loc.gov/MARC21/slim"); + yaz_marc_modify_leader(mt, 9, "a"); + return yaz_marc_write_marcxml_ns(mt, wr, "http://www.loc.gov/MARC21/slim", + 0, 0); } -int yaz_marc_write_marcxchange(yaz_marc_t mt, WRBUF wr) +int yaz_marc_write_marcxchange(yaz_marc_t mt, WRBUF wr, + const char *format, + const char *type) { return yaz_marc_write_marcxml_ns(mt, wr, - "http://www.bs.dk/standards/MarcXchange"); + "http://www.bs.dk/standards/MarcXchange", + 0, 0); } int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr) @@ -680,11 +672,15 @@ int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr) wrbuf_printf(wr, "%.*s", indicator_length, n->u.datafield.indicator); for (s = n->u.datafield.subfields; s; s = s->next) - wrbuf_printf(wr, "%c%s", ISO2709_IDFS, s->code_data); + { + wrbuf_printf(wr, "%c", ISO2709_IDFS); + wrbuf_puts(wr, s->code_data); + } wrbuf_printf(wr, "%c", ISO2709_FS); break; case YAZ_MARC_CONTROLFIELD: - wrbuf_printf(wr, "%s%c", n->u.controlfield.data, ISO2709_FS); + wrbuf_puts(wr, n->u.controlfield.data); + wrbuf_printf(wr, "%c", ISO2709_FS); break; case YAZ_MARC_COMMENT: break; @@ -1126,6 +1122,19 @@ void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd) mt->iconv_cd = cd; } +void yaz_marc_modify_leader(yaz_marc_t mt, size_t off, const char *str) +{ + struct yaz_marc_node *n; + char *leader = 0; + for (n = mt->nodes; n; n = n->next) + if (n->which == YAZ_MARC_LEADER) + { + leader = n->u.leader; + memcpy(leader+off, str, strlen(str)); + break; + } +} + /* deprecated */ int yaz_marc_decode(const char *buf, WRBUF wr, int debug, int bsize, int xml) {