Code updates which makes things compile as C++. Mostly type casts were
[yaz-moved-to-github.git] / src / marcdisp.c
index 6544559..bde5fd0 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2007, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: marcdisp.c,v 1.48 2007-03-19 14:40:07 adam Exp $
+ * $Id: marcdisp.c,v 1.50 2007-05-06 20:12:20 adam Exp $
  */
 
 /**
@@ -128,15 +128,7 @@ NMEM yaz_marc_get_nmem(yaz_marc_t mt)
 
 static void marc_iconv_reset(yaz_marc_t mt, WRBUF wr)
 {
-    if (mt->iconv_cd)
-    {
-        char outbuf[12];
-        size_t outbytesleft = sizeof(outbuf);
-        char *outp = outbuf;
-        size_t r = yaz_iconv(mt->iconv_cd, 0, 0, &outp, &outbytesleft);
-        if (r != (size_t) (-1))
-            wrbuf_write(wr, outbuf, outp - outbuf);
-    }
+    wrbuf_iconv_reset(wr, mt->iconv_cd);
 }
 
 static int marc_exec_leader(const char *leader_spec, char *leader,
@@ -145,7 +137,8 @@ static int marc_exec_leader(const char *leader_spec, char *leader,
 
 static struct yaz_marc_node *yaz_marc_add_node(yaz_marc_t mt)
 {
-    struct yaz_marc_node *n = nmem_malloc(mt->nmem, sizeof(*n));
+    struct yaz_marc_node *n = (struct yaz_marc_node *)
+        nmem_malloc(mt->nmem, sizeof(*n));
     n->next = 0;
     *mt->nodes_pp = n;
     mt->nodes_pp = &n->next;
@@ -264,7 +257,8 @@ void yaz_marc_add_subfield(yaz_marc_t mt,
 
     if (mt->subfield_pp)
     {
-        struct yaz_marc_subfield *n = nmem_malloc(mt->nmem, sizeof(*n));
+        struct yaz_marc_subfield *n = (struct yaz_marc_subfield *)
+            nmem_malloc(mt->nmem, sizeof(*n));
         n->code_data = nmem_strdupn(mt->nmem, code_data, code_data_len);
         n->next = 0;
         /* mark subfield_pp to point to this one, so we append here next */
@@ -491,6 +485,7 @@ int yaz_marc_write_line(yaz_marc_t mt, WRBUF wr)
             wrbuf_puts(wr, "(");
             wrbuf_iconv_write(wr, mt->iconv_cd, 
                               n->u.comment, strlen(n->u.comment));
+            marc_iconv_reset(mt, wr);
             wrbuf_puts(wr, ")\n");
             break;
         case YAZ_MARC_LEADER:
@@ -847,6 +842,7 @@ int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr)
             }
             /* write dummy FS (makes MARC-8 to become ASCII) */
             wrbuf_iconv_putchar(wr_data_tmp, mt->iconv_cd, ' ');
+            marc_iconv_reset(mt, wr_data_tmp);
             data_length += wrbuf_len(wr_data_tmp);
             break;
         case YAZ_MARC_CONTROLFIELD:
@@ -857,6 +853,7 @@ int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr)
                              n->u.controlfield.data);
             marc_iconv_reset(mt, wr_data_tmp);
             wrbuf_iconv_putchar(wr_data_tmp, mt->iconv_cd, ' ');/* field sep */
+            marc_iconv_reset(mt, wr_data_tmp);
             data_length += wrbuf_len(wr_data_tmp);
             break;
         case YAZ_MARC_COMMENT: