From adaf8a609831734c41e89f386bdec83598a0912b Mon Sep 17 00:00:00 2001
From: Yorhel <git@yorhel.nl>
Date: Sun, 18 Oct 2009 12:05:36 +0200
Subject: [PATCH] Call setlocale() at initialization

This (in combination with linking to ncursesw) fixes the display of
non-ASCII characters.
---
 ChangeLog    | 1 +
 TODO         | 3 +++
 configure.in | 4 ++--
 src/main.c   | 3 +++
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dd3b0cf..8c71264 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ git - ?
 	- Return to previously opened directory on failed recalculation
 	- Properly display MiB units instead of MB (IEEE 1541 - bug #2831412)
 	- Link to ncursesw when available
+	- Improved support for non-ASCII characters
 
 1.5 - 2009-05-02
 	- Fixed incorrect apparent size on directory refresh
diff --git a/TODO b/TODO
index 8ed7a89..6c10601 100644
--- a/TODO
+++ b/TODO
@@ -24,3 +24,6 @@ Small list of planned features/changes, suggestions are always welcome.
     This should be both more intuitive and more correct than simply
     counting a semi-random occurence and ignoring others, as we do now.
 
+- Better handling of multibyte or multicolumn characters
+  * strlen() <> number_of_columns() <> number_of_characters()
+
diff --git a/configure.in b/configure.in
index 18487a7..c4ee13e 100644
--- a/configure.in
+++ b/configure.in
@@ -11,7 +11,7 @@ AC_PROG_RANLIB
 
 # Check for header files.
 AC_CHECK_HEADERS(
-  [limits.h stdlib.h string.h sys/time.h sys/types.h sys/stat.h dirent.h unistd.h fnmatch.h ncurses.h],[],
+  [limits.h stdlib.h string.h sys/time.h sys/types.h sys/stat.h dirent.h unistd.h fnmatch.h ncurses.h locale.h],[],
   AC_MSG_ERROR([required header file not found]))
 
 # Check for typedefs, structures, and compiler characteristics.
@@ -21,7 +21,7 @@ AC_STRUCT_ST_BLOCKS
 
 # Check for library functions.
 AC_CHECK_FUNCS(
-  [getcwd gettimeofday memset fnmatch chdir rmdir unlink lstat getcwd],[],
+  [getcwd gettimeofday memset fnmatch chdir rmdir unlink lstat getcwd setlocale],[],
   AC_MSG_ERROR([required function missing]))
 
 
diff --git a/src/main.c b/src/main.c
index d3f22d6..697c1e2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,6 +31,7 @@
 
 #include <unistd.h>
 #include <sys/time.h>
+#include <locale.h>
 
 int pstate;
 
@@ -146,6 +147,8 @@ char *argv_parse(int argc, char **argv) {
 int main(int argc, char **argv) {
   char *dir;
 
+  setlocale(LC_ALL, "");
+
   if((dir = argv_parse(argc, argv)) == NULL)
     dir = ".";
 
-- 
GitLab