1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2010, 2011 Free Software Foundation, Inc.
4 This program 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 3 of the License, or
7 (at your option) any later version.
9 This program 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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "libpspp/i18n.h"
29 main (int argc, char *argv[])
33 if (argc == 5 && !strcmp (argv[1], "recode"))
35 const char *from = argv[2];
36 const char *to = argv[3];
37 const char *string = argv[4];
38 char *result = recode_string (to, from, string, -1);
40 assert (strlen (result) == recode_string_len (to, from, string, -1));
43 else if (argc == 6 && !strcmp (argv[1], "concat"))
45 const char *head = argv[2];
46 const char *tail = argv[3];
47 const char *encoding = argv[4];
48 int max_len = atoi (argv[5]);
51 result = utf8_encoding_concat (head, tail, encoding, max_len);
54 assert (strlen (result)
55 == utf8_encoding_concat_len (head, tail, encoding, max_len));
59 char *result2 = utf8_encoding_trunc (head, encoding, max_len);
60 assert (!strcmp (result, result2));
61 assert (strlen (result2)
62 == utf8_encoding_trunc_len (head, encoding, max_len));
71 usage: %s recode FROM TO STRING\n\
72 where FROM is the source encoding,\n\
73 TO is the target encoding,\n\
74 and STRING is the text to recode.\n\
76 usage: %s concat HEAD TAIL ENCODING MAX_LEN\n\
77 where HEAD is the first string to concatenate\n\
78 TAIL is the second string to concatenate\n\
79 ENCODING is the encoding in which to measure the result's length\n\
80 MAX_LEN is the maximum length of the result in ENCODING.\n",