ignore-value: remove dependency on stdint
[gnulib.git] / tests / test-iconvme.c
blob38165f7dfc2293a7e0324e3f86cb1dab4e886e37
1 /* Recode strings between character sets, using iconv.
2 Copyright (C) 2004-2005, 2009-2011 Free Software Foundation, Inc.
3 Written by Simon Josefsson.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include <config.h>
20 #include <stdlib.h>
21 #include <stdio.h>
23 #include "iconvme.h"
25 int main (int ac, char *av[])
27 char *in = NULL, *out = NULL;
28 char *to = NULL, *from = NULL;
30 if (ac > 1)
31 from = av[1];
33 if (ac > 2)
34 to = av[2];
36 if (ac > 3)
37 in = av[3];
39 if (!in)
41 size_t len = 0;
42 printf ("Enter string to convert:\n\t> ");
43 if (getline (&in, &len, stdin) < 0)
44 perror ("getline");
45 if (in[strlen (in) - 1] == '\n')
46 in[strlen (in) - 1] = '\0';
49 if (!to)
51 size_t len = 0;
52 printf ("Enter destination code set:\n\t> ");
53 if (getline (&to, &len, stdin) < 0)
54 perror ("getline");
55 if (to[strlen (to) - 1] == '\n')
56 to[strlen (to) - 1] = '\0';
59 if (!from)
61 size_t len = 0;
62 printf ("Enter source code set:\n\t> ");
63 if (getline (&from, &len, stdin) < 0)
64 perror ("getline");
65 if (from[strlen (from) - 1] == '\n')
66 from[strlen (from) - 1] = '\0';
69 printf (" Input string: `%s'\n"
70 "From code set: `%s'\n"
71 " To code set: `%s'\n",
72 in, from, to);
74 out = iconv_string (in, from, to);
76 if (out == NULL)
77 perror ("iconv");
78 else
80 printf ("\nOutput: `%s'\n", out);
81 free (out);
84 return EXIT_SUCCESS;