1*946379e7Schristos /* Test program, used by the format-c-5 test.
2*946379e7Schristos Copyright (C) 2004, 2006 Free Software Foundation, Inc.
3*946379e7Schristos
4*946379e7Schristos This program is free software; you can redistribute it and/or modify
5*946379e7Schristos it under the terms of the GNU General Public License as published by
6*946379e7Schristos the Free Software Foundation; either version 2, or (at your option)
7*946379e7Schristos any later version.
8*946379e7Schristos
9*946379e7Schristos This program is distributed in the hope that it will be useful,
10*946379e7Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
11*946379e7Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*946379e7Schristos GNU General Public License for more details.
13*946379e7Schristos
14*946379e7Schristos You should have received a copy of the GNU General Public License
15*946379e7Schristos along with this program; if not, write to the Free Software Foundation,
16*946379e7Schristos Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17*946379e7Schristos
18*946379e7Schristos #ifdef HAVE_CONFIG_H
19*946379e7Schristos # include "config.h"
20*946379e7Schristos #endif
21*946379e7Schristos
22*946379e7Schristos #include <locale.h>
23*946379e7Schristos #include <stdio.h>
24*946379e7Schristos #include <stdlib.h>
25*946379e7Schristos #include <string.h>
26*946379e7Schristos #include "xsetenv.h"
27*946379e7Schristos
28*946379e7Schristos /* For %Id to work, we need the real setlocale(), not the fake one. */
29*946379e7Schristos #if !(__GLIBC__ >= 2)
30*946379e7Schristos # include "setlocale.c"
31*946379e7Schristos #endif
32*946379e7Schristos
33*946379e7Schristos /* Make sure we use the included libintl, not the system's one. */
34*946379e7Schristos #undef _LIBINTL_H
35*946379e7Schristos #include "libgnuintl.h"
36*946379e7Schristos
37*946379e7Schristos #define _(string) gettext (string)
38*946379e7Schristos
39*946379e7Schristos int
main(int argc,char * argv[])40*946379e7Schristos main (int argc, char *argv[])
41*946379e7Schristos {
42*946379e7Schristos int n = 5;
43*946379e7Schristos const char *en;
44*946379e7Schristos const char *s;
45*946379e7Schristos const char *expected_translation;
46*946379e7Schristos const char *expected_result;
47*946379e7Schristos char buf[100];
48*946379e7Schristos
49*946379e7Schristos xsetenv ("LC_ALL", argv[1], 1);
50*946379e7Schristos if (setlocale (LC_ALL, "") == NULL)
51*946379e7Schristos /* Couldn't set locale. */
52*946379e7Schristos exit (77);
53*946379e7Schristos
54*946379e7Schristos textdomain ("fc5");
55*946379e7Schristos bindtextdomain ("fc5", ".");
56*946379e7Schristos
57*946379e7Schristos s = gettext ("father of %d children");
58*946379e7Schristos en = "father of %d children";
59*946379e7Schristos #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
60*946379e7Schristos expected_translation = "Vater von %Id Kindern";
61*946379e7Schristos expected_result = "Vater von \xdb\xb5 Kindern";
62*946379e7Schristos #else
63*946379e7Schristos expected_translation = "Vater von %d Kindern";
64*946379e7Schristos expected_result = "Vater von 5 Kindern";
65*946379e7Schristos #endif
66*946379e7Schristos
67*946379e7Schristos if (strcmp (s, en) == 0)
68*946379e7Schristos {
69*946379e7Schristos fprintf (stderr, "String untranslated.\n");
70*946379e7Schristos exit (1);
71*946379e7Schristos }
72*946379e7Schristos if (strcmp (s, expected_translation) != 0)
73*946379e7Schristos {
74*946379e7Schristos fprintf (stderr, "String incorrectly translated.\n");
75*946379e7Schristos exit (1);
76*946379e7Schristos }
77*946379e7Schristos sprintf (buf, s, n);
78*946379e7Schristos if (strcmp (buf, expected_result) != 0)
79*946379e7Schristos {
80*946379e7Schristos fprintf (stderr, "printf of translation wrong.\n");
81*946379e7Schristos exit (1);
82*946379e7Schristos }
83*946379e7Schristos return 0;
84*946379e7Schristos }
85