From b925ea17d6f146a28d745b0d34e9eec6eafda21f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 28 Aug 2006 12:34:40 +0000 Subject: [PATCH] Fixed bug #643: Bad sequence for MARC conversions from UTF-8 to MARC-8. Added test tstmarccol.sh for testing this. All sample ISO2709 marc records renamed to have suffix .marc. --- include/yaz/wrbuf.h | 4 +- src/marcdisp.c | 51 ++++-- src/siconv.c | 38 +++- src/wrbuf.c | 9 +- test/Makefile.am | 18 +- test/marc1 | 1 - test/marc1.marc | 1 + test/marc2 | 1 - test/marc2.marc | 1 + test/marc3 | 1 - test/marc3.marc | 1 + test/marc4 | 1 - test/marc4.marc | 1 + test/marc5 | 1 - test/marc5.marc | 1 + test/marc6 | 1 - test/marc6.marc | 1 + test/marc7.chr | 1 + test/marc7.marc | 1 + test/marc7.xml | 86 +++++++++ test/marc7.xml.marc | 1 + test/marccol1.u8.1.lst | 458 ++++++++++++++++++++++++++++++++++++++++++++++++ test/marccol1.u8.2.lst | 458 ++++++++++++++++++++++++++++++++++++++++++++++++ test/marccol1.u8.marc | 1 + test/tstmarccol.sh | 66 +++++++ test/tstmarciso.sh | 19 +- test/tstmarcxml.sh | 9 +- 27 files changed, 1185 insertions(+), 47 deletions(-) delete mode 100644 test/marc1 create mode 100644 test/marc1.marc delete mode 100644 test/marc2 create mode 100644 test/marc2.marc delete mode 100644 test/marc3 create mode 100644 test/marc3.marc delete mode 100644 test/marc4 create mode 100644 test/marc4.marc delete mode 100644 test/marc5 create mode 100644 test/marc5.marc delete mode 100644 test/marc6 create mode 100644 test/marc6.marc create mode 100644 test/marc7.chr create mode 100644 test/marc7.marc create mode 100644 test/marc7.xml create mode 100644 test/marc7.xml.marc create mode 100644 test/marccol1.u8.1.lst create mode 100644 test/marccol1.u8.2.lst create mode 100644 test/marccol1.u8.marc create mode 100755 test/tstmarccol.sh diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index c6df481..46e7e09 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: wrbuf.h,v 1.18 2006-07-07 10:31:26 marc Exp $ + * $Id: wrbuf.h,v 1.19 2006-08-28 12:34:40 adam Exp $ */ /** * \file wrbuf.h @@ -67,6 +67,8 @@ YAZ_EXPORT int wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd, const char *buf, int size); YAZ_EXPORT int wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *strz); +YAZ_EXPORT int wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch); + YAZ_EXPORT void wrbuf_chop_right(WRBUF b); #define wrbuf_len(b) ((b)->pos) diff --git a/src/marcdisp.c b/src/marcdisp.c index 1680ea5..1d408be 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.32 2006-08-01 09:28:04 adam Exp $ + * $Id: marcdisp.c,v 1.33 2006-08-28 12:34:40 adam Exp $ */ /** @@ -422,15 +422,20 @@ int yaz_marc_write_line(yaz_marc_t mt, WRBUF wr) wrbuf_puts (wr, mt->subfield_str); wrbuf_iconv_write(wr, mt->iconv_cd, s->code_data, using_code_len); - wrbuf_printf(wr, " "); + wrbuf_iconv_puts(wr, mt->iconv_cd, " "); wrbuf_iconv_puts(wr, mt->iconv_cd, s->code_data + using_code_len); + wrbuf_iconv_puts(wr, mt->iconv_cd, " "); + wr->pos--; } wrbuf_puts (wr, mt->endline_str); break; case YAZ_MARC_CONTROLFIELD: - wrbuf_printf(wr, "%s ", n->u.controlfield.tag); + wrbuf_printf(wr, "%s", n->u.controlfield.tag); + wrbuf_iconv_puts(wr, mt->iconv_cd, " "); wrbuf_iconv_puts(wr, mt->iconv_cd, n->u.controlfield.data); + wrbuf_iconv_puts(wr, mt->iconv_cd, " "); + wr->pos--; wrbuf_puts (wr, mt->endline_str); break; case YAZ_MARC_COMMENT: @@ -499,6 +504,7 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, for (n = mt->nodes; n; n = n->next) { struct yaz_marc_subfield *s; + switch(n->which) { case YAZ_MARC_DATAFIELD: @@ -514,7 +520,7 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, wrbuf_printf(wr, " ind%d=\"", i+1); wrbuf_iconv_write_cdata(wr, mt->iconv_cd, n->u.datafield.indicator+i, 1); - wrbuf_printf(wr, "\""); + wrbuf_iconv_puts(wr, mt->iconv_cd, "\""); } } wrbuf_printf(wr, ">\n"); @@ -528,14 +534,15 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, : cdata_one_character(mt, s->code_data); - wrbuf_puts(wr, " iconv_cd, " iconv_cd, s->code_data, using_code_len); - wrbuf_puts(wr, "\">"); + wrbuf_iconv_puts(wr, mt->iconv_cd, "\">"); wrbuf_iconv_write_cdata(wr, mt->iconv_cd, s->code_data + using_code_len, strlen(s->code_data + using_code_len)); - wrbuf_puts(wr, "\n"); + wrbuf_iconv_puts(wr, mt->iconv_cd, ""); + wrbuf_puts(wr, "\n"); } wrbuf_printf(wr, " \n"); break; @@ -543,9 +550,10 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, wrbuf_printf(wr, " iconv_cd, n->u.controlfield.tag, strlen(n->u.controlfield.tag)); - wrbuf_printf(wr, "\">"); + wrbuf_iconv_puts(wr, mt->iconv_cd, "\">"); wrbuf_iconv_puts(wr, mt->iconv_cd, n->u.controlfield.data); - wrbuf_printf(wr, "\n"); + wrbuf_iconv_puts(wr, mt->iconv_cd, ""); + wrbuf_puts(wr, "\n"); break; case YAZ_MARC_COMMENT: wrbuf_printf(wr, "