Mercurial > mplayer.hg
annotate mp_msg.c @ 8210:e88dffa0c555
removed win32 section - no much sense of separating them now
moved up untested codevs, before the buggy ones
author | arpi |
---|---|
date | Sat, 16 Nov 2002 05:30:43 +0000 |
parents | 9d11474c39af |
children | b2e4f9dab7ad |
rev | line source |
---|---|
7200 | 1 |
2 //#define MSG_USE_COLORS | |
1562 | 3 |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <stdarg.h> | |
7 | |
1925 | 8 #include "config.h" |
9 | |
10 #ifdef HAVE_NEW_GUI | |
11 #include "Gui/mplayer/widgets.h" | |
12 extern void gtkMessageBox( int type,char * str ); | |
13 extern int use_gui; | |
14 #endif | |
1562 | 15 #include "mp_msg.h" |
16 | |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
17 /* maximum message length of mp_msg */ |
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
18 #define MSGSIZE_MAX 3072 |
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
19 |
1562 | 20 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module |
21 | |
22 #if 1 | |
23 | |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
24 void mp_msg_init(){ |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
25 #ifdef USE_I18N |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
26 fprintf(stdout, "Using GNU internationalization\n"); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
27 fprintf(stdout, "Original domain: %s\n", textdomain(NULL)); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
28 fprintf(stdout, "Original dirname: %s\n", bindtextdomain(textdomain(NULL),NULL)); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
29 setlocale(LC_ALL, ""); /* set from the environment variables */ |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
30 bindtextdomain("mplayer", PREFIX"/share/locale"); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
31 textdomain("mplayer"); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
32 fprintf(stdout, "Current domain: %s\n", textdomain(NULL)); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
33 fprintf(stdout, "Current dirname: %s\n", bindtextdomain(textdomain(NULL),NULL)); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
34 #endif |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
35 mp_msg_set_level(MSGL_STATUS); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
36 } |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
37 |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
38 void mp_msg_set_level(int verbose){ |
1562 | 39 int i; |
40 for(i=0;i<MSGT_MAX;i++){ | |
41 mp_msg_levels[i]=verbose; | |
42 } | |
43 } | |
44 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
45 int mp_msg_test(int mod, int lev) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
46 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
47 return lev <= mp_msg_levels[mod]; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
48 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
49 |
1562 | 50 void mp_msg_c( int x, const char *format, ... ){ |
5102 | 51 #if 1 |
52 va_list va; | |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
53 char tmp[MSGSIZE_MAX]; |
5102 | 54 |
55 if((x&255)>mp_msg_levels[x>>8]) return; // do not display | |
5286
30caf02c0eae
10l - va_start needs teh pointer to stack - not the translated message
arpi
parents:
5220
diff
changeset
|
56 va_start(va, format); |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
57 vsnprintf(tmp, MSGSIZE_MAX, mp_gettext(format), va); |
7195
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
58 va_end(va); |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
59 tmp[MSGSIZE_MAX-1] = 0; |
5102 | 60 |
6048
4301077b29d0
HAVE_MENCODER->FOR_MENCODER (forgot to commit some weeks ago...)
arpi
parents:
5919
diff
changeset
|
61 #if defined(HAVE_NEW_GUI) && !defined(FOR_MENCODER) |
5102 | 62 if(use_gui) |
63 { | |
64 switch(x & 255) | |
65 { | |
66 case MSGL_FATAL: | |
67 gtkMessageBox(GTK_MB_FATAL|GTK_MB_SIMPLE, tmp); | |
68 break; | |
69 case MSGL_ERR: | |
70 gtkMessageBox(GTK_MB_ERROR|GTK_MB_SIMPLE, tmp); | |
71 break; | |
7205
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
72 #if 0 |
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
73 // WARNING! Do NOT enable this! There are too many non-critical messages with |
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
74 // MSGL_WARN, for example: broken SPU packets, codec's bit error messages, |
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
75 // etc etc, they should not raise up a new window every time. |
7200 | 76 case MSGL_WARN: |
77 gtkMessageBox(GTK_MB_WARNING|GTK_MB_SIMPLE, tmp); | |
78 break; | |
7205
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
79 #endif |
5102 | 80 } |
81 } | |
82 #endif | |
83 | |
7200 | 84 #ifdef MSG_USE_COLORS |
85 #if 1 | |
86 { int c; | |
87 static int flag=1; | |
88 if(flag) | |
89 for(c=0;c<16;c++) | |
90 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c); | |
91 flag=0; | |
92 } | |
93 #endif | |
94 { unsigned char v_colors[10]={9,9,11,14,15,7,6,5,5,5}; | |
95 int c=v_colors[(x & 255)]; | |
96 fprintf(((x & 255) <= MSGL_WARN)?stderr:stdout, "\033[%d;3%dm",(c>7),c&7); | |
97 } | |
98 #endif | |
7195
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
99 if ((x & 255) <= MSGL_WARN){ |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
100 fprintf(stderr, "%s", tmp);fflush(stderr); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
101 } else { |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
102 printf("%s", tmp);fflush(stdout); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
103 } |
7200 | 104 |
5102 | 105 #else |
1562 | 106 va_list va; |
107 if((x&255)>mp_msg_levels[x>>8]) return; // do not display | |
108 va_start(va, format); | |
6048
4301077b29d0
HAVE_MENCODER->FOR_MENCODER (forgot to commit some weeks ago...)
arpi
parents:
5919
diff
changeset
|
109 #if defined( HAVE_NEW_GUI ) && !defined( FOR_MENCODER ) |
1971 | 110 if(use_gui){ |
3293 | 111 char tmp[16*80]; |
1971 | 112 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0; |
113 switch( x&255 ) { | |
1925 | 114 case MSGL_FATAL: |
115 fprintf( stderr,"%s",tmp ); | |
3780 | 116 fflush(stderr); |
1971 | 117 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp ); |
1925 | 118 break; |
119 case MSGL_ERR: | |
120 fprintf( stderr,"%s",tmp ); | |
3780 | 121 fflush(stderr); |
1971 | 122 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp ); |
1925 | 123 break; |
124 case MSGL_WARN: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
125 fprintf( stderr, "%s",tmp ); |
3780 | 126 fflush(stdout); |
1971 | 127 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp ); |
1925 | 128 break; |
129 default: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
130 fprintf(stderr, "%s",tmp ); |
3780 | 131 fflush(stdout); |
1971 | 132 } |
133 } else | |
134 #endif | |
135 if((x&255)<=MSGL_ERR){ | |
136 // fprintf(stderr,"%%%%%% "); | |
137 vfprintf(stderr,format, va); | |
3780 | 138 fflush(stderr); |
1971 | 139 } else { |
140 // printf("%%%%%% "); | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
141 vfprintf(stderr,format, va); |
3780 | 142 fflush(stdout); |
1971 | 143 } |
144 va_end(va); | |
5102 | 145 #endif |
1562 | 146 } |
147 | |
148 #else | |
149 | |
150 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err) | |
151 static FILE* mp_msg_last_file=NULL; | |
152 | |
153 // how to handle errors->stderr messages->stdout ? | |
154 void mp_msg( int x, const char *format, ... ){ | |
155 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display | |
156 va_list va; | |
157 va_start(va, format); | |
158 vfprintf(mp_msg_file[x>>8],format, va); | |
159 if(mp_msg_last_file!=mp_msg_file[x>>8]){ | |
160 fflush(mp_msg_file[x>>8]); | |
161 mp_msg_last_file=mp_msg_file[x>>8]; | |
162 } | |
163 va_end(va); | |
164 } | |
165 | |
166 #endif |