2 * Simple character set convertor
4 * (c) 1998 Pavel Machek <pavel@ucw.cz>
5 * (c) 2003 Martin Mares <mj@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU General Public License.
12 #include <charset/charconv.h>
25 main(int argc, char **argv)
27 struct conv_context ctxt;
28 int ch_from, ch_to, n, flags;
29 char inbuf[BUFSIZE], outbuf[BUFSIZE];
32 die("cs2cs in-charset out-charset");
34 ch_from = find_charset_by_name(argv[1]);
36 die("Unknown charset %s", argv[1]);
37 ch_to = find_charset_by_name(argv[2]);
39 die("Unknown charset %s", argv[2]);
41 conv_set_charset(&ctxt, ch_from, ch_to);
42 while ((n = read(0, inbuf, sizeof(inbuf))) > 0)
45 ctxt.source_end = inbuf + n;
46 ctxt.dest = ctxt.dest_start = outbuf;
47 ctxt.dest_end = outbuf + sizeof(outbuf);
50 flags = conv_run(&ctxt);
51 if (flags & (CONV_SOURCE_END | CONV_DEST_END))
53 int w = write(1, ctxt.dest_start, ctxt.dest - ctxt.dest_start);
55 die("write error: %m");
59 while (! (flags & CONV_SOURCE_END));
62 die("read error: %m");