1 /* Test program, used by the format-c-4 test. 2 Copyright (C) 2002 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 2, or (at your option) 7 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, write to the Free Software Foundation, 16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 17 18 #ifdef HAVE_CONFIG_H 19 # include "config.h" 20 #endif 21 22 #include <locale.h> 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 #ifdef HAVE_INTTYPES_H 27 # include <inttypes.h> 28 #endif 29 #include "xsetenv.h" 30 31 /* Make sure we use the included libintl, not the system's one. */ 32 #undef _LIBINTL_H 33 #include "libgnuintl.h" 34 35 #define _(string) gettext (string) 36 37 /* Fallback definition. */ 38 #if !defined PRId8 || PRI_MACROS_BROKEN 39 # undef PRId8 40 # define PRId8 "d" 41 #endif 42 43 int 44 main (int argc, char *argv[]) 45 { 46 unsigned char n = 5; 47 const char *s; 48 const char *c1; 49 const char *c2; 50 char buf[100]; 51 52 xsetenv ("LC_ALL", argv[1], 1); 53 if (setlocale (LC_ALL, "") == NULL) 54 { 55 fprintf (stderr, "Couldn't set locale.\n"); 56 exit (1); 57 } 58 59 textdomain ("fc4"); 60 bindtextdomain ("fc4", "."); 61 62 s = ngettext ("father of %"PRId8" child", "father of %"PRId8" children", n); 63 c1 = "Vater von %"; c2 = " Kindern"; 64 65 if (!(strlen (s) > strlen (c1) + strlen (c2) 66 && memcmp (s, c1, strlen (c1)) == 0 67 && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0)) 68 { 69 fprintf (stderr, "String not translated.\n"); 70 exit (1); 71 } 72 if (strchr (s, '<') != NULL || strchr (s, '>') != NULL) 73 { 74 fprintf (stderr, "Translation contains <...> markers.\n"); 75 exit (1); 76 } 77 sprintf (buf, s, n); 78 if (strcmp (buf, "Vater von 5 Kindern") != 0) 79 { 80 fprintf (stderr, "printf of translation wrong.\n"); 81 exit (1); 82 } 83 return 0; 84 } 85