diff options
author | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2007-03-04 19:04:08 +0000 |
---|---|---|
committer | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2007-03-04 19:04:08 +0000 |
commit | a188335a339bea5d07f8d79ea105446362f3a95e (patch) | |
tree | e61e7af5e46acd6ee2d708bd33c8bf9d23414385 /osdep | |
parent | 9ca5decb0b51bedea1de69e088db5631156508fd (diff) | |
download | mpv-a188335a339bea5d07f8d79ea105446362f3a95e.tar.bz2 mpv-a188335a339bea5d07f8d79ea105446362f3a95e.tar.xz |
Add code to detect and convert to console codepage on Windows.
Patch by Zuxy Meng [zuxy.meng at gmail com]
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22460 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/getch2-win.c | 40 | ||||
-rw-r--r-- | osdep/getch2.c | 18 |
2 files changed, 58 insertions, 0 deletions
diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c index d0aba80823..a20f1331f0 100644 --- a/osdep/getch2-win.c +++ b/osdep/getch2-win.c @@ -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 diff --git a/osdep/getch2.c b/osdep/getch2.c index c104790900..a4226415f0 100644 --- a/osdep/getch2.c +++ b/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 @@ 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 + |