From 1c08859b486db8ce18311bb05901b3f583154e5c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 22 Jul 2006 14:11:57 +0000 Subject: [PATCH] Update localcharset module from GNU gettext. --- lib/ChangeLog | 21 +++++++++++++++ lib/config.charset | 44 ++++++++++++++++--------------- lib/localcharset.c | 66 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 102 insertions(+), 29 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 84e5b417b9..810daab552 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,24 @@ +2006-06-17 Bruno Haible + + * config.charset: Update for NetBSD 3.0. + +2006-05-17 Bruno Haible + + Cygwin portability. + * localcharset.c (WIN32_NATIVE): Renamed from WIN32. + +2006-05-16 Bruno Haible + + * localcharset.c [CYGWIN]: Include . + (get_charset_aliases): For Cygwin, return the same CPxxx aliases list + as under WIN32. + (locale_charset) [CYGWIN]: Try to retrieve the encoding from the + environment variables. Fall back to GetACP(). + +2006-04-05 Bruno Haible + + * config.charset: Update Juan Manuel Guerrero's address. + 2005-02-12 Bruno Haible * allocsa.h: Add extern "C" for C++. diff --git a/lib/config.charset b/lib/config.charset index 98294583db..148ea441fa 100755 --- a/lib/config.charset +++ b/lib/config.charset @@ -1,7 +1,7 @@ #! /bin/sh # Output a system dependent table of character encoding aliases. # -# Copyright (C) 2000-2004 Free Software Foundation, Inc. +# Copyright (C) 2000-2004, 2006 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,21 +30,21 @@ # The current list of GNU canonical charset names is as follows. # # name MIME? used by which systems -# ASCII, ANSI_X3.4-1968 glibc solaris freebsd darwin -# ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd darwin -# ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd darwin +# ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin +# ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd darwin +# ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd darwin # ISO-8859-3 Y glibc solaris -# ISO-8859-4 Y osf solaris freebsd darwin -# ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd darwin +# ISO-8859-4 Y osf solaris freebsd netbsd darwin +# ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd darwin # ISO-8859-6 Y glibc aix hpux solaris -# ISO-8859-7 Y glibc aix hpux irix osf solaris darwin +# ISO-8859-7 Y glibc aix hpux irix osf solaris netbsd darwin # ISO-8859-8 Y glibc aix hpux osf solaris # ISO-8859-9 Y glibc aix hpux irix osf solaris darwin -# ISO-8859-13 glibc darwin +# ISO-8859-13 glibc netbsd darwin # ISO-8859-14 glibc # ISO-8859-15 glibc aix osf solaris freebsd darwin -# KOI8-R Y glibc solaris freebsd darwin -# KOI8-U Y glibc freebsd darwin +# KOI8-R Y glibc solaris freebsd netbsd darwin +# KOI8-U Y glibc freebsd netbsd darwin # KOI8-T glibc # CP437 dos # CP775 dos @@ -57,7 +57,7 @@ # CP862 dos # CP864 dos # CP865 dos -# CP866 freebsd darwin dos +# CP866 freebsd netbsd darwin dos # CP869 dos # CP874 woe32 dos # CP922 aix @@ -70,22 +70,22 @@ # CP1125 dos # CP1129 aix # CP1250 woe32 -# CP1251 glibc solaris darwin woe32 +# CP1251 glibc solaris netbsd darwin woe32 # CP1252 aix woe32 # CP1253 woe32 # CP1254 woe32 # CP1255 glibc woe32 # CP1256 woe32 # CP1257 woe32 -# GB2312 Y glibc aix hpux irix solaris freebsd darwin -# EUC-JP Y glibc aix hpux irix osf solaris freebsd darwin -# EUC-KR Y glibc aix hpux irix osf solaris freebsd darwin -# EUC-TW glibc aix hpux irix osf solaris -# BIG5 Y glibc aix hpux osf solaris freebsd darwin +# GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin +# EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin +# EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin +# EUC-TW glibc aix hpux irix osf solaris netbsd +# BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin # BIG5-HKSCS glibc solaris # GBK glibc aix osf solaris woe32 dos -# GB18030 glibc solaris -# SHIFT_JIS Y hpux osf solaris freebsd darwin +# GB18030 glibc solaris netbsd +# SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin # JOHAB glibc solaris woe32 # TIS-620 glibc aix hpux osf solaris # VISCII Y glibc @@ -99,7 +99,7 @@ # HP-KANA8 hpux # DEC-KANJI osf # DEC-HANYU osf -# UTF-8 Y glibc aix hpux osf solaris darwin +# UTF-8 Y glibc aix hpux osf solaris netbsd darwin # # Note: Names which are not marked as being a MIME name should not be used in # Internet protocols for information interchange (mail, news, etc.). @@ -387,6 +387,8 @@ case "$os" in echo "ISO8859-2 ISO-8859-2" echo "ISO8859-4 ISO-8859-4" echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-13 ISO-8859-13" echo "ISO8859-15 ISO-8859-15" echo "eucCN GB2312" echo "eucJP EUC-JP" @@ -479,7 +481,7 @@ case "$os" in echo "# If you find that the encoding given for your language and" echo "# country is not the one your DOS machine actually uses, just" echo "# correct it in this file, and send a mail to" - echo "# Juan Manuel Guerrero " + echo "# Juan Manuel Guerrero " echo "# and Bruno Haible ." echo "#" echo "C ASCII" diff --git a/lib/localcharset.c b/lib/localcharset.c index d03ab79d07..08daf7353a 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -40,8 +40,7 @@ #endif #if defined _WIN32 || defined __WIN32__ -# undef WIN32 /* avoid warning on mingw32 */ -# define WIN32 +# define WIN32_NATIVE #endif #if defined __EMX__ @@ -49,7 +48,7 @@ # define OS2 #endif -#if !defined WIN32 +#if !defined WIN32_NATIVE # if HAVE_LANGINFO_CODESET # include # else @@ -57,7 +56,11 @@ # include # endif # endif -#elif defined WIN32 +# ifdef __CYGWIN__ +# define WIN32_LEAN_AND_MEAN +# include +# endif +#elif defined WIN32_NATIVE # define WIN32_LEAN_AND_MEAN # include #endif @@ -113,7 +116,7 @@ get_charset_aliases (void) cp = charset_aliases; if (cp == NULL) { -#if !(defined VMS || defined WIN32) +#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__) FILE *fp; const char *dir; const char *base = "charset.alias"; @@ -239,7 +242,7 @@ get_charset_aliases (void) "DECKOREAN" "\0" "EUC-KR" "\0"; # endif -# if defined WIN32 +# if defined WIN32_NATIVE || defined __CYGWIN__ /* To avoid the troubles of installing a separate file in the same directory as the DLL and of retrieving the DLL's directory at runtime, simply inline the aliases here. */ @@ -291,13 +294,60 @@ locale_charset (void) const char *codeset; const char *aliases; -#if !(defined WIN32 || defined OS2) +#if !(defined WIN32_NATIVE || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo (CODESET) nowadays. */ codeset = nl_langinfo (CODESET); +# ifdef __CYGWIN__ + /* Cygwin 2006 does not have locales. nl_langinfo (CODESET) always + returns "US-ASCII". As long as this is not fixed, return the suffix + of the locale name from the environment variables (if present) or + the codepage as a number. */ + if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) + { + const char *locale; + static char buf[2 + 10 + 1]; + + locale = getenv ("LC_ALL"); + if (locale == NULL || locale[0] == '\0') + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } + if (locale != NULL && locale[0] != '\0') + { + /* If the locale name contains an encoding after the dot, return + it. */ + const char *dot = strchr (locale, '.'); + + if (dot != NULL) + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } + } + + /* Woe32 has a function returning the locale's codepage as a number. */ + sprintf (buf, "CP%u", GetACP ()); + codeset = buf; + } +# endif + # else /* On old systems which lack it, use setlocale or getenv. */ @@ -328,7 +378,7 @@ locale_charset (void) # endif -#elif defined WIN32 +#elif defined WIN32_NATIVE static char buf[2 + 10 + 1]; -- 2.30.2