1 /* Test program, used by the format-c-5 test.
2 Copyright (C) 2004, 2006, 2010, 2018 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 <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 /* For %Id to work, we need the real setlocale(), not the fake one. */
27 #if !USE_SYSTEM_LIBINTL && !(__GLIBC__ >= 2 && !defined __UCLIBC__)
28 # include "setlocale.c"
29 #endif
30
31 #if USE_SYSTEM_LIBINTL
32 # define xsetenv setenv
33 # include <libintl.h>
34 #else
35 # include "xsetenv.h"
36 /* Make sure we use the included libintl, not the system's one. */
37 # undef _LIBINTL_H
38 # include "libgnuintl.h"
39 #endif
40
41 #define _(string) gettext (string)
42
43 int
main(int argc,char * argv[])44 main (int argc, char *argv[])
45 {
46 int n = 5;
47 const char *en;
48 const char *s;
49 const char *expected_translation;
50 const char *expected_result;
51 char buf[100];
52
53 xsetenv ("LC_ALL", argv[1], 1);
54 if (setlocale (LC_ALL, "") == NULL)
55 /* Couldn't set locale. */
56 exit (77);
57
58 textdomain ("fc5");
59 bindtextdomain ("fc5", ".");
60
61 s = gettext ("father of %d children");
62 en = "father of %d children";
63 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__
64 expected_translation = "Vater von %Id Kindern";
65 expected_result = "Vater von \xdb\xb5 Kindern";
66 #else
67 expected_translation = "Vater von %d Kindern";
68 expected_result = "Vater von 5 Kindern";
69 #endif
70
71 if (strcmp (s, en) == 0)
72 {
73 fprintf (stderr, "String untranslated.\n");
74 exit (1);
75 }
76 if (strcmp (s, expected_translation) != 0)
77 {
78 fprintf (stderr, "String incorrectly translated.\n");
79 exit (1);
80 }
81 sprintf (buf, s, n);
82 if (strcmp (buf, expected_result) != 0)
83 {
84 fprintf (stderr, "printf of translation wrong.\n");
85 exit (1);
86 }
87 return 0;
88 }
89