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

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Jan 27 13:32:20 CET 2007


Hello,
On Sat, Jan 27, 2007 at 12:23:10AM +0800, Zuxy Meng wrote:
> Copy & paste from GnuPG:-) Comments are welcome.
> 
> -- 
> Zuxy
> Beauty is truth,
> While truth is beauty.
> PGP KeyID: E8555ED6

> Index: mp_msg.c
> ===================================================================
> --- mp_msg.c	???????? 22020??
> +++ mp_msg.c	????????????
> @@ -27,6 +27,10 @@
>  #endif
>  #include "mp_msg.h"
>  
> +#ifdef __MINGW32__
> +#include <windows.h>
> +#endif
> +
>  /* maximum message length of mp_msg */
>  #define MSGSIZE_MAX 3072
>  
> @@ -72,6 +76,30 @@
>  void mp_msg_init(void){
>      int i;
>      char *env = getenv("MPLAYER_VERBOSE");
> +#if defined(USE_ICONV) && defined(__MINGW32__) && !defined(USE_LANGINFO)
> +    static char codepage[10];
> +    unsigned cpno;
> +    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 }
> +    };
> +#endif

Too much code, put it in a separate function IMO, maybe best into
osdep/getch2-win.c (I know it fits not quite. On the other hand that's
where all the other windows console functions are currently).

> @@ -84,6 +112,30 @@
>        mp_msg_charset = nl_langinfo(CODESET);
>        setlocale(LC_CTYPE, "C");
>      }
> +#elif defined(__MINGW32__)
> +    if (mp_msg_charset)
> +	return;

Do not use tabs in this file.

> +    cpno = GetConsoleOutputCP();
> +    if (!cpno)
> +        cpno = GetACP();
> +    if (!cpno)
> +        return;
> +
> +    if (cpno >= cp_alias[0].cp) {
> +        unsigned cur_cp;
> +        i = 0;
> +        while (cur_cp = cp_alias[i].cp) {
> +            if (cpno == cur_cp) {
> +                mp_msg_charset = cp_alias[i].alias;
> +                return;
> +            } 
> +            i++;
> +        }
> +    }

(assuming you put it in a separate function:)
for (i = 0; cp_alias[i].alias; i++)
    if (cur_cp == cpno)
        return cp_alias[i].alias;

> +
> +    snprintf(codepage, sizeof(codepage), "CP%u", cpno);
> +    mp_msg_charset = codepage;
> +    return;

that return is useless in this case.

Greetings,
Reimar Döffinger



More information about the MPlayer-dev-eng mailing list