2 //#define MSG_USE_COLORS
20 #if defined(FOR_MENCODER) || defined(CODECS2HTML)
25 #include "Gui/interface.h"
30 /* maximum message length of mp_msg */
31 #define MSGSIZE_MAX 3072
33 int mp_msg_levels
[MSGT_MAX
]; // verbose level of this module. inited to -2
34 int mp_msg_level_all
= MSGL_STATUS
;
37 char *mp_msg_charset
= NULL
;
38 static char *old_charset
= NULL
;
39 static iconv_t msgiconv
;
42 const char* filename_recode(const char* filename
)
44 #if !defined(USE_ICONV) || !defined(MSG_CHARSET)
47 static iconv_t inv_msgiconv
= (iconv_t
)(-1);
48 static char recoded_filename
[MSGSIZE_MAX
];
49 size_t filename_len
, max_path
;
51 if (!mp_msg_charset
||
52 !strcasecmp(mp_msg_charset
, MSG_CHARSET
) ||
53 !strcasecmp(mp_msg_charset
, "noconv"))
55 if (inv_msgiconv
== (iconv_t
)(-1)) {
56 inv_msgiconv
= iconv_open(MSG_CHARSET
, mp_msg_charset
);
57 if (inv_msgiconv
== (iconv_t
)(-1))
60 filename_len
= strlen(filename
);
61 max_path
= MSGSIZE_MAX
- 4;
62 precoded
= recoded_filename
;
63 if (iconv(inv_msgiconv
, &filename
, &filename_len
,
64 &precoded
, &max_path
) == (size_t)(-1) && errno
== E2BIG
) {
65 precoded
[0] = precoded
[1] = precoded
[2] = '.';
69 return recoded_filename
;
73 void mp_msg_init(void){
75 char *env
= getenv("MPLAYER_VERBOSE");
78 for(i
=0;i
<MSGT_MAX
;i
++) mp_msg_levels
[i
] = -2;
79 mp_msg_levels
[MSGT_IDENTIFY
] = -1; // no -identify output by default
81 mp_msg_charset
= getenv("MPLAYER_CHARSET");
83 if (!mp_msg_charset
) {
84 setlocale(LC_CTYPE
, "");
85 mp_msg_charset
= nl_langinfo(CODESET
);
86 setlocale(LC_CTYPE
, "C");
92 int mp_msg_test(int mod
, int lev
)
94 return lev
<= (mp_msg_levels
[mod
] == -2 ? mp_msg_level_all
+ verbose
: mp_msg_levels
[mod
]);
97 void mp_msg(int mod
, int lev
, const char *format
, ... ){
99 char tmp
[MSGSIZE_MAX
];
101 if (!mp_msg_test(mod
, lev
)) return; // do not display
102 va_start(va
, format
);
103 vsnprintf(tmp
, MSGSIZE_MAX
, format
, va
);
105 tmp
[MSGSIZE_MAX
-2] = '\n';
106 tmp
[MSGSIZE_MAX
-1] = 0;
110 guiMessageBox(lev
, tmp
);
113 #if defined(USE_ICONV) && defined(MSG_CHARSET)
114 if (mp_msg_charset
&& strcasecmp(mp_msg_charset
, "noconv")) {
115 char tmp2
[MSGSIZE_MAX
];
116 size_t inlen
= strlen(tmp
), outlen
= MSGSIZE_MAX
;
117 char *in
= tmp
, *out
= tmp2
;
118 if (!old_charset
|| strcmp(old_charset
, mp_msg_charset
)) {
121 iconv_close(msgiconv
);
123 msgiconv
= iconv_open(mp_msg_charset
, MSG_CHARSET
);
124 old_charset
= strdup(mp_msg_charset
);
126 if (msgiconv
== (iconv_t
)(-1)) {
127 fprintf(stderr
,"iconv: conversion from %s to %s unsupported\n"
128 ,MSG_CHARSET
,mp_msg_charset
);
130 memset(tmp2
, 0, MSGSIZE_MAX
);
131 while (iconv(msgiconv
, &in
, &inlen
, &out
, &outlen
) == -1) {
132 if (!inlen
|| !outlen
)
137 strncpy(tmp
, tmp2
, MSGSIZE_MAX
);
138 tmp
[MSGSIZE_MAX
-1] = 0;
139 tmp
[MSGSIZE_MAX
-2] = '\n';
144 #ifdef MSG_USE_COLORS
145 /* that's only a silly color test */
151 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c
>7),c
&7,c
);
155 { unsigned char v_colors
[10]={9,1,3,15,7,2,2,8,8,8};
156 static const char *lev_text
[]= {
169 static const char *mod_text
[MSGT_MAX
]= {
220 FILE *stream
= (lev
) <= MSGL_WARN
? stderr
: stdout
;
222 fprintf(stream
, "\033[%d;3%dm%9s\033[0;37m: ",c2
>>3,c2
&7, mod_text
[mod
]);
224 fprintf(stream
, "\033[%d;3%dm",c
>>3,c
&7);
225 header
= tmp
[strlen(tmp
)-1] == '\n'
226 ||tmp
[strlen(tmp
)-1] == '\r';
229 if (lev
<= MSGL_WARN
){
230 fprintf(stderr
, "%s", tmp
);fflush(stderr
);
232 printf("%s", tmp
);fflush(stdout
);