This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20 #include <stdlib.h>
21 #include <stdio.h>
22
23 #include "iconvme.h"
24
25 int main (int ac, char *av[])
26 {
27 char *in = NULL, *out = NULL;
28 char *to = NULL, *from = NULL;
29
30 if (ac > 1)
31 from = av[1];
32
33 if (ac > 2)
34 to = av[2];
35
36 if (ac > 3)
37 in = av[3];
38
39 if (!in)
40 {
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';
47 }
48
49 if (!to)
50 {
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';
57 }
58
59 if (!from)
60 {
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';
67 }
68
69 printf (" Input string: '%s'\n"
70 "From code set: '%s'\n"
71 " To code set: '%s'\n",
72 in, from, to);
73
74 out = iconv_string (in, from, to);
75
76 if (out == NULL)
77 perror ("iconv");
78 else
79 {
80 printf ("\nOutput: '%s'\n", out);
81 free (out);
82 }
83
84 return EXIT_SUCCESS;
85 }