A test program for filter_iconv
Showing
1 changed file
with
66 additions
and
0 deletions
examples/iconv.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2004 Free Software Foundation, Inc. | ||
3 | |||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Mailutils is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with GNU Mailutils; if not, write to the Free Software | ||
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | ||
17 | |||
18 | #include <stdio.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <string.h> | ||
21 | #include <errno.h> | ||
22 | #include <unistd.h> | ||
23 | #include <assert.h> | ||
24 | |||
25 | #include <mailutils/mailutils.h> | ||
26 | |||
27 | int | ||
28 | main (int argc, char **argv) | ||
29 | { | ||
30 | int rc; | ||
31 | stream_t in, out; | ||
32 | stream_t cvt; | ||
33 | size_t total = 0, size; | ||
34 | char buffer[80]; | ||
35 | |||
36 | if (argc != 3) | ||
37 | { | ||
38 | fprintf (stderr, "usage: %s from-code to-code\n", argv[0]); | ||
39 | return 1; | ||
40 | } | ||
41 | |||
42 | rc = stdio_stream_create (&in, stdin, 0); | ||
43 | assert (rc == 0); | ||
44 | assert (stream_open (in) == 0); | ||
45 | assert (filter_iconv_create (&cvt, in, argv[1], argv[2], 0) == 0); | ||
46 | assert (stream_open (cvt) == 0); | ||
47 | |||
48 | rc = stdio_stream_create (&out, stdout, 0); | ||
49 | assert (rc == 0); | ||
50 | assert (stream_open (out) == 0); | ||
51 | |||
52 | while ((rc = stream_read (cvt, buffer, sizeof (buffer), total, &size)) == 0 | ||
53 | && size > 0) | ||
54 | { | ||
55 | stream_sequential_write (out, buffer, size); | ||
56 | total += size; | ||
57 | } | ||
58 | stream_flush (out); | ||
59 | if (rc) | ||
60 | { | ||
61 | char *p; | ||
62 | stream_strerror (cvt, &p); | ||
63 | fprintf (stderr, "error: %s / %s\n", mu_strerror (rc), p); | ||
64 | } | ||
65 | return 0; | ||
66 | } |
-
Please register or sign in to post a comment