2 //#define MSG_USE_COLORS
18 #if defined(FOR_MENCODER) || defined(CODECS2HTML)
23 #include "Gui/interface.h"
28 /* maximum message length of mp_msg */
29 #define MSGSIZE_MAX 3072
31 int mp_msg_levels
[MSGT_MAX
]; // verbose level of this module. inited to -2
32 int mp_msg_level_all
= MSGL_STATUS
;
35 char *mp_msg_charset
= NULL
;
36 static char *old_charset
= NULL
;
37 static iconv_t msgiconv
;
40 void mp_msg_init(void){
42 char *env
= getenv("MPLAYER_VERBOSE");
47 fprintf(stdout
, "Using GNU internationalization\n");
48 fprintf(stdout
, "Original domain: %s\n", textdomain(NULL
));
49 fprintf(stdout
, "Original dirname: %s\n", bindtextdomain(textdomain(NULL
),NULL
));
51 bindtextdomain("mplayer", PREFIX
"/share/locale");
52 textdomain("mplayer");
54 fprintf(stdout
, "Current domain: %s\n", textdomain(NULL
));
55 fprintf(stdout
, "Current dirname: %s\n\n", bindtextdomain(textdomain(NULL
),NULL
));
58 for(i
=0;i
<MSGT_MAX
;i
++) mp_msg_levels
[i
] = -2;
60 mp_msg_charset
= getenv("MPLAYER_CHARSET");
62 if (!mp_msg_charset
) {
63 setlocale(LC_CTYPE
, "");
64 mp_msg_charset
= nl_langinfo(CODESET
);
65 setlocale(LC_CTYPE
, "C");
71 int mp_msg_test(int mod
, int lev
)
73 return lev
<= (mp_msg_levels
[mod
] == -2 ? mp_msg_level_all
+ verbose
: mp_msg_levels
[mod
]);
76 void mp_msg(int mod
, int lev
, const char *format
, ... ){
78 char tmp
[MSGSIZE_MAX
];
80 if (!mp_msg_test(mod
, lev
)) return; // do not display
82 vsnprintf(tmp
, MSGSIZE_MAX
, mp_gettext(format
), va
);
84 tmp
[MSGSIZE_MAX
-2] = '\n';
85 tmp
[MSGSIZE_MAX
-1] = 0;
89 guiMessageBox(lev
, tmp
);
92 #if defined(USE_ICONV) && defined(MSG_CHARSET)
93 if (mp_msg_charset
&& strcasecmp(mp_msg_charset
, "noconv")) {
94 char tmp2
[MSGSIZE_MAX
];
95 size_t inlen
= strlen(tmp
), outlen
= MSGSIZE_MAX
;
96 char *in
= tmp
, *out
= tmp2
;
97 if (!old_charset
|| strcmp(old_charset
, mp_msg_charset
)) {
100 iconv_close(msgiconv
);
102 msgiconv
= iconv_open(mp_msg_charset
, MSG_CHARSET
);
103 old_charset
= strdup(mp_msg_charset
);
105 memset(tmp2
, 0, MSGSIZE_MAX
);
106 while (iconv(msgiconv
, &in
, &inlen
, &out
, &outlen
) == -1) {
107 if (!inlen
|| !outlen
)
112 strncpy(tmp
, tmp2
, MSGSIZE_MAX
);
113 tmp
[MSGSIZE_MAX
-1] = 0;
114 tmp
[MSGSIZE_MAX
-2] = '\n';
118 #ifdef MSG_USE_COLORS
119 /* that's only a silly color test */
125 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c
>7),c
&7,c
);
129 { unsigned char v_colors
[10]={9,1,3,15,7,2,2,8,8,8};
130 static const char *lev_text
[]= {
141 static const char *mod_text
[]= {
186 FILE *stream
= (lev
) <= MSGL_WARN
? stderr
: stdout
;
188 fprintf(stream
, "\033[%d;3%dm%9s\033[0;37m: ",c2
>>3,c2
&7, mod_text
[mod
]);
190 fprintf(stream
, "\033[%d;3%dm",c
>>3,c
&7);
191 header
= tmp
[strlen(tmp
)-1] == '\n'
192 ||tmp
[strlen(tmp
)-1] == '\r';
195 if (lev
<= MSGL_WARN
){
196 fprintf(stderr
, "%s", tmp
);fflush(stderr
);
198 printf("%s", tmp
);fflush(stdout
);