Mercurial > mplayer.hg
annotate mp_msg.c @ 9470:3c0bc75f380d
Latest version has the following features:
- --language=ab,cd,ef and --language="ab cd ef" are supported, the list
is now used as a fallback for possible message/gui translations
- --language=all is supported
- --language=ab,cd,ef,all and --language="ab cd ef all" are supported
for all man pages, but different message/gui translations than en
- $LINGUAS is honored
- if no --language or $LINGUAS is given it defaults to en
Credits for ideas go out to (in no particular order):
Tobias Diedrich
Sylvain Petreolle
Dan Christiansen
Dominik Mierzejewski
Andriy N. Gritsenko
and everyone I've forgotten
Andreas Hess <jaska@gmx.net>
author | arpi |
---|---|
date | Thu, 20 Feb 2003 23:32:47 +0000 |
parents | b2e4f9dab7ad |
children | c1247b33c424 |
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 |
1925 | 19 #include "Gui/mplayer/widgets.h" |
20 extern void gtkMessageBox( int type,char * str ); | |
21 extern int use_gui; | |
22 #endif | |
1562 | 23 #include "mp_msg.h" |
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 | 28 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module |
29 | |
30 #if 1 | |
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 |
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)); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
37 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
|
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"); |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
40 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
|
41 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
|
42 #endif |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
43 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
|
44 } |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
45 |
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
46 void mp_msg_set_level(int verbose){ |
1562 | 47 int i; |
48 for(i=0;i<MSGT_MAX;i++){ | |
49 mp_msg_levels[i]=verbose; | |
50 } | |
51 } | |
52 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
53 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
|
54 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
55 return lev <= mp_msg_levels[mod]; |
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 |
1562 | 58 void mp_msg_c( int x, const char *format, ... ){ |
5102 | 59 #if 1 |
60 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
|
61 char tmp[MSGSIZE_MAX]; |
5102 | 62 |
63 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
|
64 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
|
65 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
|
66 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
|
67 tmp[MSGSIZE_MAX-1] = 0; |
5102 | 68 |
8573
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
69 #if ENABLE_GUI_CODE |
5102 | 70 if(use_gui) |
71 { | |
72 switch(x & 255) | |
73 { | |
74 case MSGL_FATAL: | |
75 gtkMessageBox(GTK_MB_FATAL|GTK_MB_SIMPLE, tmp); | |
76 break; | |
77 case MSGL_ERR: | |
78 gtkMessageBox(GTK_MB_ERROR|GTK_MB_SIMPLE, tmp); | |
79 break; | |
7205
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
80 #if 0 |
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
81 // 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
|
82 // 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
|
83 // etc etc, they should not raise up a new window every time. |
7200 | 84 case MSGL_WARN: |
85 gtkMessageBox(GTK_MB_WARNING|GTK_MB_SIMPLE, tmp); | |
86 break; | |
7205
9d11474c39af
WARNING message gui windows disabled, the only critical warn message (too
arpi
parents:
7200
diff
changeset
|
87 #endif |
5102 | 88 } |
89 } | |
90 #endif | |
91 | |
7200 | 92 #ifdef MSG_USE_COLORS |
93 #if 1 | |
94 { int c; | |
95 static int flag=1; | |
96 if(flag) | |
97 for(c=0;c<16;c++) | |
98 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c); | |
99 flag=0; | |
100 } | |
101 #endif | |
102 { unsigned char v_colors[10]={9,9,11,14,15,7,6,5,5,5}; | |
103 int c=v_colors[(x & 255)]; | |
104 fprintf(((x & 255) <= MSGL_WARN)?stderr:stdout, "\033[%d;3%dm",(c>7),c&7); | |
105 } | |
106 #endif | |
7195
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
107 if ((x & 255) <= MSGL_WARN){ |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
108 fprintf(stderr, "%s", tmp);fflush(stderr); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
109 } else { |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
110 printf("%s", tmp);fflush(stdout); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
111 } |
7200 | 112 |
5102 | 113 #else |
1562 | 114 va_list va; |
115 if((x&255)>mp_msg_levels[x>>8]) return; // do not display | |
116 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
|
117 #if ENABLE_GUI_CODE |
1971 | 118 if(use_gui){ |
3293 | 119 char tmp[16*80]; |
1971 | 120 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0; |
121 switch( x&255 ) { | |
1925 | 122 case MSGL_FATAL: |
123 fprintf( stderr,"%s",tmp ); | |
3780 | 124 fflush(stderr); |
1971 | 125 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp ); |
1925 | 126 break; |
127 case MSGL_ERR: | |
128 fprintf( stderr,"%s",tmp ); | |
3780 | 129 fflush(stderr); |
1971 | 130 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp ); |
1925 | 131 break; |
132 case MSGL_WARN: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
133 fprintf( stderr, "%s",tmp ); |
3780 | 134 fflush(stdout); |
1971 | 135 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp ); |
1925 | 136 break; |
137 default: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
138 fprintf(stderr, "%s",tmp ); |
3780 | 139 fflush(stdout); |
1971 | 140 } |
141 } else | |
142 #endif | |
143 if((x&255)<=MSGL_ERR){ | |
144 // fprintf(stderr,"%%%%%% "); | |
145 vfprintf(stderr,format, va); | |
3780 | 146 fflush(stderr); |
1971 | 147 } else { |
148 // printf("%%%%%% "); | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
149 vfprintf(stderr,format, va); |
3780 | 150 fflush(stdout); |
1971 | 151 } |
152 va_end(va); | |
5102 | 153 #endif |
1562 | 154 } |
155 | |
156 #else | |
157 | |
158 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err) | |
159 static FILE* mp_msg_last_file=NULL; | |
160 | |
161 // how to handle errors->stderr messages->stdout ? | |
162 void mp_msg( int x, const char *format, ... ){ | |
163 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display | |
164 va_list va; | |
165 va_start(va, format); | |
166 vfprintf(mp_msg_file[x>>8],format, va); | |
167 if(mp_msg_last_file!=mp_msg_file[x>>8]){ | |
168 fflush(mp_msg_file[x>>8]); | |
169 mp_msg_last_file=mp_msg_file[x>>8]; | |
170 } | |
171 va_end(va); | |
172 } | |
173 | |
174 #endif |