~ubuntu-branches/ubuntu/saucy/m17n-lib/saucy

« back to all changes in this revision

Viewing changes to intl/localcharset.c

  • Committer: Bazaar Package Importer
  • Author(s): Harshula Jayasuriya
  • Date: 2010-11-23 01:39:29 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101123013929-rs3kpqgu4kr3qx32
Tags: 1.6.2-1
* New upstream release 1.6.2.
* Update Standards-Version to Debian Policy 3.9.1. (No changes)
* debian/control: Depends: m17n-db and m17n-contrib. (Closes: #599643)
* PATCH: (make_locale): Don't call setlocale.  Just parse the arg NAME.
         (Closes: #601858)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Determine a canonical name for the current locale's character encoding.
2
2
 
3
 
   Copyright (C) 2000-2004 Free Software Foundation, Inc.
 
3
   Copyright (C) 2000-2006 Free Software Foundation, Inc.
4
4
 
5
5
   This program is free software; you can redistribute it and/or modify it
6
6
   under the terms of the GNU Library General Public License as published
14
14
 
15
15
   You should have received a copy of the GNU Library General Public
16
16
   License along with this program; if not, write to the Free Software
17
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
17
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18
18
   USA.  */
19
19
 
20
20
/* Written by Bruno Haible <bruno@clisp.org>.  */
21
21
 
22
 
#ifdef HAVE_CONFIG_H
23
 
# include <config.h>
24
 
#endif
 
22
#include <config.h>
25
23
 
26
24
/* Specification.  */
27
25
#include "localcharset.h"
28
26
 
29
 
#if HAVE_STDDEF_H
30
 
# include <stddef.h>
31
 
#endif
32
 
 
 
27
#include <stddef.h>
33
28
#include <stdio.h>
34
 
#if HAVE_STRING_H
35
 
# include <string.h>
36
 
#else
37
 
# include <strings.h>
38
 
#endif
39
 
#if HAVE_STDLIB_H
40
 
# include <stdlib.h>
41
 
#endif
 
29
#include <string.h>
 
30
#include <stdlib.h>
42
31
 
43
32
#if defined _WIN32 || defined __WIN32__
44
 
# undef WIN32   /* avoid warning on mingw32 */
45
 
# define WIN32
 
33
# define WIN32_NATIVE
46
34
#endif
47
35
 
48
36
#if defined __EMX__
50
38
# define OS2
51
39
#endif
52
40
 
53
 
#if !defined WIN32
 
41
#if !defined WIN32_NATIVE
54
42
# if HAVE_LANGINFO_CODESET
55
43
#  include <langinfo.h>
56
44
# else
57
 
#  if HAVE_SETLOCALE
 
45
#  if 0 /* see comment below */
58
46
#   include <locale.h>
59
47
#  endif
60
48
# endif
61
 
#elif defined WIN32
 
49
# ifdef __CYGWIN__
 
50
#  define WIN32_LEAN_AND_MEAN
 
51
#  include <windows.h>
 
52
# endif
 
53
#elif defined WIN32_NATIVE
62
54
# define WIN32_LEAN_AND_MEAN
63
55
# include <windows.h>
64
56
#endif
73
65
# define relocate(pathname) (pathname)
74
66
#endif
75
67
 
 
68
/* Get LIBDIR.  */
 
69
#ifndef LIBDIR
 
70
# include "configmake.h"
 
71
#endif
 
72
 
76
73
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
77
74
  /* Win32, Cygwin, OS/2, DOS */
78
75
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
107
104
 
108
105
/* Return a pointer to the contents of the charset.alias file.  */
109
106
static const char *
110
 
get_charset_aliases ()
 
107
get_charset_aliases (void)
111
108
{
112
109
  const char *cp;
113
110
 
114
111
  cp = charset_aliases;
115
112
  if (cp == NULL)
116
113
    {
117
 
#if !(defined VMS || defined WIN32)
 
114
#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
118
115
      FILE *fp;
119
116
      const char *dir;
120
117
      const char *base = "charset.alias";
240
237
           "DECKOREAN" "\0" "EUC-KR" "\0";
241
238
# endif
242
239
 
243
 
# if defined WIN32
 
240
# if defined WIN32_NATIVE || defined __CYGWIN__
244
241
      /* To avoid the troubles of installing a separate file in the same
245
242
         directory as the DLL and of retrieving the DLL's directory at
246
243
         runtime, simply inline the aliases here.  */
249
246
           "CP1361" "\0" "JOHAB" "\0"
250
247
           "CP20127" "\0" "ASCII" "\0"
251
248
           "CP20866" "\0" "KOI8-R" "\0"
 
249
           "CP20936" "\0" "GB2312" "\0"
252
250
           "CP21866" "\0" "KOI8-RU" "\0"
253
251
           "CP28591" "\0" "ISO-8859-1" "\0"
254
252
           "CP28592" "\0" "ISO-8859-2" "\0"
259
257
           "CP28597" "\0" "ISO-8859-7" "\0"
260
258
           "CP28598" "\0" "ISO-8859-8" "\0"
261
259
           "CP28599" "\0" "ISO-8859-9" "\0"
262
 
           "CP28605" "\0" "ISO-8859-15" "\0";
 
260
           "CP28605" "\0" "ISO-8859-15" "\0"
 
261
           "CP38598" "\0" "ISO-8859-8" "\0"
 
262
           "CP51932" "\0" "EUC-JP" "\0"
 
263
           "CP51936" "\0" "GB2312" "\0"
 
264
           "CP51949" "\0" "EUC-KR" "\0"
 
265
           "CP51950" "\0" "EUC-TW" "\0"
 
266
           "CP54936" "\0" "GB18030" "\0"
 
267
           "CP65001" "\0" "UTF-8" "\0";
263
268
# endif
264
269
#endif
265
270
 
279
284
STATIC
280
285
#endif
281
286
const char *
282
 
locale_charset ()
 
287
locale_charset (void)
283
288
{
284
289
  const char *codeset;
285
290
  const char *aliases;
286
291
 
287
 
#if !(defined WIN32 || defined OS2)
 
292
#if !(defined WIN32_NATIVE || defined OS2)
288
293
 
289
294
# if HAVE_LANGINFO_CODESET
290
295
 
291
296
  /* Most systems support nl_langinfo (CODESET) nowadays.  */
292
297
  codeset = nl_langinfo (CODESET);
293
298
 
 
299
#  ifdef __CYGWIN__
 
300
  /* Cygwin 2006 does not have locales.  nl_langinfo (CODESET) always
 
301
     returns "US-ASCII".  As long as this is not fixed, return the suffix
 
302
     of the locale name from the environment variables (if present) or
 
303
     the codepage as a number.  */
 
304
  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
 
305
    {
 
306
      const char *locale;
 
307
      static char buf[2 + 10 + 1];
 
308
 
 
309
      locale = getenv ("LC_ALL");
 
310
      if (locale == NULL || locale[0] == '\0')
 
311
        {
 
312
          locale = getenv ("LC_CTYPE");
 
313
          if (locale == NULL || locale[0] == '\0')
 
314
            locale = getenv ("LANG");
 
315
        }
 
316
      if (locale != NULL && locale[0] != '\0')
 
317
        {
 
318
          /* If the locale name contains an encoding after the dot, return
 
319
             it.  */
 
320
          const char *dot = strchr (locale, '.');
 
321
 
 
322
          if (dot != NULL)
 
323
            {
 
324
              const char *modifier;
 
325
 
 
326
              dot++;
 
327
              /* Look for the possible @... trailer and remove it, if any.  */
 
328
              modifier = strchr (dot, '@');
 
329
              if (modifier == NULL)
 
330
                return dot;
 
331
              if (modifier - dot < sizeof (buf))
 
332
                {
 
333
                  memcpy (buf, dot, modifier - dot);
 
334
                  buf [modifier - dot] = '\0';
 
335
                  return buf;
 
336
                }
 
337
            }
 
338
        }
 
339
 
 
340
      /* Woe32 has a function returning the locale's codepage as a number.  */
 
341
      sprintf (buf, "CP%u", GetACP ());
 
342
      codeset = buf;
 
343
    }
 
344
#  endif
 
345
 
294
346
# else
295
347
 
296
348
  /* On old systems which lack it, use setlocale or getenv.  */
300
352
     (like SunOS 4 or DJGPP) have only the C locale.  Therefore we don't
301
353
     use setlocale here; it would return "C" when it doesn't support the
302
354
     locale name the user has set.  */
303
 
#  if HAVE_SETLOCALE && 0
 
355
#  if 0
304
356
  locale = setlocale (LC_CTYPE, NULL);
305
357
#  endif
306
358
  if (locale == NULL || locale[0] == '\0')
321
373
 
322
374
# endif
323
375
 
324
 
#elif defined WIN32
 
376
#elif defined WIN32_NATIVE
325
377
 
326
378
  static char buf[2 + 10 + 1];
327
379