Correct dumping hint (vc dummy faster than null).
[mplayer/greg.git] / mp_msg.c
blobfdf6d363e36b29557bea1cecaf79a9548b64ab9e
2 //#define MSG_USE_COLORS
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdarg.h>
8 #include "config.h"
10 #if defined(FOR_MENCODER) || defined(CODECS2HTML)
11 #undef ENABLE_GUI_CODE
12 #elif defined(HAVE_NEW_GUI)
13 #define ENABLE_GUI_CODE HAVE_NEW_GUI
14 #else
15 #undef ENABLE_GUI_CODE
16 #endif
18 #if ENABLE_GUI_CODE
19 #include "Gui/mplayer/widgets.h"
20 extern void gtkMessageBox( int type,char * str );
21 extern int use_gui;
22 #endif
23 #include "mp_msg.h"
25 /* maximum message length of mp_msg */
26 #define MSGSIZE_MAX 3072
28 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module
30 #if 1
32 void mp_msg_init(){
33 #ifdef USE_I18N
34 fprintf(stdout, "Using GNU internationalization\n");
35 fprintf(stdout, "Original domain: %s\n", textdomain(NULL));
36 fprintf(stdout, "Original dirname: %s\n", bindtextdomain(textdomain(NULL),NULL));
37 setlocale(LC_ALL, ""); /* set from the environment variables */
38 bindtextdomain("mplayer", PREFIX"/share/locale");
39 textdomain("mplayer");
40 fprintf(stdout, "Current domain: %s\n", textdomain(NULL));
41 fprintf(stdout, "Current dirname: %s\n", bindtextdomain(textdomain(NULL),NULL));
42 #endif
43 mp_msg_set_level(MSGL_STATUS);
46 void mp_msg_set_level(int verbose){
47 int i;
48 for(i=0;i<MSGT_MAX;i++){
49 mp_msg_levels[i]=verbose;
53 int mp_msg_test(int mod, int lev)
55 return lev <= mp_msg_levels[mod];
58 void mp_msg_c( int x, const char *format, ... ){
59 #if 1
60 va_list va;
61 char tmp[MSGSIZE_MAX];
63 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
64 va_start(va, format);
65 vsnprintf(tmp, MSGSIZE_MAX, mp_gettext(format), va);
66 va_end(va);
67 tmp[MSGSIZE_MAX-1] = 0;
69 #if ENABLE_GUI_CODE
70 if(use_gui)
72 switch(x & 255)
74 case MSGL_FATAL:
75 gtkMessageBox(GTK_MB_FATAL|GTK_MB_SIMPLE, tmp);
76 break;
77 case MSGL_ERR:
78 gtkMessageBox(GTK_MB_ERROR|GTK_MB_SIMPLE, tmp);
79 break;
80 #if 0
81 // WARNING! Do NOT enable this! There are too many non-critical messages with
82 // MSGL_WARN, for example: broken SPU packets, codec's bit error messages,
83 // etc etc, they should not raise up a new window every time.
84 case MSGL_WARN:
85 gtkMessageBox(GTK_MB_WARNING|GTK_MB_SIMPLE, tmp);
86 break;
87 #endif
90 #endif
92 #ifdef MSG_USE_COLORS
93 #if 1
94 { int c;
95 static int flag=1;
96 if(flag)
97 for(c=0;c<16;c++)
98 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c);
99 flag=0;
101 #endif
102 { unsigned char v_colors[10]={9,9,11,14,15,7,6,5,5,5};
103 int c=v_colors[(x & 255)];
104 fprintf(((x & 255) <= MSGL_WARN)?stderr:stdout, "\033[%d;3%dm",(c>7),c&7);
106 #endif
107 if ((x & 255) <= MSGL_WARN){
108 fprintf(stderr, "%s", tmp);fflush(stderr);
109 } else {
110 printf("%s", tmp);fflush(stdout);
113 #else
114 va_list va;
115 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
116 va_start(va, format);
117 #if ENABLE_GUI_CODE
118 if(use_gui){
119 char tmp[16*80];
120 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0;
121 switch( x&255 ) {
122 case MSGL_FATAL:
123 fprintf( stderr,"%s",tmp );
124 fflush(stderr);
125 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp );
126 break;
127 case MSGL_ERR:
128 fprintf( stderr,"%s",tmp );
129 fflush(stderr);
130 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp );
131 break;
132 case MSGL_WARN:
133 fprintf( stderr, "%s",tmp );
134 fflush(stdout);
135 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp );
136 break;
137 default:
138 fprintf(stderr, "%s",tmp );
139 fflush(stdout);
141 } else
142 #endif
143 if((x&255)<=MSGL_ERR){
144 // fprintf(stderr,"%%%%%% ");
145 vfprintf(stderr,format, va);
146 fflush(stderr);
147 } else {
148 // printf("%%%%%% ");
149 vfprintf(stderr,format, va);
150 fflush(stdout);
152 va_end(va);
153 #endif
156 #else
158 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
159 static FILE* mp_msg_last_file=NULL;
161 // how to handle errors->stderr messages->stdout ?
162 void mp_msg( int x, const char *format, ... ){
163 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display
164 va_list va;
165 va_start(va, format);
166 vfprintf(mp_msg_file[x>>8],format, va);
167 if(mp_msg_last_file!=mp_msg_file[x>>8]){
168 fflush(mp_msg_file[x>>8]);
169 mp_msg_last_file=mp_msg_file[x>>8];
171 va_end(va);
174 #endif