Mercurial > mplayer.hg
annotate mp_msg.c @ 16469:8c1c8d10c163
cycle through tv channels (patch by Andrew Calkin < calkina at geexbox.org >)
author | aurel |
---|---|
date | Mon, 12 Sep 2005 22:48:14 +0000 |
parents | cdd8c0dfc19b |
children | bad73cd81b23 |
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 | |
8573
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
10 #if defined(FOR_MENCODER) || defined(CODECS2HTML) |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
11 #undef ENABLE_GUI_CODE |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
12 #elif defined(HAVE_NEW_GUI) |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
13 #define ENABLE_GUI_CODE HAVE_NEW_GUI |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
14 #else |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
15 #undef ENABLE_GUI_CODE |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
16 #endif |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
17 |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
18 #if ENABLE_GUI_CODE |
16374
e2e231134056
Remove many annoying GTK includes in every compile line and remove GTK
ods15
parents:
14542
diff
changeset
|
19 #include "Gui/interface.h" |
1925 | 20 extern int use_gui; |
21 #endif | |
1562 | 22 #include "mp_msg.h" |
23 | |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
24 /* 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
|
25 #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
|
26 |
1562 | 27 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module |
28 | |
29 #if 1 | |
30 | |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
31 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
|
32 #ifdef USE_I18N |
10415 | 33 #ifdef MP_DEBUG |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
34 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
|
35 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
|
36 fprintf(stdout, "Original dirname: %s\n", bindtextdomain(textdomain(NULL),NULL)); |
10415 | 37 #endif |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
38 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
|
39 textdomain("mplayer"); |
10415 | 40 #ifdef MP_DEBUG |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
41 fprintf(stdout, "Current domain: %s\n", textdomain(NULL)); |
10415 | 42 fprintf(stdout, "Current dirname: %s\n\n", bindtextdomain(textdomain(NULL),NULL)); |
43 #endif | |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
44 #endif |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
45 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
|
46 } |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
47 |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
48 void mp_msg_set_level(int verbose){ |
1562 | 49 int i; |
50 for(i=0;i<MSGT_MAX;i++){ | |
51 mp_msg_levels[i]=verbose; | |
52 } | |
53 } | |
54 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
55 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
|
56 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
57 return lev <= mp_msg_levels[mod]; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
58 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
59 |
1562 | 60 void mp_msg_c( int x, const char *format, ... ){ |
5102 | 61 #if 1 |
62 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
|
63 char tmp[MSGSIZE_MAX]; |
5102 | 64 |
65 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
|
66 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
|
67 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
|
68 va_end(va); |
10853 | 69 tmp[MSGSIZE_MAX-2] = '\n'; |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
70 tmp[MSGSIZE_MAX-1] = 0; |
5102 | 71 |
8573
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
72 #if ENABLE_GUI_CODE |
5102 | 73 if(use_gui) |
16374
e2e231134056
Remove many annoying GTK includes in every compile line and remove GTK
ods15
parents:
14542
diff
changeset
|
74 guiMessageBox(x&255, tmp); |
5102 | 75 #endif |
76 | |
7200 | 77 #ifdef MSG_USE_COLORS |
10415 | 78 /* that's only a silly color test */ |
16379 | 79 #ifdef MP_ANNOY_ME |
7200 | 80 { int c; |
81 static int flag=1; | |
82 if(flag) | |
16379 | 83 for(c=0;c<24;c++) |
7200 | 84 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c); |
85 flag=0; | |
86 } | |
87 #endif | |
16379 | 88 { unsigned char v_colors[10]={9,1,3,15,7,2,2,8,8,8}; |
89 static const char *lev_text[]= { | |
90 "FATAL", | |
91 "ERROR", | |
92 "WARN", | |
93 "HINT", | |
94 "INFO", | |
95 "STATUS", | |
96 "V", | |
97 "DGB2", | |
98 "DGB3", | |
99 "DGB4"}; | |
100 static const char *mod_text[]= { | |
101 "GLOBAL", | |
102 "CPLAYER", | |
103 "GPLAYER", | |
104 "VIDEOOUT", | |
105 "AUDIOOUT", | |
106 "DEMUXER", | |
107 "DS", | |
108 "DEMUX", | |
109 "HEADER", | |
110 "AVSYNC", | |
111 "AUTOQ", | |
112 "CFGPARSER", | |
113 "DECAUDIO", | |
114 "DECVIDEO", | |
115 "SEEK", | |
116 "WIN32", | |
117 "OPEN", | |
118 "DVD", | |
119 "PARSEES", | |
120 "LIRC", | |
121 "STREAM", | |
122 "CACHE", | |
123 "MENCODER", | |
124 "XACODEC", | |
125 "TV", | |
126 "OSDEP", | |
127 "SPUDEC", | |
128 "PLAYTREE", | |
129 "INPUT", | |
130 "VFILTER", | |
131 "OSD", | |
132 "NETWORK", | |
133 "CPUDETECT", | |
134 "CODECCFG", | |
135 "SWS", | |
136 "VOBSUB", | |
137 "SUBREADER", | |
138 "AFILTER", | |
139 "NETST", | |
140 "MUXER"}; | |
141 | |
7200 | 142 int c=v_colors[(x & 255)]; |
16379 | 143 int c2=((x>>8)+1)%15+1; |
144 static int header=1; | |
145 FILE *stream= (x & 255) <= MSGL_WARN ? stderr : stdout; | |
146 if(header){ | |
147 fprintf(stream, "\033[%d;3%dm%9s\033[0;37m: ",c2>>3,c2&7, mod_text[x>>8]); | |
148 } | |
149 fprintf(stream, "\033[%d;3%dm",c>>3,c&7); | |
150 header= tmp[strlen(tmp)-1] == '\n' | |
151 /*||tmp[strlen(tmp)-1] == '\r'*/; | |
7200 | 152 } |
153 #endif | |
7195
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
154 if ((x & 255) <= MSGL_WARN){ |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
155 fprintf(stderr, "%s", tmp);fflush(stderr); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
156 } else { |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
157 printf("%s", tmp);fflush(stdout); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
158 } |
7200 | 159 |
5102 | 160 #else |
1562 | 161 va_list va; |
162 if((x&255)>mp_msg_levels[x>>8]) return; // do not display | |
163 va_start(va, format); | |
8573
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
164 #if ENABLE_GUI_CODE |
1971 | 165 if(use_gui){ |
3293 | 166 char tmp[16*80]; |
1971 | 167 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0; |
168 switch( x&255 ) { | |
1925 | 169 case MSGL_FATAL: |
170 fprintf( stderr,"%s",tmp ); | |
3780 | 171 fflush(stderr); |
1971 | 172 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp ); |
1925 | 173 break; |
174 case MSGL_ERR: | |
175 fprintf( stderr,"%s",tmp ); | |
3780 | 176 fflush(stderr); |
1971 | 177 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp ); |
1925 | 178 break; |
179 case MSGL_WARN: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
180 fprintf( stderr, "%s",tmp ); |
3780 | 181 fflush(stdout); |
1971 | 182 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp ); |
1925 | 183 break; |
184 default: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
185 fprintf(stderr, "%s",tmp ); |
3780 | 186 fflush(stdout); |
1971 | 187 } |
188 } else | |
189 #endif | |
190 if((x&255)<=MSGL_ERR){ | |
191 // fprintf(stderr,"%%%%%% "); | |
192 vfprintf(stderr,format, va); | |
3780 | 193 fflush(stderr); |
1971 | 194 } else { |
195 // printf("%%%%%% "); | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
196 vfprintf(stderr,format, va); |
3780 | 197 fflush(stdout); |
1971 | 198 } |
199 va_end(va); | |
5102 | 200 #endif |
1562 | 201 } |
202 | |
203 #else | |
204 | |
205 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err) | |
206 static FILE* mp_msg_last_file=NULL; | |
207 | |
208 // how to handle errors->stderr messages->stdout ? | |
209 void mp_msg( int x, const char *format, ... ){ | |
210 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display | |
211 va_list va; | |
212 va_start(va, format); | |
213 vfprintf(mp_msg_file[x>>8],format, va); | |
214 if(mp_msg_last_file!=mp_msg_file[x>>8]){ | |
215 fflush(mp_msg_file[x>>8]); | |
216 mp_msg_last_file=mp_msg_file[x>>8]; | |
217 } | |
218 va_end(va); | |
219 } | |
220 | |
221 #endif |