Fixed bug #832: Problem with MARC/charset in yaz-client.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 24 Jan 2007 15:14:57 +0000 (15:14 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 24 Jan 2007 15:14:57 +0000 (15:14 +0000)
NEWS
client/client.c

diff --git a/NEWS b/NEWS
index 51ee56a..9db4d91 100644 (file)
--- 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.
index 1055bff..ac57c74 100644 (file)
@@ -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");