1 /* Test program, used by the format-c-3 test.
2 Copyright (C) 2002, 2009, 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 <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_INTTYPES_H
26 # include <inttypes.h>
27 #endif
28
29 #if USE_SYSTEM_LIBINTL
30 # define xsetenv setenv
31 # include <libintl.h>
32 #else
33 # include "xsetenv.h"
34 /* Make sure we use the included libintl, not the system's one. */
35 # undef _LIBINTL_H
36 # include "libgnuintl.h"
37 #endif
38
39 /* Disable the override of setlocale that libgnuintl.h activates on MacOS X
40 and Windows. This test relies on the fake setlocale function in
41 setlocale.c. */
42 #undef setlocale
43 #if defined _WIN32 && !defined __CYGWIN__
44 # define setlocale fake_setlocale
45 extern char *setlocale (int category, SETLOCALE_CONST char *locale);
46 #endif
47
48 #define _(string) gettext (string)
49
50 /* Fallback definition. */
51 #if !defined PRId8
52 # define PRId8 "d"
53 #endif
54
55 int
main(int argc,char * argv[])56 main (int argc, char *argv[])
57 {
58 unsigned char n = 5;
59 const char *s;
60 const char *c1;
61 const char *c2;
62 char buf[100];
63
64 xsetenv ("LC_ALL", argv[1], 1);
65 if (setlocale (LC_ALL, "") == NULL)
66 {
67 fprintf (stderr, "Couldn't set locale.\n");
68 exit (1);
69 }
70
71 textdomain ("fc3");
72 bindtextdomain ("fc3", "fc3-dir");
73
74 s = gettext ("father of %"PRId8" children");
75 c1 = "Vater von %"; c2 = " Kindern";
76
77 if (!(strlen (s) > strlen (c1) + strlen (c2)
78 && memcmp (s, c1, strlen (c1)) == 0
79 && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0))
80 {
81 fprintf (stderr, "String not translated.\n");
82 exit (1);
83 }
84 if (strchr (s, '<') != NULL || strchr (s, '>') != NULL)
85 {
86 fprintf (stderr, "Translation contains <...> markers.\n");
87 exit (1);
88 }
89 sprintf (buf, s, n);
90 if (strcmp (buf, "Vater von 5 Kindern") != 0)
91 {
92 fprintf (stderr, "printf of translation wrong.\n");
93 exit (1);
94 }
95 return 0;
96 }
97