annotate mp_msg.c @ 13865:33a4b3714458

proper gcc4 compile-fix suggested by richard
author atmos4
date Wed, 03 Nov 2004 17:25:38 +0000
parents 1e04ac498440
children 4a6b79a1ad52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
1
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
2 //#define MSG_USE_COLORS
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
3
2caba2f48026 new message printing system
arpi
parents:
diff changeset
4 #include <stdio.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
5 #include <stdlib.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
6 #include <stdarg.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
7
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
8 #include "config.h"
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
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
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
19 #include "Gui/mplayer/widgets.h"
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
20 extern void gtkMessageBox( int type,char * str );
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
21 extern int use_gui;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
22 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
23 #include "mp_msg.h"
2caba2f48026 new message printing system
arpi
parents:
diff changeset
24
6306
786ab42c10be Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents: 6048
diff changeset
25 /* 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
26 #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
27
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
28 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module
2caba2f48026 new message printing system
arpi
parents:
diff changeset
29
2caba2f48026 new message printing system
arpi
parents:
diff changeset
30 #if 1
2caba2f48026 new message printing system
arpi
parents:
diff changeset
31
5220
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
32 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
33 #ifdef USE_I18N
10415
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
34 #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
35 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
36 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
37 fprintf(stdout, "Original dirname: %s\n", bindtextdomain(textdomain(NULL),NULL));
10415
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
38 #endif
5220
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
39 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
40 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
41 textdomain("mplayer");
10415
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
42 #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
43 fprintf(stdout, "Current domain: %s\n", textdomain(NULL));
10415
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
44 fprintf(stdout, "Current dirname: %s\n\n", bindtextdomain(textdomain(NULL),NULL));
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
45 #endif
5220
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
46 #endif
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
47 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
48 }
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
49
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
50 void mp_msg_set_level(int verbose){
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
51 int i;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
52 for(i=0;i<MSGT_MAX;i++){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
53 mp_msg_levels[i]=verbose;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
54 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
55 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
56
7058
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
57 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
58 {
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
59 return lev <= mp_msg_levels[mod];
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
60 }
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
61
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
62 void mp_msg_c( int x, const char *format, ... ){
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
63 #if 1
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
64 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
65 char tmp[MSGSIZE_MAX];
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
66
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
67 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
68 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
69 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
70 va_end(va);
10853
1e04ac498440 force a new line if a message is very long
pl
parents: 10415
diff changeset
71 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
72 tmp[MSGSIZE_MAX-1] = 0;
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
73
8573
b2e4f9dab7ad codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents: 7205
diff changeset
74 #if ENABLE_GUI_CODE
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
75 if(use_gui)
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
76 {
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
77 switch(x & 255)
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
78 {
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
79 case MSGL_FATAL:
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
80 gtkMessageBox(GTK_MB_FATAL|GTK_MB_SIMPLE, tmp);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
81 break;
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
82 case MSGL_ERR:
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
83 gtkMessageBox(GTK_MB_ERROR|GTK_MB_SIMPLE, tmp);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
84 break;
7205
9d11474c39af WARNING message gui windows disabled, the only critical warn message (too
arpi
parents: 7200
diff changeset
85 #if 0
9d11474c39af WARNING message gui windows disabled, the only critical warn message (too
arpi
parents: 7200
diff changeset
86 // 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
87 // 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
88 // etc etc, they should not raise up a new window every time.
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
89 case MSGL_WARN:
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
90 gtkMessageBox(GTK_MB_WARNING|GTK_MB_SIMPLE, tmp);
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
91 break;
7205
9d11474c39af WARNING message gui windows disabled, the only critical warn message (too
arpi
parents: 7200
diff changeset
92 #endif
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
93 }
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
94 }
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
95 #endif
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
96
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
97 #ifdef MSG_USE_COLORS
10415
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
98 /* that's only a silly color test */
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
99 #ifdef MP_DEBUG
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
100 { int c;
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
101 static int flag=1;
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
102 if(flag)
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
103 for(c=0;c<16;c++)
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
104 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c);
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
105 flag=0;
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
106 }
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
107 #endif
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
108 { unsigned char v_colors[10]={9,9,11,14,15,7,6,5,5,5};
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
109 int c=v_colors[(x & 255)];
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
110 fprintf(((x & 255) <= MSGL_WARN)?stderr:stdout, "\033[%d;3%dm",(c>7),c&7);
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
111 }
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
112 #endif
7195
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
113 if ((x & 255) <= MSGL_WARN){
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
114 fprintf(stderr, "%s", tmp);fflush(stderr);
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
115 } else {
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
116 printf("%s", tmp);fflush(stdout);
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
117 }
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
118
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
119 #else
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
120 va_list va;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
121 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
2caba2f48026 new message printing system
arpi
parents:
diff changeset
122 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
123 #if ENABLE_GUI_CODE
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
124 if(use_gui){
3293
fc74fe43eb89 msg limit increased
arpi
parents: 1971
diff changeset
125 char tmp[16*80];
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
126 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0;
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
127 switch( x&255 ) {
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
128 case MSGL_FATAL:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
129 fprintf( stderr,"%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
130 fflush(stderr);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
131 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
132 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
133 case MSGL_ERR:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
134 fprintf( stderr,"%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
135 fflush(stderr);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
136 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
137 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
138 case MSGL_WARN:
4888
cb2adf32c356 Use stdout as default mencoder's output if no filename specified
nick
parents: 4176
diff changeset
139 fprintf( stderr, "%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
140 fflush(stdout);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
141 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
142 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
143 default:
4888
cb2adf32c356 Use stdout as default mencoder's output if no filename specified
nick
parents: 4176
diff changeset
144 fprintf(stderr, "%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
145 fflush(stdout);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
146 }
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
147 } else
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
148 #endif
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
149 if((x&255)<=MSGL_ERR){
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
150 // fprintf(stderr,"%%%%%% ");
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
151 vfprintf(stderr,format, va);
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
152 fflush(stderr);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
153 } else {
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
154 // printf("%%%%%% ");
4888
cb2adf32c356 Use stdout as default mencoder's output if no filename specified
nick
parents: 4176
diff changeset
155 vfprintf(stderr,format, va);
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
156 fflush(stdout);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
157 }
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
158 va_end(va);
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
159 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
160 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
161
2caba2f48026 new message printing system
arpi
parents:
diff changeset
162 #else
2caba2f48026 new message printing system
arpi
parents:
diff changeset
163
2caba2f48026 new message printing system
arpi
parents:
diff changeset
164 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
2caba2f48026 new message printing system
arpi
parents:
diff changeset
165 static FILE* mp_msg_last_file=NULL;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
166
2caba2f48026 new message printing system
arpi
parents:
diff changeset
167 // how to handle errors->stderr messages->stdout ?
2caba2f48026 new message printing system
arpi
parents:
diff changeset
168 void mp_msg( int x, const char *format, ... ){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
169 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display
2caba2f48026 new message printing system
arpi
parents:
diff changeset
170 va_list va;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
171 va_start(va, format);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
172 vfprintf(mp_msg_file[x>>8],format, va);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
173 if(mp_msg_last_file!=mp_msg_file[x>>8]){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
174 fflush(mp_msg_file[x>>8]);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
175 mp_msg_last_file=mp_msg_file[x>>8];
2caba2f48026 new message printing system
arpi
parents:
diff changeset
176 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
177 va_end(va);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
178 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
179
2caba2f48026 new message printing system
arpi
parents:
diff changeset
180 #endif