[MPlayer-cvslog] r22460 - in trunk: mp_msg.c osdep/getch2-win.c osdep/getch2.c

reimar subversion at mplayerhq.hu
Sun Mar 4 20:04:08 CET 2007


Author: reimar
Date: Sun Mar  4 20:04:08 2007
New Revision: 22460

Modified:
   trunk/mp_msg.c
   trunk/osdep/getch2-win.c
   trunk/osdep/getch2.c

Log:
Add code to detect and convert to console codepage on Windows.
Patch by Zuxy Meng [zuxy.meng at gmail com]


Modified: trunk/mp_msg.c
==============================================================================
--- trunk/mp_msg.c	(original)
+++ trunk/mp_msg.c	Sun Mar  4 20:04:08 2007
@@ -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,13 +76,8 @@ void mp_msg_init(void){
     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");
-    }
-#endif
+    if (!mp_msg_charset)
+      mp_msg_charset = get_term_charset();
 #endif
 }
 

Modified: trunk/osdep/getch2-win.c
==============================================================================
--- trunk/osdep/getch2-win.c	(original)
+++ trunk/osdep/getch2-win.c	Sun Mar  4 20:04:08 2007
@@ -4,6 +4,7 @@
 // for additional virtual keycodes
 
 
+#include "config.h"
 #include <stdio.h>
 #include <windows.h>
 #include "keycodes.h"
@@ -134,3 +135,42 @@ void getch2_disable(){
     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

Modified: trunk/osdep/getch2.c
==============================================================================
--- trunk/osdep/getch2.c	(original)
+++ trunk/osdep/getch2.c	Sun Mar  4 20:04:08 2007
@@ -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 @@ void getch2_disable(void){
     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
+



More information about the MPlayer-cvslog mailing list