]> wagner.pp.ru Git - oss/less.git/commitdiff
Force output codepage to 65001 and restore before quit
authorVictor Wagner <vitus@wagner.pp.ru>
Fri, 18 Mar 2016 09:46:51 +0000 (12:46 +0300)
committerVictor Wagner <vitus@wagner.pp.ru>
Fri, 18 Mar 2016 09:46:51 +0000 (12:46 +0300)
charset.c
main.c

index 4c62664e73d1008a48dc8bb564314c3c4c56f272..69b035f1d4a736f667470c43eef4dee57e2434e9 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -14,6 +14,9 @@
  */
 
 #include "less.h"
+#if MSDOS_COMPILER==WIN32C
+#include <windows.h>
+#endif
 #if HAVE_LOCALE
 #include <locale.h>
 #include <ctype.h>
@@ -319,7 +322,15 @@ set_charset()
                ichardef(s);
                return;
        }
-
+#ifdef WIN32
+       SetConsoleOutputCP(65001);
+    _setmode(_fileno(stdout),_O_U8TEXT);
+    _setmode(_fileno(stderr),_O_U8TEXT);
+       if (isatty(fileno(stdin))) 
+               _setmode(_fileno(stdin),_O_U8TEXT);
+       icharset("UTF-8",0);
+       
+#else 
 #if HAVE_LOCALE
 #ifdef CODESET
        /*
@@ -364,6 +375,7 @@ set_charset()
        (void) icharset("latin1", 1);
 #endif
 #endif
+#endif
 }
 
 /*
diff --git a/main.c b/main.c
index 149999cd4b537fa1d2b38bb969c18c845305772a..e4f35b9ac72eb34b2c6557999b940c9927d78887 100644 (file)
--- a/main.c
+++ b/main.c
@@ -51,6 +51,7 @@ extern int    jump_sline;
 
 #ifdef WIN32
 static char consoleTitle[256];
+static int  savedConsoleCodePage;
 #endif
 
 extern int     less_is_more;
@@ -103,6 +104,7 @@ main(argc, argv)
                }
        }
        GetConsoleTitle(consoleTitle, sizeof(consoleTitle)/sizeof(char));
+       savedConsoleCodePage = GetConsoleOutputCP();    
 #endif /* WIN32 */
 
        /*
@@ -404,6 +406,7 @@ quit(status)
 #endif
 #ifdef WIN32
        SetConsoleTitle(consoleTitle);
+       SetConsoleOutputCP(savedConsoleCodePage);
 #endif
        close_getchr();
        exit(status);