dx50 = DX50
[mplayer/glamo.git] / mp_msg.c
blobaaf98ef33f28e301d8932a281dc8c7717cfaa84e
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 #ifdef MP_DEBUG
35 fprintf(stdout, "Using GNU internationalization\n");
36 fprintf(stdout, "Original domain: %s\n", textdomain(NULL));
37 fprintf(stdout, "Original dirname: %s\n", bindtextdomain(textdomain(NULL),NULL));
38 #endif
39 setlocale(LC_ALL, ""); /* set from the environment variables */
40 bindtextdomain("mplayer", PREFIX"/share/locale");
41 textdomain("mplayer");
42 #ifdef MP_DEBUG
43 fprintf(stdout, "Current domain: %s\n", textdomain(NULL));
44 fprintf(stdout, "Current dirname: %s\n\n", bindtextdomain(textdomain(NULL),NULL));
45 #endif
46 #endif
47 mp_msg_set_level(MSGL_STATUS);
50 void mp_msg_set_level(int verbose){
51 int i;
52 for(i=0;i<MSGT_MAX;i++){
53 mp_msg_levels[i]=verbose;
57 int mp_msg_test(int mod, int lev)
59 return lev <= mp_msg_levels[mod];
62 void mp_msg_c( int x, const char *format, ... ){
63 #if 1
64 va_list va;
65 char tmp[MSGSIZE_MAX];
67 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
68 va_start(va, format);
69 vsnprintf(tmp, MSGSIZE_MAX, mp_gettext(format), va);
70 va_end(va);
71 tmp[MSGSIZE_MAX-2] = '\n';
72 tmp[MSGSIZE_MAX-1] = 0;
74 #if ENABLE_GUI_CODE
75 if(use_gui)
77 switch(x & 255)
79 case MSGL_FATAL:
80 gtkMessageBox(GTK_MB_FATAL|GTK_MB_SIMPLE, tmp);
81 break;
82 case MSGL_ERR:
83 gtkMessageBox(GTK_MB_ERROR|GTK_MB_SIMPLE, tmp);
84 break;
85 #if 0
86 // WARNING! Do NOT enable this! There are too many non-critical messages with
87 // MSGL_WARN, for example: broken SPU packets, codec's bit error messages,
88 // etc etc, they should not raise up a new window every time.
89 case MSGL_WARN:
90 gtkMessageBox(GTK_MB_WARNING|GTK_MB_SIMPLE, tmp);
91 break;
92 #endif
95 #endif
97 #ifdef MSG_USE_COLORS
98 /* that's only a silly color test */
99 #ifdef MP_DEBUG
100 { int c;
101 static int flag=1;
102 if(flag)
103 for(c=0;c<16;c++)
104 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c);
105 flag=0;
107 #endif
108 { unsigned char v_colors[10]={9,9,11,14,15,7,6,5,5,5};
109 int c=v_colors[(x & 255)];
110 fprintf(((x & 255) <= MSGL_WARN)?stderr:stdout, "\033[%d;3%dm",(c>7),c&7);
112 #endif
113 if ((x & 255) <= MSGL_WARN){
114 fprintf(stderr, "%s", tmp);fflush(stderr);
115 } else {
116 printf("%s", tmp);fflush(stdout);
119 #else
120 va_list va;
121 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
122 va_start(va, format);
123 #if ENABLE_GUI_CODE
124 if(use_gui){
125 char tmp[16*80];
126 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0;
127 switch( x&255 ) {
128 case MSGL_FATAL:
129 fprintf( stderr,"%s",tmp );
130 fflush(stderr);
131 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp );
132 break;
133 case MSGL_ERR:
134 fprintf( stderr,"%s",tmp );
135 fflush(stderr);
136 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp );
137 break;
138 case MSGL_WARN:
139 fprintf( stderr, "%s",tmp );
140 fflush(stdout);
141 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp );
142 break;
143 default:
144 fprintf(stderr, "%s",tmp );
145 fflush(stdout);
147 } else
148 #endif
149 if((x&255)<=MSGL_ERR){
150 // fprintf(stderr,"%%%%%% ");
151 vfprintf(stderr,format, va);
152 fflush(stderr);
153 } else {
154 // printf("%%%%%% ");
155 vfprintf(stderr,format, va);
156 fflush(stdout);
158 va_end(va);
159 #endif
162 #else
164 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
165 static FILE* mp_msg_last_file=NULL;
167 // how to handle errors->stderr messages->stdout ?
168 void mp_msg( int x, const char *format, ... ){
169 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display
170 va_list va;
171 va_start(va, format);
172 vfprintf(mp_msg_file[x>>8],format, va);
173 if(mp_msg_last_file!=mp_msg_file[x>>8]){
174 fflush(mp_msg_file[x>>8]);
175 mp_msg_last_file=mp_msg_file[x>>8];
177 va_end(va);
180 #endif