diff options
author | hobbs <hobbs> | 2001-11-16 23:40:41 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2001-11-16 23:40:41 (GMT) |
commit | f1faf95e9df1c283ad82eae2029b1ff343e87da1 (patch) | |
tree | 8185a3f81576f448f7373bf373953eaaf2f3316b /unix/tclUnixInit.c | |
parent | 90d80ae682bd62e4420a9cc7a93eff286530fbde (diff) | |
download | tcl-f1faf95e9df1c283ad82eae2029b1ff343e87da1.zip tcl-f1faf95e9df1c283ad82eae2029b1ff343e87da1.tar.gz tcl-f1faf95e9df1c283ad82eae2029b1ff343e87da1.tar.bz2 |
adjusted HAVE_LANGINFO to allow for fallback table, added gb2312-1980 alias for gb2312
Diffstat (limited to 'unix/tclUnixInit.c')
-rw-r--r-- | unix/tclUnixInit.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index 44d486e..72d1cda 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -7,7 +7,7 @@ * Copyright (c) 1999 by Scriptics Corporation. * All rights reserved. * - * RCS: @(#) $Id: tclUnixInit.c,v 1.25 2001/11/16 20:55:40 hobbs Exp $ + * RCS: @(#) $Id: tclUnixInit.c,v 1.26 2001/11/16 23:40:41 hobbs Exp $ */ #include "tclInt.h" @@ -52,10 +52,12 @@ static char defaultLibraryDir[sizeof(TCL_LIBRARY)+200] = TCL_LIBRARY; 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. + * encoding files. If HAVE_LANGINFO is defined, then this is a fallback + * table when the result from nl_langinfo isn't a recognized encoding. + * Otherwise this is the first list checked for a mapping from env + * encoding to Tcl encoding name. */ typedef struct LocaleTable { @@ -64,6 +66,9 @@ typedef struct LocaleTable { } LocaleTable; static CONST LocaleTable localeTable[] = { +#ifdef HAVE_LANGINFO + {"gb2312-1980", "gb2312"}, +#else {"ja_JP.SJIS", "shiftjis"}, {"ja_JP.EUC", "euc-jp"}, {"ja_JP.eucJP", "euc-jp"}, @@ -98,10 +103,9 @@ static CONST LocaleTable localeTable[] = { {"ru_SU", "iso8859-5"}, {"zh", "cp936"}, - +#endif /* !HAVE_LANGINFO */ {NULL, NULL} }; -#endif /* !HAVE_LANGINFO */ /* *--------------------------------------------------------------------------- @@ -409,6 +413,7 @@ TclpSetInitialEncodings() */ #ifdef HAVE_LANGINFO Tcl_DString ds; + int code; setlocale(LC_CTYPE,""); Tcl_DStringInit(&ds); @@ -437,7 +442,17 @@ TclpSetInitialEncodings() Tcl_DStringSetLength(&ds, 0); Tcl_DStringAppend(&ds, "iso8859-1", -1); } - if (Tcl_SetSystemEncoding(NULL, encoding) != TCL_OK) { + code = Tcl_SetSystemEncoding(NULL, encoding); + if (code != TCL_OK) { + for (i = 0; localeTable[i].lang != NULL; i++) { + if (strcmp(localeTable[i].lang, encoding) == 0) { + encoding = localeTable[i].encoding; + code = Tcl_SetSystemEncoding(NULL, encoding); + break; + } + } + } + if (code != TCL_OK) { Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); if (errChannel) { char msg[100]; |