2 * Copyright (c) 1997-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: siconvtst.c,v 1.4 2002-08-28 19:33:53 adam Exp $
16 #include <yaz/yaz-util.h>
20 void convert (FILE *inf, yaz_iconv_t cd)
22 char inbuf0[CHUNK], *inbuf = inbuf0;
23 char outbuf0[CHUNK], *outbuf = outbuf0;
24 size_t outbytesleft = CHUNK;
25 size_t inbytesleft = CHUNK;
33 r = fread (inbuf, 1, inbytesleft, inf);
38 fprintf (stderr, "yaziconv: error reading file\n");
43 if (outbuf != outbuf0)
44 fwrite (outbuf0, 1, outbuf - outbuf0, stdout);
50 r = yaz_iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
51 if (r == (size_t)(-1))
53 int e = yaz_iconv_error(cd);
54 if (e == YAZ_ICONV_EILSEQ)
56 fprintf (stderr, "invalid sequence\n");
59 else if (e == YAZ_ICONV_EINVAL) /* incomplete input */
62 for (i = 0; i<inbytesleft; i++)
65 inbytesleft = CHUNK - inbytesleft;
68 else if (e == YAZ_ICONV_E2BIG) /* no more output space */
70 fwrite (outbuf0, 1, outbuf - outbuf0, stdout);
77 fprintf (stderr, "yaziconv: unknown error\n");
86 fwrite (outbuf0, 1, outbuf - outbuf0, stdout);
95 int main (int argc, char **argv)
104 while ((ret = options ("f:t:", argv, argc, &arg)) != -2)
109 inf = fopen (arg, "rb");
112 fprintf (stderr, "yaziconv: cannot open %s", arg);
123 fprintf (stderr, "yaziconv: Usage\n"
124 "siconv -f encoding -t encoding [file]\n");
130 fprintf (stderr, "yaziconv: -t encoding missing\n");
135 fprintf (stderr, "yaziconv: -f encoding missing\n");
138 cd = yaz_iconv_open (to, from);
141 fprintf (stderr, "yaziconv: unsupported encoding\n");
146 yaz_iconv_close (cd);