X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fsiconv.c;h=ba54b163b5e2fa698beec385c62011d8d7bedd7c;hb=b7d2e2be0cdfdcd7703f4097165c5342202b9c65;hp=bee184bf58c519061fd0d984562e981043571e4c;hpb=711f37334de1dde9fee4dfdee2e9263f42373494;p=yaz-moved-to-github.git diff --git a/src/siconv.c b/src/siconv.c index bee184b..ba54b16 100644 --- a/src/siconv.c +++ b/src/siconv.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: siconv.c,v 1.22 2006-04-24 23:21:26 adam Exp $ + * $Id: siconv.c,v 1.24 2006-08-04 14:35:40 adam Exp $ */ /** * \file siconv.c @@ -198,8 +198,9 @@ static size_t yaz_init_UTF8 (yaz_iconv_t cd, unsigned char *inp, return 0; } -static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, - size_t inbytesleft, size_t *no_read) +unsigned long yaz_read_UTF8_char(unsigned char *inp, + size_t inbytesleft, size_t *no_read, + int *error) { unsigned long x = 0; @@ -211,7 +212,7 @@ static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, else if (inp[0] <= 0xbf || inp[0] >= 0xfe) { *no_read = 0; - cd->my_errno = YAZ_ICONV_EILSEQ; + *error = YAZ_ICONV_EILSEQ; } else if (inp[0] <= 0xdf && inbytesleft >= 2) { @@ -221,7 +222,7 @@ static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, else { *no_read = 0; - cd->my_errno = YAZ_ICONV_EILSEQ; + *error = YAZ_ICONV_EILSEQ; } } else if (inp[0] <= 0xef && inbytesleft >= 3) @@ -233,7 +234,7 @@ static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, else { *no_read = 0; - cd->my_errno = YAZ_ICONV_EILSEQ; + *error = YAZ_ICONV_EILSEQ; } } else if (inp[0] <= 0xf7 && inbytesleft >= 4) @@ -245,7 +246,7 @@ static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, else { *no_read = 0; - cd->my_errno = YAZ_ICONV_EILSEQ; + *error = YAZ_ICONV_EILSEQ; } } else if (inp[0] <= 0xfb && inbytesleft >= 5) @@ -258,7 +259,7 @@ static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, else { *no_read = 0; - cd->my_errno = YAZ_ICONV_EILSEQ; + *error = YAZ_ICONV_EILSEQ; } } else if (inp[0] <= 0xfd && inbytesleft >= 6) @@ -271,17 +272,23 @@ static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, else { *no_read = 0; - cd->my_errno = YAZ_ICONV_EILSEQ; + *error = YAZ_ICONV_EILSEQ; } } else { *no_read = 0; - cd->my_errno = YAZ_ICONV_EINVAL; + *error = YAZ_ICONV_EINVAL; } return x; } +static unsigned long yaz_read_UTF8 (yaz_iconv_t cd, unsigned char *inp, + size_t inbytesleft, size_t *no_read) +{ + return yaz_read_UTF8_char(inp, inbytesleft, no_read, &cd->my_errno); +} + static unsigned long yaz_read_UCS4 (yaz_iconv_t cd, unsigned char *inp, size_t inbytesleft, size_t *no_read) { @@ -785,9 +792,9 @@ static size_t flush_combos(yaz_iconv_t cd, return 0; } -static size_t yaz_write_marc8(yaz_iconv_t cd, unsigned long x, - char **outbuf, size_t *outbytesleft, - int last) +static size_t yaz_write_marc8_2(yaz_iconv_t cd, unsigned long x, + char **outbuf, size_t *outbytesleft, + int last) { int comb = 0; const char *page_chr = 0; @@ -837,6 +844,41 @@ static size_t yaz_write_marc8(yaz_iconv_t cd, unsigned long x, return 0; } +static size_t yaz_write_marc8(yaz_iconv_t cd, unsigned long x, + char **outbuf, size_t *outbytesleft, + int last) +{ + int i; + for (i = 0; latin1_comb[i].x1; i++) + { + if (x == latin1_comb[i].y) + { + size_t r ; + /* save the output pointers .. */ + char *outbuf0 = *outbuf; + size_t outbytesleft0 = *outbytesleft; + int last_ch = cd->write_marc8_last; + + r = yaz_write_marc8_2(cd, latin1_comb[i].x1, + outbuf, outbytesleft, 0); + if (r) + return r; + r = yaz_write_marc8_2(cd, latin1_comb[i].x2, + outbuf, outbytesleft, last); + if (r && cd->my_errno == YAZ_ICONV_E2BIG) + { + /* not enough room. reset output to original values */ + *outbuf = outbuf0; + *outbytesleft = outbytesleft0; + cd->write_marc8_last = last_ch; + } + return r; + } + } + return yaz_write_marc8_2(cd, x, outbuf, outbytesleft, last); +} + + #if HAVE_WCHAR_H static size_t yaz_write_wchar_t (yaz_iconv_t cd, unsigned long x, char **outbuf, size_t *outbytesleft,