[MPlayer-dev-eng] [PATCH] Support locale under Windows console

Zuxy Meng zuxy.meng at gmail.com
Thu Mar 1 12:00:51 CET 2007


Hi,

2007/3/1, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> Hello,
> On Thu, Mar 01, 2007 at 06:10:21PM +0800, Zuxy Meng wrote:
> > 2007/3/1, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> > >On Thu, Mar 01, 2007 at 12:39:20PM +0800, Zuxy Meng wrote:
> > >> -
> > >> +#include <stdio.h>
> > >>  #include <windows.h>
> > >>  #include "keycodes.h"
> > >>  #include "input/input.h"
> > >>
> > >>  int mp_input_win32_slave_cmd_func(int fd,char* dest,int size){
> > >>    DWORD retval;
> > >> -  HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE);
> > >> -  if(!PeekNamedPipe(stdin, NULL, size, &retval, NULL, NULL) || !retval){
> > >> +  HANDLE hd_stdin = GetStdHandle(STD_INPUT_HANDLE);
> > >> +  if(!PeekNamedPipe(hd_stdin, NULL, size, &retval, NULL, NULL) ||
> > >!retval){
> > >
> > >
> > >just put the stdio.h include into the USE_ICONV ifdef below. That's not
> > >too beautiful but not more ugly than this...
> >
> > The purpose to include <stdio.h> was to avoid warnings about
> > undeclared "snprintf": just don't want to introduce more warnings in
> > the new code. However, "printf" had been used in old code, too; so
> > after I did what you suggested, there were still warnings. So we can
> > either:
> > 1. Ignore the warning and don't bother <stdio.h> at all.
> > 2. Rename stdin....
>
> 3. #undef stdin after the include
> 4. change printf to mp_msg in a separate patch
> 5. add stdio.h and rename stdin in a separate patch

OK. Let's deal with this header later.


-- 
Zuxy
Beauty is truth,
While truth is beauty.
PGP KeyID: E8555ED6
-------------- next part --------------
Index: mp_msg.c
===================================================================
--- mp_msg.c	?????? 22383??
+++ mp_msg.c	????????????
@@ -8,13 +8,10 @@
 
 #include "config.h"
 
-#ifdef USE_LANGINFO
-#include <locale.h>
-#include <langinfo.h>
-#endif
 #ifdef USE_ICONV
 #include <iconv.h>
 #include <errno.h>
+extern char* get_term_charset();
 #endif
 
 #if defined(FOR_MENCODER) || defined(CODECS2HTML)
@@ -79,14 +76,9 @@
     mp_msg_levels[MSGT_IDENTIFY] = -1; // no -identify output by default
 #ifdef USE_ICONV
     mp_msg_charset = getenv("MPLAYER_CHARSET");
-#ifdef USE_LANGINFO
-    if (!mp_msg_charset) {
-      setlocale(LC_CTYPE, "");
-      mp_msg_charset = nl_langinfo(CODESET);
-      setlocale(LC_CTYPE, "C");
-    }
+    if (!mp_msg_charset)
+      mp_msg_charset = get_term_charset();
 #endif
-#endif
 }
 
 int mp_msg_test(int mod, int lev)
Index: osdep/getch2.c
===================================================================
--- osdep/getch2.c	?????? 22383??
+++ osdep/getch2.c	????????????
@@ -28,6 +28,11 @@
 #endif
 #endif
 
+#if defined(USE_LANGINFO) && defined(USE_ICONV)
+#include <locale.h>
+#include <langinfo.h>
+#endif
+
 #include <unistd.h>
 
 #include "keycodes.h"
@@ -238,3 +243,16 @@
     getch2_status=0;
 }
 
+#ifdef USE_ICONV
+char* get_term_charset()
+{
+    char* charset = NULL;
+#ifdef USE_LANGINFO
+    setlocale(LC_CTYPE, "");
+    charset = nl_langinfo(CODESET);
+    setlocale(LC_CTYPE, "C");
+#endif
+    return charset;
+}
+#endif
+
Index: osdep/getch2-win.c
===================================================================
--- osdep/getch2-win.c	?????? 22383??
+++ osdep/getch2-win.c	????????????
@@ -2,8 +2,8 @@
 
 // See  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
 // for additional virtual keycodes
+#include "config.h"
 
-
 #include <windows.h>
 #include "keycodes.h"
 #include "input/input.h"
@@ -131,3 +131,42 @@
     getch2_status=0;
 }
 
+#ifdef USE_ICONV
+static const struct {
+    unsigned cp;
+    char* alias;
+} cp_alias[] = {
+    { 20127, "ASCII" },
+    { 20866, "KOI8-R" },
+    { 21866, "KOI8-RU" },
+    { 28591, "ISO-8859-1" },
+    { 28592, "ISO-8859-2" },
+    { 28593, "ISO-8859-3" },
+    { 28594, "ISO-8859-4" },
+    { 28595, "ISO-8859-5" },
+    { 28596, "ISO-8859-6" },
+    { 28597, "ISO-8859-7" },
+    { 28598, "ISO-8859-8" },
+    { 28599, "ISO-8859-9" },
+    { 28605, "ISO-8859-15" },
+    { 65001, "UTF-8" },
+    { 0, NULL }
+};
+ 
+char* get_term_charset()
+{
+    static char codepage[10];
+    unsigned i, cpno = GetConsoleOutputCP();
+    if (!cpno)
+        cpno = GetACP();
+    if (!cpno)
+        return NULL;
+
+    for (i = 0; cp_alias[i].cp; i++)
+	if (cpno == cp_alias[i].cp)
+	    return cp_alias[i].alias;
+
+    snprintf(codepage, sizeof(codepage), "CP%u", cpno);
+    return codepage;
+}
+#endif


More information about the MPlayer-dev-eng mailing list