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