From 11594352845d8e70c9d668c20fde891a1d45f3d6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 24 Jan 2007 15:14:57 +0000 Subject: [PATCH 1/1] Fixed bug #832: Problem with MARC/charset in yaz-client. --- NEWS | 2 ++ client/client.c | 75 ++++++++++++++++++++----------------------------------- 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/NEWS b/NEWS index 51ee56a..9db4d91 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +Fixed bug #832: Problem with MARC/charset in yaz-client. + Fixed bug #668: save command line history for yaz-client. Fixed bug #830: pkg-config support. diff --git a/client/client.c b/client/client.c index 1055bff..ac57c74 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: client.c,v 1.325 2007-01-24 11:50:18 adam Exp $ + * $Id: client.c,v 1.326 2007-01-24 15:14:57 adam Exp $ */ /** \file client.c * \brief yaz-client program @@ -939,62 +939,41 @@ static void display_record(Z_External *r) int rlen; yaz_iconv_t cd = 0; yaz_marc_t mt = yaz_marc_create(); - - if (yaz_marc_decode_buf(mt, octet_buf,r->u.octet_aligned->len, - &result, &rlen)> 0) + const char *from = 0; + + if (marcCharset && !strcmp(marcCharset, "auto")) { - char *from = 0; - if (marcCharset && !strcmp(marcCharset, "auto")) + if (ent->value == VAL_USMARC) { - if (ent->value == VAL_USMARC) - { - if (octet_buf[9] == 'a') - from = "UTF-8"; - else - from = "MARC-8"; - } + if (octet_buf[9] == 'a') + from = "UTF-8"; else - from = "ISO-8859-1"; - } - else if (marcCharset) - from = marcCharset; - if (outputCharset && from) - { - cd = yaz_iconv_open(outputCharset, from); - printf ("convert from %s to %s", from, - outputCharset); - if (!cd) - printf (" unsupported\n"); - else - printf ("\n"); + from = "MARC-8"; } + else + from = "ISO-8859-1"; + } + else if (marcCharset) + from = marcCharset; + if (outputCharset && from) + { + cd = yaz_iconv_open(outputCharset, from); + printf ("convert from %s to %s", from, + outputCharset); if (!cd) - fwrite (result, 1, rlen, stdout); + printf (" unsupported\n"); else { - char outbuf[6]; - size_t inbytesleft = rlen; - const char *inp = result; - - while (inbytesleft) - { - size_t outbytesleft = sizeof(outbuf); - char *outp = outbuf; - size_t r; - - r = yaz_iconv (cd, (char**) &inp, - &inbytesleft, - &outp, &outbytesleft); - if (r == (size_t) (-1)) - { - int e = yaz_iconv_error(cd); - if (e != YAZ_ICONV_E2BIG) - break; - } - fwrite (outbuf, outp - outbuf, 1, stdout); - } + yaz_marc_iconv(mt, cd); + printf ("\n"); } } + + if (yaz_marc_decode_buf(mt, octet_buf,r->u.octet_aligned->len, + &result, &rlen)> 0) + { + fwrite (result, rlen, 1, stdout); + } else { printf ("bad MARC. Dumping as it is:\n"); -- 1.7.10.4