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