2 //#define MSG_USE_COLORS
19 #if defined(FOR_MENCODER) || defined(CODECS2HTML)
24 #include "Gui/interface.h"
29 /* maximum message length of mp_msg */
30 #define MSGSIZE_MAX 3072
32 int mp_msg_levels
[MSGT_MAX
]; // verbose level of this module. inited to -2
33 int mp_msg_level_all
= MSGL_STATUS
;
36 char *mp_msg_charset
= NULL
;
37 static char *old_charset
= NULL
;
38 static iconv_t msgiconv
;
41 void mp_msg_init(void){
43 char *env
= getenv("MPLAYER_VERBOSE");
46 for(i
=0;i
<MSGT_MAX
;i
++) mp_msg_levels
[i
] = -2;
47 mp_msg_levels
[MSGT_IDENTIFY
] = -1; // no -identify output by default
49 mp_msg_charset
= getenv("MPLAYER_CHARSET");
51 if (!mp_msg_charset
) {
52 setlocale(LC_CTYPE
, "");
53 mp_msg_charset
= nl_langinfo(CODESET
);
54 setlocale(LC_CTYPE
, "C");
60 int mp_msg_test(int mod
, int lev
)
62 return lev
<= (mp_msg_levels
[mod
] == -2 ? mp_msg_level_all
+ verbose
: mp_msg_levels
[mod
]);
65 void mp_msg(int mod
, int lev
, const char *format
, ... ){
67 char tmp
[MSGSIZE_MAX
];
69 if (!mp_msg_test(mod
, lev
)) return; // do not display
71 vsnprintf(tmp
, MSGSIZE_MAX
, format
, va
);
73 tmp
[MSGSIZE_MAX
-2] = '\n';
74 tmp
[MSGSIZE_MAX
-1] = 0;
78 guiMessageBox(lev
, tmp
);
81 #if defined(USE_ICONV) && defined(MSG_CHARSET)
82 if (mp_msg_charset
&& strcasecmp(mp_msg_charset
, "noconv")) {
83 char tmp2
[MSGSIZE_MAX
];
84 size_t inlen
= strlen(tmp
), outlen
= MSGSIZE_MAX
;
85 char *in
= tmp
, *out
= tmp2
;
86 if (!old_charset
|| strcmp(old_charset
, mp_msg_charset
)) {
89 iconv_close(msgiconv
);
91 msgiconv
= iconv_open(mp_msg_charset
, MSG_CHARSET
);
92 old_charset
= strdup(mp_msg_charset
);
94 if (msgiconv
== (iconv_t
)(-1)) {
95 fprintf(stderr
,"iconv: conversion from %s to %s unsupported\n"
96 ,mp_msg_charset
,MSG_CHARSET
);
98 memset(tmp2
, 0, MSGSIZE_MAX
);
99 while (iconv(msgiconv
, &in
, &inlen
, &out
, &outlen
) == -1) {
100 if (!inlen
|| !outlen
)
105 strncpy(tmp
, tmp2
, MSGSIZE_MAX
);
106 tmp
[MSGSIZE_MAX
-1] = 0;
107 tmp
[MSGSIZE_MAX
-2] = '\n';
112 #ifdef MSG_USE_COLORS
113 /* that's only a silly color test */
119 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c
>7),c
&7,c
);
123 { unsigned char v_colors
[10]={9,1,3,15,7,2,2,8,8,8};
124 static const char *lev_text
[]= {
135 static const char *mod_text
[]= {
180 FILE *stream
= (lev
) <= MSGL_WARN
? stderr
: stdout
;
182 fprintf(stream
, "\033[%d;3%dm%9s\033[0;37m: ",c2
>>3,c2
&7, mod_text
[mod
]);
184 fprintf(stream
, "\033[%d;3%dm",c
>>3,c
&7);
185 header
= tmp
[strlen(tmp
)-1] == '\n'
186 ||tmp
[strlen(tmp
)-1] == '\r';
189 if (lev
<= MSGL_WARN
){
190 fprintf(stderr
, "%s", tmp
);fflush(stderr
);
192 printf("%s", tmp
);fflush(stdout
);