Mercurial > mplayer.hg
annotate mp_msg.c @ 16378:430ca60471ba
64 bit fix: do not cast pointers to uint32_t
author | reimar |
---|---|
date | Sat, 03 Sep 2005 19:20:51 +0000 |
parents | e2e231134056 |
children | cdd8c0dfc19b |
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 */ |
79 #ifdef MP_DEBUG | |
7200 | 80 { int c; |
81 static int flag=1; | |
82 if(flag) | |
83 for(c=0;c<16;c++) | |
84 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c); | |
85 flag=0; | |
86 } | |
87 #endif | |
88 { unsigned char v_colors[10]={9,9,11,14,15,7,6,5,5,5}; | |
89 int c=v_colors[(x & 255)]; | |
90 fprintf(((x & 255) <= MSGL_WARN)?stderr:stdout, "\033[%d;3%dm",(c>7),c&7); | |
91 } | |
92 #endif | |
7195
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
93 if ((x & 255) <= MSGL_WARN){ |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
94 fprintf(stderr, "%s", tmp);fflush(stderr); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
95 } else { |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
96 printf("%s", tmp);fflush(stdout); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
97 } |
7200 | 98 |
5102 | 99 #else |
1562 | 100 va_list va; |
101 if((x&255)>mp_msg_levels[x>>8]) return; // do not display | |
102 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
|
103 #if ENABLE_GUI_CODE |
1971 | 104 if(use_gui){ |
3293 | 105 char tmp[16*80]; |
1971 | 106 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0; |
107 switch( x&255 ) { | |
1925 | 108 case MSGL_FATAL: |
109 fprintf( stderr,"%s",tmp ); | |
3780 | 110 fflush(stderr); |
1971 | 111 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp ); |
1925 | 112 break; |
113 case MSGL_ERR: | |
114 fprintf( stderr,"%s",tmp ); | |
3780 | 115 fflush(stderr); |
1971 | 116 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp ); |
1925 | 117 break; |
118 case MSGL_WARN: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
119 fprintf( stderr, "%s",tmp ); |
3780 | 120 fflush(stdout); |
1971 | 121 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp ); |
1925 | 122 break; |
123 default: | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
124 fprintf(stderr, "%s",tmp ); |
3780 | 125 fflush(stdout); |
1971 | 126 } |
127 } else | |
128 #endif | |
129 if((x&255)<=MSGL_ERR){ | |
130 // fprintf(stderr,"%%%%%% "); | |
131 vfprintf(stderr,format, va); | |
3780 | 132 fflush(stderr); |
1971 | 133 } else { |
134 // printf("%%%%%% "); | |
4888
cb2adf32c356
Use stdout as default mencoder's output if no filename specified
nick
parents:
4176
diff
changeset
|
135 vfprintf(stderr,format, va); |
3780 | 136 fflush(stdout); |
1971 | 137 } |
138 va_end(va); | |
5102 | 139 #endif |
1562 | 140 } |
141 | |
142 #else | |
143 | |
144 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err) | |
145 static FILE* mp_msg_last_file=NULL; | |
146 | |
147 // how to handle errors->stderr messages->stdout ? | |
148 void mp_msg( int x, const char *format, ... ){ | |
149 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display | |
150 va_list va; | |
151 va_start(va, format); | |
152 vfprintf(mp_msg_file[x>>8],format, va); | |
153 if(mp_msg_last_file!=mp_msg_file[x>>8]){ | |
154 fflush(mp_msg_file[x>>8]); | |
155 mp_msg_last_file=mp_msg_file[x>>8]; | |
156 } | |
157 va_end(va); | |
158 } | |
159 | |
160 #endif |