2 * Copyright (c) 1997-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: siconvtst.c,v 1.1 2002-08-27 14:02:13 adam Exp $
16 #include <yaz/yaz-util.h>
20 static 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;
29 size_t r = fread (inbuf, 1, inbytesleft, inf);
34 fprintf (stderr, "yaziconv: error reading file\n");
39 if (outbuf != outbuf0)
40 fwrite (outbuf0, 1, outbuf - outbuf0, stdout);
44 r = yaz_iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
45 if (r == (size_t)(-1))
47 if (yaz_iconv_error(cd) == YAZ_ICONV_EILSEQ)
49 fprintf (stderr, "invalid sequence\n");
53 if (yaz_iconv_error(cd) == EINVAL) /* incomplete input */
56 for (i = 0; i<inbytesleft; i++)
58 inbytesleft = CHUNK - inbytesleft;
60 if (yaz_iconv_error(cd) == E2BIG) /* no more output space */
62 fwrite (outbuf0, 1, outbuf - outbuf0, stdout);
68 fprintf (stderr, "yaziconv: unknown error\n");
80 int main (int argc, char **argv)
89 while ((ret = options ("f:t:", argv, argc, &arg)) != -2)
94 inf = fopen (arg, "rb");
97 fprintf (stderr, "yaziconv: cannot open %s", arg);
108 fprintf (stderr, "yaziconv: Usage\n"
109 "siconv -f encoding -t encoding [file]\n");
115 fprintf (stderr, "yaziconv: -t encoding missing\n");
120 fprintf (stderr, "yaziconv: -f encoding missing\n");
123 cd = yaz_iconv_open (to, from);
126 fprintf (stderr, "yaziconv: unsupported encoding\n");
131 yaz_iconv_close (cd);