Tcl Source Code

Artifact [dbc66fa117]
Login

Artifact dbc66fa11733033cac8e3b2ee950b379792bd6c0:

Attachment "langinfo.patch" to ticket [418645ffff] added by hobbs 2001-11-07 09:42:06.
--- tcl/unix/configure.in.orig	Sat Nov  3 15:43:29 2001
+++ tcl/unix/configure.in	Sat Nov  3 12:49:50 2001
@@ -339,6 +339,25 @@
 fi
 
 #--------------------------------------------------------------------
+# Check for support of nl_langinfo function
+#--------------------------------------------------------------------
+AC_ARG_ENABLE(langinfo,
+[  --disable-langinfo	   use old heuristic to determine encoding at
+			  startup instead of langinfo function],
+[lnginfok=$enableval], [lnginfok=yes])
+if test "$lnginfok" = yes; then
+AC_CHECK_HEADER(langinfo.h,[lnginfok=yes],[lnginfok=no])
+fi
+if test "$lnginfok" = yes; then
+AC_MSG_CHECKING([working nl_langinfo])
+AC_TRY_COMPILE([#include <langinfo.h>],
+[nl_langinfo(CODESET);],[lnginfok=yes],[lnginfok=no])
+AC_MSG_RESULT($lnginfok)
+if test "$lnginfok" = yes; then
+AC_DEFINE(HAVE_LANGINFO)
+fi
+fi
+#--------------------------------------------------------------------
 # Look for libraries that we will need when compiling the Tcl shell
 #--------------------------------------------------------------------
 
--- tcl/unix/tclUnixInit.c.orig	Sat Nov  3 15:43:09 2001
+++ tcl/unix/tclUnixInit.c	Sat Nov  3 14:04:03 2001
@@ -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
 
 /*
  *---------------------------------------------------------------------------
@@ -396,14 +401,48 @@
 	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));
+	 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")) {
+             Tcl_DStringSetLength(&ds,0);
+	     Tcl_DStringAppend(&ds,"iso8859-1",-1);
+	 }   
+	 if (Tcl_SetSystemEncoding(NULL, encoding) != TCL_OK) {
+	    fprintf(stderr,"Couldn't set encoding to '%s'\n",encoding);
+	    encoding="iso8859-1";
+	    Tcl_SetSystemEncoding(NULL,encoding);
+
+	 }
+         Tcl_DStringFree(&ds);
+#else	
+	char *langEnv;
 	langEnv = getenv("LC_ALL");
 
 	if (langEnv == NULL || langEnv[0] == '\0') {
@@ -470,7 +509,7 @@
 	 */
 
 	setlocale(LC_CTYPE, "");
-
+#endif
 	/*
 	 * In case the initial locale is not "C", ensure that the numeric
 	 * processing is done in "C" locale regardless.  This is needed because