1562
|
1
|
|
2 #include <stdio.h>
|
|
3 #include <stdlib.h>
|
|
4 #include <stdarg.h>
|
|
5
|
1925
|
6 #include "config.h"
|
|
7
|
|
8 #ifdef HAVE_NEW_GUI
|
|
9 #include "Gui/mplayer/widgets.h"
|
|
10 extern void gtkMessageBox( int type,char * str );
|
|
11 extern int use_gui;
|
|
12 #endif
|
|
13
|
1562
|
14 #include "mp_msg.h"
|
|
15
|
|
16 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module
|
|
17
|
|
18 #if 1
|
|
19
|
|
20 void mp_msg_init(int verbose){
|
|
21 int i;
|
|
22 for(i=0;i<MSGT_MAX;i++){
|
|
23 mp_msg_levels[i]=verbose;
|
|
24 }
|
|
25 }
|
|
26
|
|
27 void mp_msg_c( int x, const char *format, ... ){
|
|
28 va_list va;
|
|
29 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
|
|
30 va_start(va, format);
|
1971
|
31 #ifdef HAVE_NEW_GUI
|
|
32 if(use_gui){
|
|
33 char tmp[8*80];
|
|
34 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0;
|
|
35 switch( x&255 ) {
|
1925
|
36 case MSGL_FATAL:
|
|
37 fprintf( stderr,"%s",tmp );
|
1971
|
38 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp );
|
1925
|
39 break;
|
|
40 case MSGL_ERR:
|
|
41 fprintf( stderr,"%s",tmp );
|
1971
|
42 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp );
|
1925
|
43 break;
|
|
44 case MSGL_WARN:
|
|
45 printf( "%s",tmp );
|
1971
|
46 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp );
|
1925
|
47 break;
|
|
48 default:
|
|
49 printf( "%s",tmp );
|
1971
|
50 }
|
|
51 } else
|
|
52 #endif
|
|
53 if((x&255)<=MSGL_ERR){
|
|
54 // fprintf(stderr,"%%%%%% ");
|
|
55 vfprintf(stderr,format, va);
|
|
56 } else {
|
|
57 // printf("%%%%%% ");
|
|
58 vprintf(format, va);
|
|
59 }
|
|
60 va_end(va);
|
1562
|
61 }
|
|
62
|
|
63 #else
|
|
64
|
|
65 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
|
|
66 static FILE* mp_msg_last_file=NULL;
|
|
67
|
|
68 // how to handle errors->stderr messages->stdout ?
|
|
69 void mp_msg( int x, const char *format, ... ){
|
|
70 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display
|
|
71 va_list va;
|
|
72 va_start(va, format);
|
|
73 vfprintf(mp_msg_file[x>>8],format, va);
|
|
74 if(mp_msg_last_file!=mp_msg_file[x>>8]){
|
|
75 fflush(mp_msg_file[x>>8]);
|
|
76 mp_msg_last_file=mp_msg_file[x>>8];
|
|
77 }
|
|
78 va_end(va);
|
|
79 }
|
|
80
|
|
81 #endif
|