Mercurial > mplayer.hg
annotate mp_msg.c @ 17921:baa1df31e661
insert linebreak, \-playing-msg option
author | kraymer |
---|---|
date | Wed, 22 Mar 2006 18:19:15 +0000 |
parents | 0d7cc103ed1e |
children | ed9950b8200d |
rev | line source |
---|---|
7200 | 1 |
17108
f9a03e3c8e23
1000l, reverting 2 more unrelated changes with last commit
ods15
parents:
17106
diff
changeset
|
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 | |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
10 #ifdef USE_LANGINFO |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
11 #include <locale.h> |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
12 #include <langinfo.h> |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
13 #endif |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
14 #ifdef USE_ICONV |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
15 #include <iconv.h> |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
16 #endif |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
17 |
8573
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
18 #if defined(FOR_MENCODER) || defined(CODECS2HTML) |
16618 | 19 #undef HAVE_NEW_GUI |
8573
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
20 #endif |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
21 |
16618 | 22 #ifdef HAVE_NEW_GUI |
16374
e2e231134056
Remove many annoying GTK includes in every compile line and remove GTK
ods15
parents:
14542
diff
changeset
|
23 #include "Gui/interface.h" |
1925 | 24 extern int use_gui; |
25 #endif | |
1562 | 26 #include "mp_msg.h" |
27 | |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
28 /* 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
|
29 #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
|
30 |
17742
c95961832830
Comment fix: mp_msg_levels[] is inited to -2, not 2.
diego
parents:
17672
diff
changeset
|
31 int mp_msg_levels[MSGT_MAX]; // verbose level of this module. inited to -2 |
17120
637a2f4ff216
Some more cola for msglevel, codec-cfg can't even call mp_msg_init or it'll
ods15
parents:
17108
diff
changeset
|
32 int mp_msg_level_all = MSGL_STATUS; |
637a2f4ff216
Some more cola for msglevel, codec-cfg can't even call mp_msg_init or it'll
ods15
parents:
17108
diff
changeset
|
33 int verbose = 0; |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
34 #ifdef USE_ICONV |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
35 char *mp_msg_charset = NULL; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
36 static char *old_charset = NULL; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
37 static iconv_t msgiconv; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
38 #endif |
1562 | 39 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17440
diff
changeset
|
40 void mp_msg_init(void){ |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
41 int i; |
17440
de9a36b1082c
MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents:
17120
diff
changeset
|
42 char *env = getenv("MPLAYER_VERBOSE"); |
de9a36b1082c
MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents:
17120
diff
changeset
|
43 if (env) |
de9a36b1082c
MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents:
17120
diff
changeset
|
44 verbose = atoi(env); |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
45 #ifdef USE_I18N |
10415 | 46 #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
|
47 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
|
48 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
|
49 fprintf(stdout, "Original dirname: %s\n", bindtextdomain(textdomain(NULL),NULL)); |
10415 | 50 #endif |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
51 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
|
52 textdomain("mplayer"); |
10415 | 53 #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
|
54 fprintf(stdout, "Current domain: %s\n", textdomain(NULL)); |
10415 | 55 fprintf(stdout, "Current dirname: %s\n\n", bindtextdomain(textdomain(NULL),NULL)); |
56 #endif | |
5220
4afbe13150e6
splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents:
5102
diff
changeset
|
57 #endif |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
58 for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2; |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
59 #ifdef USE_ICONV |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
60 mp_msg_charset = getenv("MPLAYER_CHARSET"); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
61 #ifdef USE_LANGINFO |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
62 if (!mp_msg_charset) { |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
63 setlocale(LC_CTYPE, ""); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
64 mp_msg_charset = nl_langinfo(CODESET); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
65 setlocale(LC_CTYPE, "C"); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
66 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
67 #endif |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
68 #endif |
1562 | 69 } |
70 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
71 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
|
72 { |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
73 return lev <= (mp_msg_levels[mod] == -2 ? mp_msg_level_all + verbose : mp_msg_levels[mod]); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
74 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
75 |
16618 | 76 void mp_msg(int mod, int lev, const char *format, ... ){ |
5102 | 77 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
|
78 char tmp[MSGSIZE_MAX]; |
5102 | 79 |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
80 if (!mp_msg_test(mod, lev)) return; // do not display |
5286
30caf02c0eae
10l - va_start needs teh pointer to stack - not the translated message
arpi
parents:
5220
diff
changeset
|
81 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
|
82 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
|
83 va_end(va); |
10853 | 84 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
|
85 tmp[MSGSIZE_MAX-1] = 0; |
5102 | 86 |
16618 | 87 #ifdef HAVE_NEW_GUI |
5102 | 88 if(use_gui) |
16618 | 89 guiMessageBox(lev, tmp); |
5102 | 90 #endif |
91 | |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
92 #if defined(USE_ICONV) && defined(MSG_CHARSET) |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
93 if (mp_msg_charset && strcasecmp(mp_msg_charset, "noconv")) { |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
94 char tmp2[MSGSIZE_MAX]; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
95 size_t inlen = strlen(tmp), outlen = MSGSIZE_MAX; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
96 char *in = tmp, *out = tmp2; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
97 if (!old_charset || strcmp(old_charset, mp_msg_charset)) { |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
98 if (old_charset) { |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
99 free(old_charset); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
100 iconv_close(msgiconv); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
101 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
102 msgiconv = iconv_open(mp_msg_charset, MSG_CHARSET); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
103 old_charset = strdup(mp_msg_charset); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
104 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
105 memset(tmp2, 0, MSGSIZE_MAX); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
106 while (iconv(msgiconv, &in, &inlen, &out, &outlen) == -1) { |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
107 if (!inlen || !outlen) |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
108 break; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
109 *out++ = *in++; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
110 outlen--; inlen--; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
111 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
112 strncpy(tmp, tmp2, MSGSIZE_MAX); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
113 tmp[MSGSIZE_MAX-1] = 0; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
114 tmp[MSGSIZE_MAX-2] = '\n'; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
115 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
116 #endif |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
117 |
7200 | 118 #ifdef MSG_USE_COLORS |
10415 | 119 /* that's only a silly color test */ |
16379 | 120 #ifdef MP_ANNOY_ME |
7200 | 121 { int c; |
122 static int flag=1; | |
123 if(flag) | |
16379 | 124 for(c=0;c<24;c++) |
7200 | 125 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c); |
126 flag=0; | |
127 } | |
128 #endif | |
16379 | 129 { unsigned char v_colors[10]={9,1,3,15,7,2,2,8,8,8}; |
130 static const char *lev_text[]= { | |
131 "FATAL", | |
132 "ERROR", | |
133 "WARN", | |
134 "HINT", | |
135 "INFO", | |
136 "STATUS", | |
137 "V", | |
138 "DGB2", | |
139 "DGB3", | |
140 "DGB4"}; | |
141 static const char *mod_text[]= { | |
142 "GLOBAL", | |
143 "CPLAYER", | |
144 "GPLAYER", | |
145 "VIDEOOUT", | |
146 "AUDIOOUT", | |
147 "DEMUXER", | |
148 "DS", | |
149 "DEMUX", | |
150 "HEADER", | |
151 "AVSYNC", | |
152 "AUTOQ", | |
153 "CFGPARSER", | |
154 "DECAUDIO", | |
155 "DECVIDEO", | |
156 "SEEK", | |
157 "WIN32", | |
158 "OPEN", | |
159 "DVD", | |
160 "PARSEES", | |
161 "LIRC", | |
162 "STREAM", | |
163 "CACHE", | |
164 "MENCODER", | |
165 "XACODEC", | |
166 "TV", | |
167 "OSDEP", | |
168 "SPUDEC", | |
169 "PLAYTREE", | |
170 "INPUT", | |
171 "VFILTER", | |
172 "OSD", | |
173 "NETWORK", | |
174 "CPUDETECT", | |
175 "CODECCFG", | |
176 "SWS", | |
177 "VOBSUB", | |
178 "SUBREADER", | |
179 "AFILTER", | |
180 "NETST", | |
181 "MUXER"}; | |
182 | |
16618 | 183 int c=v_colors[lev]; |
184 int c2=(mod+1)%15+1; | |
16379 | 185 static int header=1; |
16618 | 186 FILE *stream= (lev) <= MSGL_WARN ? stderr : stdout; |
16379 | 187 if(header){ |
16618 | 188 fprintf(stream, "\033[%d;3%dm%9s\033[0;37m: ",c2>>3,c2&7, mod_text[mod]); |
16379 | 189 } |
190 fprintf(stream, "\033[%d;3%dm",c>>3,c&7); | |
191 header= tmp[strlen(tmp)-1] == '\n' | |
17672
b238eeec6ae6
This now works correctly thanks to clear-to-end-of-line patch
ods15
parents:
17566
diff
changeset
|
192 ||tmp[strlen(tmp)-1] == '\r'; |
7200 | 193 } |
194 #endif | |
16618 | 195 if (lev <= MSGL_WARN){ |
7195
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
196 fprintf(stderr, "%s", tmp);fflush(stderr); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
197 } else { |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
198 printf("%s", tmp);fflush(stdout); |
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
199 } |
1562 | 200 } |