X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=retrieval%2Fd1_read.c;h=130c51853d7dfcf2acef1e66f045b50a3f11ff45;hb=9dffa786b23759414b476e152f590f6aa0e8aa3a;hp=289d35223d4c40ced14ae2bff78bfeea6141022d;hpb=9fa5e9b2a5a3ba0644178d5ed85869a31ffe59f2;p=yaz-moved-to-github.git diff --git a/retrieval/d1_read.c b/retrieval/d1_read.c index 289d352..130c518 100644 --- a/retrieval/d1_read.c +++ b/retrieval/d1_read.c @@ -3,20 +3,15 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_read.c,v 1.49 2002-08-23 14:27:18 adam Exp $ + * $Id: d1_read.c,v 1.51 2002-08-28 07:54:11 adam Exp $ */ #include #include #include -#include - -#if HAVE_ICONV_H -#include -#endif - #include +#include #include #include @@ -533,9 +528,9 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, { data1_xattr *p; int len; - while (amp || (c && d1_isspace(c))) + while (*amp || (c && d1_isspace(c))) c = ampr (get_byte, fh, amp); - if (amp == 0 && (c == 0 || c == '>' || c == '/')) + if (*amp == 0 && (c == 0 || c == '>' || c == '/')) break; *pp = p = (data1_xattr *) nmem_malloc (m, sizeof(*p)); p->next = 0; @@ -555,11 +550,11 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, if (c == '=') { c = ampr (get_byte, fh, amp); - if (amp == 0 && c == '"') + if (*amp == 0 && c == '"') { c = ampr (get_byte, fh, amp); wrbuf_rewind(wrbuf); - while (amp || (c && c != '"')) + while (*amp || (c && c != '"')) { wrbuf_putc (wrbuf, c); c = ampr (get_byte, fh, amp); @@ -567,11 +562,11 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, if (c) c = ampr (get_byte, fh, amp); } - else if (amp == 0 && c == '\'') + else if (*amp == 0 && c == '\'') { c = ampr (get_byte, fh, amp); wrbuf_rewind(wrbuf); - while (amp || (c && c != '\'')) + while (*amp || (c && c != '\'')) { wrbuf_putc (wrbuf, c); c = ampr (get_byte, fh, amp); @@ -582,7 +577,7 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, else { wrbuf_rewind(wrbuf); - while (amp || (c && c != '>' && c != '/')) + while (*amp || (c && c != '>' && c != '/')) { wrbuf_putc (wrbuf, c); c = ampr (get_byte, fh, amp); @@ -871,9 +866,7 @@ data1_node *data1_read_sgml (data1_handle dh, NMEM m, const char *buf) } -#if HAVE_ICONV_H - -static int conv_item (NMEM m, iconv_t t, +static int conv_item (NMEM m, yaz_iconv_t t, WRBUF wrbuf, char *inbuf, size_t inlen) { wrbuf_rewind (wrbuf); @@ -883,8 +876,8 @@ static int conv_item (NMEM m, iconv_t t, { char *outbuf = wrbuf->buf + wrbuf->pos; size_t outlen = wrbuf->size - wrbuf->pos; - if (iconv (t, &inbuf, &inlen, &outbuf, &outlen) == - (size_t)(-1) && errno != E2BIG) + if (yaz_iconv (t, &inbuf, &inlen, &outbuf, &outlen) == + (size_t)(-1) && yaz_iconv_error(t) != YAZ_ICONV_E2BIG) { /* bad data. stop and skip conversion entirely */ return -1; @@ -905,7 +898,7 @@ static int conv_item (NMEM m, iconv_t t, } static void data1_iconv_s (data1_handle dh, NMEM m, data1_node *n, - iconv_t t, WRBUF wrbuf, const char *tocode) + yaz_iconv_t t, WRBUF wrbuf, const char *tocode) { for (; n; n = n->next) { @@ -957,7 +950,6 @@ static void data1_iconv_s (data1_handle dh, NMEM m, data1_node *n, data1_iconv_s (dh, m, n->child, t, wrbuf, tocode); } } -#endif const char *data1_get_encoding (data1_handle dh, data1_node *n) { @@ -982,19 +974,15 @@ int data1_iconv (data1_handle dh, NMEM m, data1_node *n, const char *tocode, const char *fromcode) { -#if HAVE_ICONV_H if (strcmp (tocode, fromcode)) { WRBUF wrbuf = wrbuf_alloc(); - iconv_t t = iconv_open (tocode, fromcode); - if (t == (iconv_t) (-1)) + yaz_iconv_t t = yaz_iconv_open (tocode, fromcode); + if (!t) return -1; data1_iconv_s (dh, m, n, t, wrbuf, tocode); - iconv_close (t); + yaz_iconv_close (t); wrbuf_free (wrbuf, 1); } return 0; -#else - return -2; -#endif }