(root)/
gettext-0.22.4/
gettext-tools/
tests/
intl-7-prg.c
       1  /* Test program, used by the intl-7 test.
       2     Copyright (C) 2000, 2005, 2007, 2013, 2018, 2020, 2023 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 <stdlib.h>
      23  #include <stdio.h>
      24  #include <string.h>
      25  #if defined _WIN32 && !defined __CYGWIN__
      26  # include <wchar.h>
      27  #endif
      28  
      29  #include "xsetenv.h"
      30  /* Make sure we use the included libintl, not the system's one. */
      31  #undef _LIBINTL_H
      32  #include "libgnuintl.h"
      33  
      34  const char unicodedir[] = "русский…日本語…हिंदी…😷";
      35  #if defined _WIN32 && !defined __CYGWIN__
      36  const wchar_t wunicodedir[] = /* the same string in UTF-16 encoding */
      37    { 0x0440, 0x0443, 0x0441, 0x0441, 0x043A, 0x0438, 0x0439, 0x2026,
      38      0x65E5, 0x672C, 0x8A9E, 0x2026,
      39      0x0939, 0x093F, 0x0902, 0x0926, 0x0940, 0x2026,
      40      0xD83D, 0xDE37, 0
      41    };
      42  #endif
      43  
      44  int
      45  main (int argc, char *argv[])
      46  {
      47    const char *lib_dir = argv[1];
      48    const char *dir = argv[2];
      49    const char *locale = argv[3];
      50    wchar_t *wdir;
      51    int ret;
      52  
      53    /* Clean up environment.  */
      54    unsetenv ("LANGUAGE");
      55    unsetenv ("OUTPUT_CHARSET");
      56  
      57    xsetenv ("LC_ALL", locale, 1);
      58    if (setlocale (LC_ALL, "") == NULL)
      59      setlocale (LC_ALL, "C");
      60  
      61    /* Set up translation domains.  */
      62  
      63    bindtextdomain ("tstlib", lib_dir);
      64  
      65    wdir = (wchar_t *) malloc ((strlen (dir) + 1) * sizeof (wchar_t));
      66    mbstowcs (wdir, dir, strlen (dir) + 1);
      67  
      68    /* Rename the directory.  */
      69  #if defined _WIN32 && !defined __CYGWIN__
      70    ret = _wrename (wdir, wunicodedir);
      71  #else
      72    ret = rename (dir, unicodedir);
      73  #endif
      74    if (ret != 0)
      75      {
      76        fprintf (stderr, "Initial rename failed.\n");
      77        exit (1);
      78      }
      79  
      80  #if defined _WIN32 && !defined __CYGWIN__
      81    wbindtextdomain ("tstbar", wunicodedir);
      82    wbindtextdomain ("tstfoo", wunicodedir);
      83  #else
      84    bindtextdomain ("tstbar", unicodedir);
      85    bindtextdomain ("tstfoo", unicodedir);
      86  #endif
      87  
      88    /* Look up the translations.  */
      89    printf ("%s\n", dgettext ("tstlib", "dog"));
      90    printf ("%s\n", dgettext ("tstbar", "jam"));
      91    printf ("%s\n", dgettext ("tstfoo", "cheese"));
      92  
      93    /* Rename the directory back.  */
      94  #if defined _WIN32 && !defined __CYGWIN__
      95    ret = _wrename (wunicodedir, wdir);
      96  #else
      97    ret = rename (unicodedir, dir);
      98  #endif
      99    if (ret != 0)
     100      {
     101        fprintf (stderr, "Final rename failed.\n");
     102        exit (1);
     103      }
     104  
     105    return 0;
     106  }