Attachment "langinfo2.diff" to
ticket [418645ffff]
added by
hobbs
2001-11-16 09:41:53.
Index: unix/configure.in
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/configure.in,v
retrieving revision 1.74
diff -b -u -r1.74 configure.in
--- unix/configure.in 2001/11/08 03:07:21 1.74
+++ unix/configure.in 2001/11/16 02:29:16
@@ -339,6 +339,12 @@
fi
#--------------------------------------------------------------------
+# Check for support of nl_langinfo function
+#--------------------------------------------------------------------
+
+SC_ENABLE_LANGINFO
+
+#--------------------------------------------------------------------
# Look for libraries that we will need when compiling the Tcl shell
#--------------------------------------------------------------------
Index: unix/tcl.m4
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tcl.m4,v
retrieving revision 1.49
diff -b -u -r1.49 tcl.m4
--- unix/tcl.m4 2001/11/10 00:57:16 1.49
+++ unix/tcl.m4 2001/11/16 02:29:16
@@ -429,6 +429,51 @@
fi
])
+#------------------------------------------------------------------------
+# SC_ENABLE_LANGINFO --
+#
+# Allows use of modern nl_langinfo check for better l10n.
+# This is only relevant for Unix.
+#
+# Arguments:
+# none
+#
+# Results:
+#
+# Adds the following arguments to configure:
+# --enable-langinfo=yes|no (default is yes)
+#
+# Defines the following vars:
+# HAVE_LANGINFO Triggers use of nl_langinfo if defined.
+#
+#------------------------------------------------------------------------
+
+AC_DEFUN(SC_ENABLE_LANGINFO, [
+ AC_ARG_ENABLE(langinfo,
+ [ --enable-langinfo use nl_langinfo if possible to determine
+ encoding at startup, otherwise use old heuristic],
+ [langinfo_ok=$enableval], [langinfo_ok=yes])
+
+ HAVE_LANGINFO=0
+ if test "$langinfo_ok" = "yes"; then
+ if test "$langinfo_ok" = "yes"; then
+ AC_CHECK_HEADER(langinfo.h,[langinfo_ok=yes],[langinfo_ok=no])
+ fi
+ fi
+ AC_MSG_CHECKING([whether to use nl_langinfo])
+ if test "$langinfo_ok" = "yes"; then
+ AC_TRY_COMPILE([#include <langinfo.h>],
+ [nl_langinfo(CODESET);],[langinfo_ok=yes],[langinfo_ok=no])
+ if test "$langinfo_ok" = "no"; then
+ langinfo_ok="no (could not compile with nl_langinfo)";
+ fi
+ if test "$langinfo_ok" = "yes"; then
+ AC_DEFINE(HAVE_LANGINFO)
+ fi
+ fi
+ AC_MSG_RESULT([$langinfo_ok])
+])
+
#--------------------------------------------------------------------
# SC_CONFIG_CFLAGS
#
@@ -926,7 +971,7 @@
# FreeBSD 3.* and greater have ELF.
SHLIB_CFLAGS="-fPIC"
SHLIB_LD="ld -Bshareable -x"
- SHLIB_LD_LIBS=""
+ SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
DL_OBJS="tclLoadDl.o"
DL_LIBS=""
Index: unix/tclUnixInit.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixInit.c,v
retrieving revision 1.24
diff -b -u -r1.24 tclUnixInit.c
--- unix/tclUnixInit.c 2001/08/27 02:14:08 1.24
+++ unix/tclUnixInit.c 2001/11/16 02:29:16
@@ -13,6 +13,9 @@
#include "tclInt.h"
#include "tclPort.h"
#include <locale.h>
+#ifdef HAVE_LANGINFO
+#include <langinfo.h>
+#endif
#if defined(__FreeBSD__)
# include <floatingpoint.h>
#endif
@@ -49,6 +52,7 @@
static char pkgPath[sizeof(TCL_PACKAGE_PATH)+200] = TCL_PACKAGE_PATH;
+#ifndef HAVE_LANGINFO
/*
* The following table is used to map from Unix locale strings to
* encoding files.
@@ -97,6 +101,7 @@
{NULL, NULL}
};
+#endif /* !HAVE_LANGINFO */
/*
*---------------------------------------------------------------------------
@@ -396,14 +401,57 @@
CONST char *encoding;
int i;
Tcl_Obj *pathPtr;
- char *langEnv;
/*
* Determine the current encoding from the LC_* or LANG environment
* variables. We previously used setlocale() to determine the locale,
* but this does not work on some systems (e.g. Linux/i386 RH 5.0).
*/
+#ifdef HAVE_LANGINFO
+ Tcl_DString ds;
+ setlocale(LC_CTYPE,"");
+ Tcl_DStringInit(&ds);
+ Tcl_DStringAppend(&ds, nl_langinfo(CODESET), -1);
+ encoding = Tcl_DStringValue(&ds);
+
+ Tcl_UtfToLower(Tcl_DStringValue(&ds));
+fprintf(stdout, "found encoding '%.50s' =>", encoding);
+ if (encoding[0] == 'i' && encoding[1] == 's' && encoding[2] == 'o'
+ && encoding[3] == '-') {
+ char *p, *q;
+ /* need to strip extra - from ISO-* encoding */
+ for(p = Tcl_DStringValue(&ds)+3, q = Tcl_DStringValue(&ds)+4; *p;
+ *p++ = *q++);
+ } else if (encoding[0] == 'i' && encoding[1] == 'b'
+ && encoding[2] == 'm' && encoding[3] >= '0'
+ && encoding[3] <= '9') {
+ char *p, *q;
+ /* if langinfo reports IBMxxx we should use cpXXX*/
+ p = Tcl_DStringValue(&ds);
+ *p++='c'; *p++='p';
+ for(q=p+1;*p;*p++= *q++);
+ } else if (!strcmp(encoding, "ansi_x3.4-1968") || *encoding == '\0') {
+ /*
+ * Use iso8859-1 for empty or 'ansi_x3.4-1968' encoding.
+ */
+ Tcl_DStringSetLength(&ds, 0);
+ Tcl_DStringAppend(&ds, "iso8859-1", -1);
+ }
+ if (Tcl_SetSystemEncoding(NULL, encoding) != TCL_OK) {
+ Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
+ if (errChannel) {
+ char msg[100];
+ sprintf(msg, "Couldn't set encoding to '%.50s'\n", encoding);
+ Tcl_Write(errChannel, msg, -1);
+ }
+ encoding = "iso8859-1";
+ Tcl_SetSystemEncoding(NULL, encoding);
+ }
+fprintf(stdout, " '%.50s'\n", encoding);
+ Tcl_DStringFree(&ds);
+#else
+ char *langEnv;
langEnv = getenv("LC_ALL");
if (langEnv == NULL || langEnv[0] == '\0') {
@@ -470,6 +518,7 @@
*/
setlocale(LC_CTYPE, "");
+#endif /* HAVE_LANGINFO */
/*
* In case the initial locale is not "C", ensure that the numeric