~ubuntu-branches/ubuntu/natty/centerim/natty

« back to all changes in this revision

Viewing changes to intl/localcharset.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-03-26 19:51:53 UTC
  • mfrom: (1.1.5 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090326195153-dxo63t1lwbp2m592
Tags: 4.22.7-1ubuntu1
* Merge from debian unstable, Ubuntu remaining changes:
  - Packages that Depend/Recommend/Suggest firefox (metapackage) must
    must alternatively Depend/Recommend/Suggest abrowser.
* Bugfix-only release, fixed bugs: LP: #146308 and LP: #186381.

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-2006 Free Software Foundation, Inc.
 
3
   Copyright (C) 2000-2004 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
19
19
 
20
20
/* Written by Bruno Haible <bruno@clisp.org>.  */
21
21
 
22
 
#include <config.h>
 
22
#ifdef HAVE_CONFIG_H
 
23
# include <config.h>
 
24
#endif
23
25
 
24
26
/* Specification.  */
25
27
#include "localcharset.h"
26
28
 
27
 
#include <stddef.h>
 
29
#if HAVE_STDDEF_H
 
30
# include <stddef.h>
 
31
#endif
 
32
 
28
33
#include <stdio.h>
29
 
#include <string.h>
30
 
#include <stdlib.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
31
42
 
32
43
#if defined _WIN32 || defined __WIN32__
33
 
# define WIN32_NATIVE
 
44
# undef WIN32   /* avoid warning on mingw32 */
 
45
# define WIN32
34
46
#endif
35
47
 
36
48
#if defined __EMX__
38
50
# define OS2
39
51
#endif
40
52
 
41
 
#if !defined WIN32_NATIVE
 
53
#if !defined WIN32
42
54
# if HAVE_LANGINFO_CODESET
43
55
#  include <langinfo.h>
44
56
# else
45
 
#  if 0 /* see comment below */
 
57
#  if HAVE_SETLOCALE
46
58
#   include <locale.h>
47
59
#  endif
48
60
# endif
49
 
# ifdef __CYGWIN__
50
 
#  define WIN32_LEAN_AND_MEAN
51
 
#  include <windows.h>
52
 
# endif
53
 
#elif defined WIN32_NATIVE
 
61
#elif defined WIN32
54
62
# define WIN32_LEAN_AND_MEAN
55
63
# include <windows.h>
56
64
#endif
65
73
# define relocate(pathname) (pathname)
66
74
#endif
67
75
 
68
 
/* Get LIBDIR.  */
69
 
#ifndef LIBDIR
70
 
# include "configmake.h"
71
 
#endif
72
 
 
73
76
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
74
77
  /* Win32, Cygwin, OS/2, DOS */
75
78
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
104
107
 
105
108
/* Return a pointer to the contents of the charset.alias file.  */
106
109
static const char *
107
 
get_charset_aliases (void)
 
110
get_charset_aliases ()
108
111
{
109
112
  const char *cp;
110
113
 
111
114
  cp = charset_aliases;
112
115
  if (cp == NULL)
113
116
    {
114
 
#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
 
117
#if !(defined VMS || defined WIN32)
115
118
      FILE *fp;
116
119
      const char *dir;
117
120
      const char *base = "charset.alias";
237
240
           "DECKOREAN" "\0" "EUC-KR" "\0";
238
241
# endif
239
242
 
240
 
# if defined WIN32_NATIVE || defined __CYGWIN__
 
243
# if defined WIN32
241
244
      /* To avoid the troubles of installing a separate file in the same
242
245
         directory as the DLL and of retrieving the DLL's directory at
243
246
         runtime, simply inline the aliases here.  */
246
249
           "CP1361" "\0" "JOHAB" "\0"
247
250
           "CP20127" "\0" "ASCII" "\0"
248
251
           "CP20866" "\0" "KOI8-R" "\0"
249
 
           "CP20936" "\0" "GB2312" "\0"
250
252
           "CP21866" "\0" "KOI8-RU" "\0"
251
253
           "CP28591" "\0" "ISO-8859-1" "\0"
252
254
           "CP28592" "\0" "ISO-8859-2" "\0"
257
259
           "CP28597" "\0" "ISO-8859-7" "\0"
258
260
           "CP28598" "\0" "ISO-8859-8" "\0"
259
261
           "CP28599" "\0" "ISO-8859-9" "\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";
 
262
           "CP28605" "\0" "ISO-8859-15" "\0";
268
263
# endif
269
264
#endif
270
265
 
284
279
STATIC
285
280
#endif
286
281
const char *
287
 
locale_charset (void)
 
282
locale_charset ()
288
283
{
289
284
  const char *codeset;
290
285
  const char *aliases;
291
286
 
292
 
#if !(defined WIN32_NATIVE || defined OS2)
 
287
#if !(defined WIN32 || defined OS2)
293
288
 
294
289
# if HAVE_LANGINFO_CODESET
295
290
 
296
291
  /* Most systems support nl_langinfo (CODESET) nowadays.  */
297
292
  codeset = nl_langinfo (CODESET);
298
293
 
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
 
 
346
294
# else
347
295
 
348
296
  /* On old systems which lack it, use setlocale or getenv.  */
352
300
     (like SunOS 4 or DJGPP) have only the C locale.  Therefore we don't
353
301
     use setlocale here; it would return "C" when it doesn't support the
354
302
     locale name the user has set.  */
355
 
#  if 0
 
303
#  if HAVE_SETLOCALE && 0
356
304
  locale = setlocale (LC_CTYPE, NULL);
357
305
#  endif
358
306
  if (locale == NULL || locale[0] == '\0')
373
321
 
374
322
# endif
375
323
 
376
 
#elif defined WIN32_NATIVE
 
324
#elif defined WIN32
377
325
 
378
326
  static char buf[2 + 10 + 1];
379
327