1 /* Test program, used by the intl-6 test.
2 Copyright (C) 2000, 2005, 2007, 2013, 2018, 2020 Free Software Foundation, Inc.
3
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.
8
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.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20
21 #include <locale.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #if defined _WIN32 && !defined __CYGWIN__
26 # include <wchar.h>
27 #endif
28
29 #include "xsetenv.h"
30 /* Make sure we use the included libintl, not the system's one. */
31 #undef _LIBINTL_H
32 #include "libgnuintl.h"
33
34 const char unicodedir[] = "русский…日本語…हिंदी…";
35 #if defined _WIN32 && !defined __CYGWIN__
36 const wchar_t wunicodedir[] = /* the same string in UTF-16 encoding */
37 { 0x0440, 0x0443, 0x0441, 0x0441, 0x043A, 0x0438, 0x0439, 0x2026,
38 0x65E5, 0x672C, 0x8A9E, 0x2026,
39 0x0939, 0x093F, 0x0902, 0x0926, 0x0940, 0x2026,
40 0xD83D, 0xDE37, 0
41 };
42 #endif
43
44 int
main(int argc,char * argv[])45 main (int argc, char *argv[])
46 {
47 const char *dir = argv[1];
48 const char *locale = argv[2];
49 wchar_t *wdir;
50 int ret;
51
52 wdir = (wchar_t *) malloc ((strlen (dir) + 1) * sizeof (wchar_t));
53 mbstowcs (wdir, dir, strlen (dir) + 1);
54
55 /* Rename the directory. */
56 #if defined _WIN32 && !defined __CYGWIN__
57 ret = _wrename (wdir, wunicodedir);
58 #else
59 ret = rename (dir, unicodedir);
60 #endif
61 if (ret != 0)
62 {
63 fprintf (stderr, "Initial rename failed.\n");
64 exit (1);
65 }
66
67 /* Clean up environment. */
68 unsetenv ("LANGUAGE");
69 unsetenv ("OUTPUT_CHARSET");
70
71 textdomain ("tstprog");
72
73 xsetenv ("LC_ALL", locale, 1);
74 if (setlocale (LC_ALL, "") == NULL)
75 setlocale (LC_ALL, "C");
76
77 #if defined _WIN32 && !defined __CYGWIN__
78 wbindtextdomain ("tstprog", wunicodedir);
79 #else
80 bindtextdomain ("tstprog", unicodedir);
81 #endif
82
83 printf ("%s\n", gettext ("cheese"));
84
85 /* Rename the directory back. */
86 #if defined _WIN32 && !defined __CYGWIN__
87 ret = _wrename (wunicodedir, wdir);
88 #else
89 ret = rename (unicodedir, dir);
90 #endif
91 if (ret != 0)
92 {
93 fprintf (stderr, "Final rename failed.\n");
94 exit (1);
95 }
96
97 return 0;
98 }
99