More flexible default encoding

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18612 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 2004-02-18 04:03:24 +00:00
parent 8872fbfe9c
commit 64e9b9289e
5 changed files with 195 additions and 1 deletions

View file

@ -1,3 +1,10 @@
2004-02-17 Bruno Haible <bruno@clisp.org>
* Source/Additions/Unicode.m (GetDefEncoding): Use the result of
nl_langinfo(CODESET) before falling back on ISO-8859-1.
* config/codeset.m4: New file, taken from GNU gettext.
* configure.ac: Include it, and invoke AM_LANGINFO_CODESET.
2004-02-17 David Ayers <d.ayers@inode.at>
* Headers/Foundation/NSLock.h: Make types of _mutex and _condition

View file

@ -46,6 +46,10 @@
#include <stdlib.h>
#include <string.h>
#if HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
typedef struct {unichar from; unsigned char to;} _ucc_;
#include "GNUstepBase/unicode/cyrillic.h"
@ -597,7 +601,103 @@ GetDefEncoding()
if (defEnc == GSUndefinedEncoding)
{
/* Encoding not set */
defEnc = NSISOLatin1StringEncoding;
#if HAVE_LANGINFO_CODESET
/* Take it from the system locale information. */
encoding = nl_langinfo(CODESET);
if (strcmp(encoding, "ANSI_X3.4-1968") == 0 /* glibc */
|| strcmp(encoding, "ISO_646.IRV:1983") == 0 /* glibc */
|| strcmp(encoding, "646") == 0 /* Solaris NetBSD */)
defEnc = NSASCIIStringEncoding;
else if (strcmp(encoding, "EUC-JP") == 0 /* glibc */
|| strcmp(encoding, "eucJP") == 0 /* HP-UX IRIX OSF/1 Solaris NetBSD */
|| strcmp(encoding, "IBM-eucJP") == 0 /* AIX */)
defEnc = NSJapaneseEUCStringEncoding;
else if (strcmp(encoding, "UTF-8") == 0 /* glibc AIX OSF/1 Solaris */
|| strcmp(encoding, "utf8") == 0 /* HP-UX */)
defEnc = NSUTF8StringEncoding;
else if (strcmp(encoding, "ISO-8859-1") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-1") == 0 /* AIX IRIX OSF/1 Solaris NetBSD */
|| strcmp(encoding, "iso88591") == 0 /* HP-UX */)
defEnc = NSISOLatin1StringEncoding;
else if (strcmp(encoding, "IBM-932") == 0 /* AIX */
|| strcmp(encoding, "SJIS") == 0 /* HP-UX OSF/1 NetBSD */
|| strcmp(encoding, "PCK") == 0 /* Solaris */)
defEnc = NSShiftJISStringEncoding;
else if (strcmp(encoding, "ISO-8859-2") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-2") == 0 /* AIX IRIX OSF/1 Solaris NetBSD */
|| strcmp(encoding, "iso88592") == 0 /* HP-UX */)
defEnc = NSISOLatin2StringEncoding;
else if (strcmp(encoding, "CP1251") == 0 /* glibc */
|| strcmp(encoding, "ansi-1251") == 0 /* Solaris */)
defEnc = NSWindowsCP1251StringEncoding;
else if (strcmp(encoding, "CP1252") == 0 /* */
|| strcmp(encoding, "IBM-1252") == 0 /* AIX */)
defEnc = NSWindowsCP1252StringEncoding;
else if (strcmp(encoding, "ISO-8859-5") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-5") == 0 /* AIX IRIX OSF/1 Solaris NetBSD */
|| strcmp(encoding, "iso88595") == 0 /* HP-UX */)
defEnc = NSISOCyrillicStringEncoding;
else if (strcmp(encoding, "KOI8-R") == 0 /* glibc */
|| strcmp(encoding, "koi8-r") == 0 /* Solaris */)
defEnc = NSKOI8RStringEncoding;
else if (strcmp(encoding, "ISO-8859-3") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-3") == 0 /* Solaris */)
defEnc = NSISOLatin3StringEncoding;
else if (strcmp(encoding, "ISO-8859-4") == 0 /* */
|| strcmp(encoding, "ISO8859-4") == 0 /* OSF/1 Solaris NetBSD */)
defEnc = NSISOLatin4StringEncoding;
else if (strcmp(encoding, "ISO-8859-6") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-6") == 0 /* AIX Solaris */
|| strcmp(encoding, "iso88596") == 0 /* HP-UX */)
defEnc = NSISOArabicStringEncoding;
else if (strcmp(encoding, "ISO-8859-7") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-7") == 0 /* AIX IRIX OSF/1 Solaris */
|| strcmp(encoding, "iso88597") == 0 /* HP-UX */)
defEnc = NSISOGreekStringEncoding;
else if (strcmp(encoding, "ISO-8859-8") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-8") == 0 /* AIX OSF/1 Solaris */
|| strcmp(encoding, "iso88598") == 0 /* HP-UX */)
defEnc = NSISOHebrewStringEncoding;
else if (strcmp(encoding, "ISO-8859-9") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-9") == 0 /* AIX IRIX OSF/1 Solaris */
|| strcmp(encoding, "iso88599") == 0 /* HP-UX */)
defEnc = NSISOLatin5StringEncoding;
else if (strcmp(encoding, "ISO-8859-10") == 0 /* */
|| strcmp(encoding, "ISO8859-10") == 0 /* */)
defEnc = NSISOLatin6StringEncoding;
else if (strcmp(encoding, "TIS-620") == 0 /* glibc AIX */
|| strcmp(encoding, "tis620") == 0 /* HP-UX */
|| strcmp(encoding, "TIS620.2533") == 0 /* Solaris */
|| strcmp(encoding, "TACTIS") == 0 /* OSF/1 */)
defEnc = NSISOThaiStringEncoding;
else if (strcmp(encoding, "ISO-8859-13") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-13") == 0 /* */
|| strcmp(encoding, "IBM-921") == 0 /* AIX */)
defEnc = NSISOLatin7StringEncoding;
else if (strcmp(encoding, "ISO-8859-14") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-14") == 0 /* */)
defEnc = NSISOLatin8StringEncoding;
else if (strcmp(encoding, "ISO-8859-15") == 0 /* glibc */
|| strcmp(encoding, "ISO8859-15") == 0 /* AIX OSF/1 Solaris NetBSD */
|| strcmp(encoding, "iso885915") == 0 /* HP-UX */)
defEnc = NSISOLatin9StringEncoding;
else if (strcmp(encoding, "GB2312") == 0 /* glibc */
|| strcmp(encoding, "gb2312") == 0 /* Solaris */
|| strcmp(encoding, "eucCN") == 0 /* IRIX NetBSD */
|| strcmp(encoding, "IBM-eucCN") == 0 /* AIX */
|| strcmp(encoding, "hp15CN") == 0 /* HP-UX */)
defEnc = NSGB2312StringEncoding;
else if (strcmp(encoding, "BIG5") == 0 /* glibc Solaris NetBSD */
|| strcmp(encoding, "big5") == 0 /* AIX HP-UX OSF/1 */)
defEnc = NSBIG5StringEncoding;
else if (strcmp(encoding, "EUC-KR") == 0 /* glibc */
|| strcmp(encoding, "eucKR") == 0 /* HP-UX IRIX OSF/1 NetBSD */
|| strcmp(encoding, "IBM-eucKR") == 0 /* AIX */
|| strcmp(encoding, "5601") == 0 /* Solaris */)
defEnc = NSKoreanEUCEncoding;
else
#endif
defEnc = NSISOLatin1StringEncoding;
}
else if (GSEncodingSupported(defEnc) == NO)
{

23
config/codeset.m4 Normal file
View file

@ -0,0 +1,23 @@
# codeset.m4 serial AM1 (gettext-0.10.40)
dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
dnl From Bruno Haible.
AC_DEFUN([AM_LANGINFO_CODESET],
[
AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset,
[AC_TRY_LINK([#include <langinfo.h>],
[char* cs = nl_langinfo(CODESET);],
am_cv_langinfo_codeset=yes,
am_cv_langinfo_codeset=no)
])
if test $am_cv_langinfo_codeset = yes; then
AC_DEFINE(HAVE_LANGINFO_CODESET, 1,
[Define if you have <langinfo.h> and nl_langinfo(CODESET).])
fi
])

58
configure vendored
View file

@ -13285,6 +13285,64 @@ if test "$USE_GMP" = "0"; then
fi
#--------------------------------------------------------------------
# Check whether nl_langinfo(CODESET) is supported, needed by Unicode.m.
#--------------------------------------------------------------------
echo "$as_me:$LINENO: checking for nl_langinfo and CODESET" >&5
echo $ECHO_N "checking for nl_langinfo and CODESET... $ECHO_C" >&6
if test "${am_cv_langinfo_codeset+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <langinfo.h>
int
main ()
{
char* cs = nl_langinfo(CODESET);
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
am_cv_langinfo_codeset=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
am_cv_langinfo_codeset=no
fi
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: $am_cv_langinfo_codeset" >&5
echo "${ECHO_T}$am_cv_langinfo_codeset" >&6
if test $am_cv_langinfo_codeset = yes; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_LANGINFO_CODESET 1
_ACEOF
fi
#--------------------------------------------------------------------
# Check for iconv support (for Unicode conversion).
#--------------------------------------------------------------------

View file

@ -26,6 +26,7 @@ builtin(include, config/objc-sys-dynamic.m4)dnl
builtin(include, config/procfs-exe-link.m4)dnl
builtin(include, config/procfs.m4)dnl
builtin(include, config/pathxml.m4)dnl
builtin(include, config/codeset.m4)dnl
AC_INIT
AC_CONFIG_SRCDIR([Source/NSArray.m])
@ -1042,6 +1043,11 @@ if test "$USE_GMP" = "0"; then
fi
AC_SUBST(USE_GMP)
#--------------------------------------------------------------------
# Check whether nl_langinfo(CODESET) is supported, needed by Unicode.m.
#--------------------------------------------------------------------
AM_LANGINFO_CODESET
#--------------------------------------------------------------------
# Check for iconv support (for Unicode conversion).
#--------------------------------------------------------------------