Mercurial > mplayer.hg
diff osdep/getch2-win.c @ 22442:56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
Patch by Zuxy Meng [zuxy.meng at gmail com]
author | reimar |
---|---|
date | Sun, 04 Mar 2007 19:04:08 +0000 |
parents | 6f183c95aafc |
children | 71b3e04d0555 |
line wrap: on
line diff
--- a/osdep/getch2-win.c Sun Mar 04 18:55:44 2007 +0000 +++ b/osdep/getch2-win.c Sun Mar 04 19:04:08 2007 +0000 @@ -4,6 +4,7 @@ // for additional virtual keycodes +#include "config.h" #include <stdio.h> #include <windows.h> #include "keycodes.h" @@ -134,3 +135,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