(root)/
gettext-0.22.4/
gettext-tools/
tests/
intl-6-prg.c
       1  /* Test program, used by the intl-6 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 *dir = argv[1];
      48    const char *locale = argv[2];
      49    wchar_t *wdir;
      50    int ret;
      51  
      52    /* Clean up environment.  */
      53    unsetenv ("LANGUAGE");
      54    unsetenv ("OUTPUT_CHARSET");
      55  
      56    xsetenv ("LC_ALL", locale, 1);
      57    if (setlocale (LC_ALL, "") == NULL)
      58      setlocale (LC_ALL, "C");
      59  
      60    /* Set up translation domain.  */
      61  
      62    wdir = (wchar_t *) malloc ((strlen (dir) + 1) * sizeof (wchar_t));
      63    mbstowcs (wdir, dir, strlen (dir) + 1);
      64  
      65    /* Rename the directory.  */
      66  #if defined _WIN32 && !defined __CYGWIN__
      67    ret = _wrename (wdir, wunicodedir);
      68  #else
      69    ret = rename (dir, unicodedir);
      70  #endif
      71    if (ret != 0)
      72      {
      73        fprintf (stderr, "Initial rename failed.\n");
      74        exit (1);
      75      }
      76  
      77    textdomain ("tstprog");
      78  
      79  #if defined _WIN32 && !defined __CYGWIN__
      80    wbindtextdomain ("tstprog", wunicodedir);
      81  #else
      82    bindtextdomain ("tstprog", unicodedir);
      83  #endif
      84  
      85    /* Look up the translation.  */
      86    printf ("%s\n", gettext ("cheese"));
      87  
      88    /* Rename the directory back.  */
      89  #if defined _WIN32 && !defined __CYGWIN__
      90    ret = _wrename (wunicodedir, wdir);
      91  #else
      92    ret = rename (unicodedir, dir);
      93  #endif
      94    if (ret != 0)
      95      {
      96        fprintf (stderr, "Final rename failed.\n");
      97        exit (1);
      98      }
      99  
     100    return 0;
     101  }