in24/in32/fl32 little/big-endian QuickTime PCM audio support
[mplayer/glamo.git] / mp_msg.c
blob8439b141d8f61b3b4e2fa3a30daefb1c3e68220f
2 //#define MSG_USE_COLORS
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdarg.h>
8 #include "config.h"
10 #ifdef USE_LANGINFO
11 #include <locale.h>
12 #include <langinfo.h>
13 #endif
14 #ifdef USE_ICONV
15 #include <iconv.h>
16 #endif
18 #if defined(FOR_MENCODER) || defined(CODECS2HTML)
19 #undef HAVE_NEW_GUI
20 #endif
22 #ifdef HAVE_NEW_GUI
23 #include "Gui/interface.h"
24 extern int use_gui;
25 #endif
26 #include "mp_msg.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;
33 int verbose = 0;
34 #ifdef USE_ICONV
35 char *mp_msg_charset = NULL;
36 static char *old_charset = NULL;
37 static iconv_t msgiconv;
38 #endif
40 void mp_msg_init(void){
41 int i;
42 char *env = getenv("MPLAYER_VERBOSE");
43 if (env)
44 verbose = atoi(env);
45 #ifdef USE_I18N
46 #ifdef MP_DEBUG
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));
50 #endif
51 bindtextdomain("mplayer", PREFIX"/share/locale");
52 textdomain("mplayer");
53 #ifdef MP_DEBUG
54 fprintf(stdout, "Current domain: %s\n", textdomain(NULL));
55 fprintf(stdout, "Current dirname: %s\n\n", bindtextdomain(textdomain(NULL),NULL));
56 #endif
57 #endif
58 for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2;
59 #ifdef USE_ICONV
60 mp_msg_charset = getenv("MPLAYER_CHARSET");
61 #ifdef USE_LANGINFO
62 if (!mp_msg_charset) {
63 setlocale(LC_CTYPE, "");
64 mp_msg_charset = nl_langinfo(CODESET);
65 setlocale(LC_CTYPE, "C");
67 #endif
68 #endif
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, ... ){
77 va_list va;
78 char tmp[MSGSIZE_MAX];
80 if (!mp_msg_test(mod, lev)) return; // do not display
81 va_start(va, format);
82 vsnprintf(tmp, MSGSIZE_MAX, mp_gettext(format), va);
83 va_end(va);
84 tmp[MSGSIZE_MAX-2] = '\n';
85 tmp[MSGSIZE_MAX-1] = 0;
87 #ifdef HAVE_NEW_GUI
88 if(use_gui)
89 guiMessageBox(lev, tmp);
90 #endif
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)) {
98 if (old_charset) {
99 free(old_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)
108 break;
109 *out++ = *in++;
110 outlen--; inlen--;
112 strncpy(tmp, tmp2, MSGSIZE_MAX);
113 tmp[MSGSIZE_MAX-1] = 0;
114 tmp[MSGSIZE_MAX-2] = '\n';
116 #endif
118 #ifdef MSG_USE_COLORS
119 /* that's only a silly color test */
120 #ifdef MP_ANNOY_ME
121 { int c;
122 static int flag=1;
123 if(flag)
124 for(c=0;c<24;c++)
125 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c);
126 flag=0;
128 #endif
129 { unsigned char v_colors[10]={9,1,3,15,7,2,2,8,8,8};
130 static const char *lev_text[]= {
131 "FATAL",
132 "ERROR",
133 "WARN",
134 "HINT",
135 "INFO",
136 "STATUS",
137 "V",
138 "DGB2",
139 "DGB3",
140 "DGB4"};
141 static const char *mod_text[]= {
142 "GLOBAL",
143 "CPLAYER",
144 "GPLAYER",
145 "VIDEOOUT",
146 "AUDIOOUT",
147 "DEMUXER",
148 "DS",
149 "DEMUX",
150 "HEADER",
151 "AVSYNC",
152 "AUTOQ",
153 "CFGPARSER",
154 "DECAUDIO",
155 "DECVIDEO",
156 "SEEK",
157 "WIN32",
158 "OPEN",
159 "DVD",
160 "PARSEES",
161 "LIRC",
162 "STREAM",
163 "CACHE",
164 "MENCODER",
165 "XACODEC",
166 "TV",
167 "OSDEP",
168 "SPUDEC",
169 "PLAYTREE",
170 "INPUT",
171 "VFILTER",
172 "OSD",
173 "NETWORK",
174 "CPUDETECT",
175 "CODECCFG",
176 "SWS",
177 "VOBSUB",
178 "SUBREADER",
179 "AFILTER",
180 "NETST",
181 "MUXER"};
183 int c=v_colors[lev];
184 int c2=(mod+1)%15+1;
185 static int header=1;
186 FILE *stream= (lev) <= MSGL_WARN ? stderr : stdout;
187 if(header){
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';
194 #endif
195 if (lev <= MSGL_WARN){
196 fprintf(stderr, "%s", tmp);fflush(stderr);
197 } else {
198 printf("%s", tmp);fflush(stdout);