Locale initialization still doesn't fixed.
Closed / Fixed217925ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:46:03
OriginalBugID: 3345 Bug
Version: 8.2.1
SubmitDate: '1999-11-05'
LastModified: '2000-05-18'
Severity: SER
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 5422 2521 2522 4236 6096
OS: Linux
OSVersion: Debian 2.1
FixedDate: '2000-10-25'
ClosedDate: '2000-05-18'
Name: Victor Wagner
Comments:
Patch was created using cvs diff -r core-8-2-1
Really, there should be way to change locale inside tcl script to allow
using even LC_NUMERIC
There are three possible approaches
1. Trace on LC_* environment variables
2. Explicit setlocale command
3, -locale option for commands such as clock scan, clock format , scan
and format
First two approaches are a bit dangerous, becouse programmer couldn'g
guarantee that no implicit
number to string conversion would occur with incorrect locale settings.
Later approach is safe, becouse in the C code it can be ensured that
locale is reset back immediately
after system call.
But in case of national date/time format additional problem occurs - it
is required to determine encoding
again for each new locale value. If it would be possible to use
nl_langinfo, it would be fine. But it can be recommended
only as compile-time option, becouse not all systems are XPG4 compliant.
ObservedBehavior:
Non-ascii characters cannot be entered from keyboard in Tk application,
if system uses Xkb.
It is caused by incorrect location of resetPath: label in TclUnixInit.c:
If LANG environment variable
is set to value with explicit encoding in it (in my case, ru_RU.KOI8-R),
tcl skips setlocale call at all.
Other cause of this error is that locale is immediately reset to C after
is set correctly, before Tk is initlized
and Xlib begans to know about current locale.
When this is fixed, another problem appeared: Tcl expects values
returned by strftime function in clock format
command to be in ISO-Latin1 charset rather than current system encoding.
DesiredBehavior:
LC_CTYPE should be set to current value and left in this state for the
duration of tcl execution. It would'nt affect
sorting and toupper/tolower operation, since they are performed in
Unicode anyway.
All locale categories except LC_NUMERIC should be set to current user
value. If user wants to have LC_TIME in
non-native language, he always can do it explicitely. But in most
applications it is desirable to allow native-language
formatting. All places where Tcl interacts with system library should
assume, that library routines expect and return
values in default encoding, unless explicitely told opposite. If any of
charsets are to be treated specially by Tcl,
it should be Unicode only (except using iso8859-1 for binary file
access).
Patch:
Index: generic/tclClock.c
===================================================================
RCS file: /cvsroot/tcl/generic/tclClock.c,v
retrieving revision 1.4
diff -u -r1.4 tclClock.c
--- tclClock.c1999/04/16 00:46:431.4
+++ tclClock.c1999/10/07 08:46:41
@@ -228,7 +228,7 @@
char *format;/* Format string */
{
struct tm *timeDataPtr;
- Tcl_DString buffer;
+ Tcl_DString buffer,unicode_buffer;
int bufSize;
char *p;
Tcl_Obj *resultPtr;
@@ -315,8 +315,10 @@
"\"", (char *) NULL);
return TCL_ERROR;
}
-
- Tcl_SetStringObj(resultPtr, buffer.string, -1);
+ Tcl_DStringInit(&unicode_buffer);
+ Tcl_ExternalToUtfDString(NULL,buffer.string,-1,&unicode_buffer);
+ Tcl_SetStringObj(resultPtr, unicode_buffer.string, -1 );
+ Tcl_DStringFree(&unicode_buffer);
Tcl_DStringFree(&buffer);
return TCL_OK;
}
Index: unix/tclUnixInit.c
===================================================================
RCS file: /cvsroot/tcl/unix/tclUnixInit.c,v
retrieving revision 1.17
diff -u -r1.17 tclUnixInit.c
--- tclUnixInit.c1999/07/22 21:50:561.17
+++ tclUnixInit.c1999/10/07 08:46:44
@@ -432,6 +432,7 @@
Tcl_SetSystemEncoding(NULL, encoding);
+ resetPath:
/*
* Initialize the C library's locale subsystem. This is required
* for input methods to work properly on X11. Note that we need to
@@ -440,11 +441,7 @@
* load any locale specific modules that are needed by X.
*/
- Tcl_DStringInit(&ds);
- Tcl_DStringAppend(&ds, setlocale(LC_ALL, NULL), -1);
setlocale(LC_ALL, "");
- setlocale(LC_ALL, Tcl_DStringValue(&ds));
- Tcl_DStringFree(&ds);
/*
* In case the initial locale is not "C", ensure that the numeric
@@ -478,7 +475,6 @@
* encoding.
*/
- resetPath:
pathPtr = TclGetLibraryPath();
if (pathPtr != NULL) {
int objc;
PatchFiles:
unix/tclUnixInit.c
generic/tclClock.c
See related bug 2521 for comments.
-- 04/09/2000 hobbs
See fix notes in 5422 for changes done in 8.4a1.
-- 05/18/2000 hobbs
welch Closed ticket [217925ffff].
[History diff]2000-10-26 08:09:13
dgp Ticket [217925ffff]: 3 changes
[History diff]2001-04-06 03:37:20
Log in (anonymous is fine) to add a comment.