On Sat, Jan 20, 2007 at 04:21:33PM -0700, Wesley J. Landaker wrote: > tree --charset=UTF-8 looks great in UTF-8 locales, but by default tree > doesn't use this charset even when the locale is set to UTF-8. Please > consider doing this by default! (The user can always override this setting by > using a different --charset option or specifying a different locale.)
The attached patch makes tree look at the user's selected locale codeset and will use this unless overridden by the TREE_CHARSET environment variable, or the user's --charset option. This fixes the getcharset() function, which was apparently not being used. If this is anappropriate, then just switch charset = getcharset(); to charset = nl_langinfo(CODESET); Note that this patch may also fix #267395 as well. tree.c was only initialising the LC_CTYPE part of the locale, rather than all locale facets setlocale(LC_ALL, ""). As a result, LC_COLLATE wasn't set, so now strcmp() et al will work in a locale-dependent manner. Regards, Roger -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.
diff -urN tree-1.5.2.2.original/tree.c tree-1.5.2.2/tree.c
--- tree-1.5.2.2.original/tree.c 2009-08-01 12:50:38.000000000 +0100
+++ tree-1.5.2.2/tree.c 2009-08-01 12:59:34.883360855 +0100
@@ -38,6 +38,7 @@
#include <ctype.h>
#include <unistd.h>
#include <limits.h>
+#include <langinfo.h>
#include <pwd.h>
#include <grp.h>
#ifdef __EMX__ /* for OS/2 systems */
@@ -218,7 +219,8 @@
dirs[0] = 0;
Level = -1;
- setlocale(LC_CTYPE, "");
+ setlocale(LC_ALL, "");
+ charset = getcharset();
/* Until I get rid of this hack, make it linux/cygwin/HP nonstop only: */
#if defined (LINUX) || defined (CYGWIN) || defined (__TANDEM)
@@ -1615,7 +1617,12 @@
const char *getcharset(void)
{
#ifndef __EMX__
- return getenv("TREE_CHARSET");
+ char *charset = getenv("TREE_CHARSET");
+
+ if (!charset)
+ charset = nl_langinfo(CODESET);
+
+ return charset;
#else
static char buffer[13];
ULONG aulCpList[3],ulListSize,codepage=0;
signature.asc
Description: Digital signature

