11 char* get_term_charset(void);
14 #if defined(FOR_MENCODER)
20 #include "gui/interface.h"
24 /* maximum message length of mp_msg */
25 #define MSGSIZE_MAX 3072
27 int mp_msg_levels
[MSGT_MAX
]; // verbose level of this module. initialized to -2
28 int mp_msg_level_all
= MSGL_STATUS
;
31 int mp_msg_module
= 0;
33 char *mp_msg_charset
= NULL
;
34 static char *old_charset
= NULL
;
35 static iconv_t msgiconv
;
38 const char* filename_recode(const char* filename
)
40 #if !defined(CONFIG_ICONV) || !defined(MSG_CHARSET)
43 static iconv_t inv_msgiconv
= (iconv_t
)(-1);
44 static char recoded_filename
[MSGSIZE_MAX
];
45 size_t filename_len
, max_path
;
47 if (!mp_msg_charset
||
48 !strcasecmp(mp_msg_charset
, MSG_CHARSET
) ||
49 !strcasecmp(mp_msg_charset
, "noconv"))
51 if (inv_msgiconv
== (iconv_t
)(-1)) {
52 inv_msgiconv
= iconv_open(MSG_CHARSET
, mp_msg_charset
);
53 if (inv_msgiconv
== (iconv_t
)(-1))
56 filename_len
= strlen(filename
);
57 max_path
= MSGSIZE_MAX
- 4;
58 precoded
= recoded_filename
;
59 if (iconv(inv_msgiconv
, &filename
, &filename_len
,
60 &precoded
, &max_path
) == (size_t)(-1) && errno
== E2BIG
) {
61 precoded
[0] = precoded
[1] = precoded
[2] = '.';
65 return recoded_filename
;
69 void mp_msg_init(void){
71 char *env
= getenv("MPLAYER_VERBOSE");
74 for(i
=0;i
<MSGT_MAX
;i
++) mp_msg_levels
[i
] = -2;
75 mp_msg_levels
[MSGT_IDENTIFY
] = -1; // no -identify output by default
77 mp_msg_charset
= getenv("MPLAYER_CHARSET");
79 mp_msg_charset
= get_term_charset();
83 int mp_msg_test(int mod
, int lev
)
85 return lev
<= (mp_msg_levels
[mod
] == -2 ? mp_msg_level_all
+ verbose
: mp_msg_levels
[mod
]);
88 static void set_msg_color(FILE* stream
, int lev
)
90 static const unsigned char v_colors
[10] = {9, 1, 3, 15, 7, 2, 2, 8, 8, 8};
91 int c
= v_colors
[lev
];
93 /* that's only a silly color test */
98 for(c
= 0; c
< 24; c
++)
99 printf("\033[%d;3%dm*** COLOR TEST %d ***\n", c
>7, c
&7, c
);
104 fprintf(stream
, "\033[%d;3%dm", c
>> 3, c
& 7);
107 static void print_msg_module(FILE* stream
, int mod
)
109 static const char *module_text
[MSGT_MAX
] = {
157 int c2
= (mod
+ 1) % 15 + 1;
162 fprintf(stream
, "\033[%d;3%dm", c2
>> 3, c2
& 7);
163 fprintf(stream
, "%9s", module_text
[mod
]);
165 fprintf(stream
, "\033[0;37m");
166 fprintf(stream
, ": ");
169 void mp_msg(int mod
, int lev
, const char *format
, ... ){
171 char tmp
[MSGSIZE_MAX
];
172 FILE *stream
= lev
<= MSGL_WARN
? stderr
: stdout
;
173 static int header
= 1;
175 if (!mp_msg_test(mod
, lev
)) return; // do not display
176 va_start(va
, format
);
177 vsnprintf(tmp
, MSGSIZE_MAX
, format
, va
);
179 tmp
[MSGSIZE_MAX
-2] = '\n';
180 tmp
[MSGSIZE_MAX
-1] = 0;
184 guiMessageBox(lev
, tmp
);
187 #if defined(CONFIG_ICONV) && defined(MSG_CHARSET)
188 if (mp_msg_charset
&& strcasecmp(mp_msg_charset
, "noconv")) {
189 char tmp2
[MSGSIZE_MAX
];
190 size_t inlen
= strlen(tmp
), outlen
= MSGSIZE_MAX
;
191 char *in
= tmp
, *out
= tmp2
;
192 if (!old_charset
|| strcmp(old_charset
, mp_msg_charset
)) {
195 iconv_close(msgiconv
);
197 msgiconv
= iconv_open(mp_msg_charset
, MSG_CHARSET
);
198 old_charset
= strdup(mp_msg_charset
);
200 if (msgiconv
== (iconv_t
)(-1)) {
201 fprintf(stderr
,"iconv: conversion from %s to %s unsupported\n"
202 ,MSG_CHARSET
,mp_msg_charset
);
204 memset(tmp2
, 0, MSGSIZE_MAX
);
205 while (iconv(msgiconv
, &in
, &inlen
, &out
, &outlen
) == -1) {
206 if (!inlen
|| !outlen
)
211 strncpy(tmp
, tmp2
, MSGSIZE_MAX
);
212 tmp
[MSGSIZE_MAX
-1] = 0;
213 tmp
[MSGSIZE_MAX
-2] = '\n';
219 print_msg_module(stream
, mod
);
220 set_msg_color(stream
, lev
);
221 header
= tmp
[strlen(tmp
)-1] == '\n' || tmp
[strlen(tmp
)-1] == '\r';
223 fprintf(stream
, "%s", tmp
);