Mercurial > mplayer.hg
annotate mp_msg.c @ 29737:25166964e1ec
Merge rules for building mencoder and mplayer.
Just the dependencies are different, so specify them separately.
author | diego |
---|---|
date | Sun, 18 Oct 2009 18:44:51 +0000 |
parents | 2d14b0b53d8e |
children | c1a3f1bbba26 |
rev | line source |
---|---|
1562 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <stdarg.h> | |
17972 | 4 #include <string.h> |
1562 | 5 |
1925 | 6 #include "config.h" |
7 | |
27393 | 8 #ifdef CONFIG_ICONV |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
9 #include <iconv.h> |
22002
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
10 #include <errno.h> |
29290
ef46d5a66bb2
Use a malloced string for the get_term_charset return value.
reimar
parents:
29263
diff
changeset
|
11 /** |
ef46d5a66bb2
Use a malloced string for the get_term_charset return value.
reimar
parents:
29263
diff
changeset
|
12 * \brief gets the name of the system's terminal character set |
ef46d5a66bb2
Use a malloced string for the get_term_charset return value.
reimar
parents:
29263
diff
changeset
|
13 * \return a malloced string indicating the system charset |
ef46d5a66bb2
Use a malloced string for the get_term_charset return value.
reimar
parents:
29263
diff
changeset
|
14 * |
ef46d5a66bb2
Use a malloced string for the get_term_charset return value.
reimar
parents:
29263
diff
changeset
|
15 * Be warned that this function on many systems is in no way thread-safe |
ef46d5a66bb2
Use a malloced string for the get_term_charset return value.
reimar
parents:
29263
diff
changeset
|
16 * since it modifies global data |
ef46d5a66bb2
Use a malloced string for the get_term_charset return value.
reimar
parents:
29263
diff
changeset
|
17 */ |
28051 | 18 char* get_term_charset(void); |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
19 #endif |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
20 |
22517 | 21 #if defined(FOR_MENCODER) |
27343 | 22 #undef CONFIG_GUI |
24697
8f2154e066cf
Make sure forked code does not try to display a GTK message box (and thus crashes)
reimar
parents:
24121
diff
changeset
|
23 int use_gui; |
29429
2d14b0b53d8e
Remove pointless #ifdefs around harmless internal header #includes.
diego
parents:
29290
diff
changeset
|
24 #else |
2d14b0b53d8e
Remove pointless #ifdefs around harmless internal header #includes.
diego
parents:
29290
diff
changeset
|
25 #include "gui/interface.h" |
8573
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
26 #endif |
b2e4f9dab7ad
codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents:
7205
diff
changeset
|
27 |
1562 | 28 #include "mp_msg.h" |
29 | |
6306
786ab42c10be
Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents:
6048
diff
changeset
|
30 /* 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
|
31 #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
|
32 |
25962 | 33 int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized 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
|
34 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
|
35 int verbose = 0; |
26370
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
36 int mp_msg_color = 0; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
37 int mp_msg_module = 0; |
27393 | 38 #ifdef CONFIG_ICONV |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
39 char *mp_msg_charset = NULL; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
40 static char *old_charset = NULL; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
41 static iconv_t msgiconv; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
42 #endif |
1562 | 43 |
22002
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
44 const char* filename_recode(const char* filename) |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
45 { |
27393 | 46 #if !defined(CONFIG_ICONV) || !defined(MSG_CHARSET) |
22002
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
47 return filename; |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
48 #else |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
49 static iconv_t inv_msgiconv = (iconv_t)(-1); |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
50 static char recoded_filename[MSGSIZE_MAX]; |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
51 size_t filename_len, max_path; |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
52 char* precoded; |
22006
b79ca70e0cad
Handle mp_msg_charset == NULL correctly in filename_recode.
reimar
parents:
22005
diff
changeset
|
53 if (!mp_msg_charset || |
b79ca70e0cad
Handle mp_msg_charset == NULL correctly in filename_recode.
reimar
parents:
22005
diff
changeset
|
54 !strcasecmp(mp_msg_charset, MSG_CHARSET) || |
22005
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
55 !strcasecmp(mp_msg_charset, "noconv")) |
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
56 return filename; |
22002
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
57 if (inv_msgiconv == (iconv_t)(-1)) { |
22005
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
58 inv_msgiconv = iconv_open(MSG_CHARSET, mp_msg_charset); |
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
59 if (inv_msgiconv == (iconv_t)(-1)) |
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
60 return filename; |
22002
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
61 } |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
62 filename_len = strlen(filename); |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
63 max_path = MSGSIZE_MAX - 4; |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
64 precoded = recoded_filename; |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
65 if (iconv(inv_msgiconv, &filename, &filename_len, |
22005
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
66 &precoded, &max_path) == (size_t)(-1) && errno == E2BIG) { |
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
67 precoded[0] = precoded[1] = precoded[2] = '.'; |
77c4ad229db6
Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents:
22002
diff
changeset
|
68 precoded += 3; |
22002
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
69 } |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
70 *precoded = '\0'; |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
71 return recoded_filename; |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
72 #endif |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
73 } |
ebd2d5efb11b
filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents:
21653
diff
changeset
|
74 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17440
diff
changeset
|
75 void mp_msg_init(void){ |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
76 int i; |
17440
de9a36b1082c
MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents:
17120
diff
changeset
|
77 char *env = getenv("MPLAYER_VERBOSE"); |
de9a36b1082c
MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents:
17120
diff
changeset
|
78 if (env) |
de9a36b1082c
MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents:
17120
diff
changeset
|
79 verbose = atoi(env); |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
80 for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2; |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
18000
diff
changeset
|
81 mp_msg_levels[MSGT_IDENTIFY] = -1; // no -identify output by default |
27393 | 82 #ifdef CONFIG_ICONV |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
83 mp_msg_charset = getenv("MPLAYER_CHARSET"); |
22442
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22006
diff
changeset
|
84 if (!mp_msg_charset) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22006
diff
changeset
|
85 mp_msg_charset = get_term_charset(); |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
86 #endif |
1562 | 87 } |
88 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
89 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
|
90 { |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
91 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
|
92 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6306
diff
changeset
|
93 |
26370
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
94 static void set_msg_color(FILE* stream, int lev) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
95 { |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
96 static const unsigned char v_colors[10] = {9, 1, 3, 15, 7, 2, 2, 8, 8, 8}; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
97 int c = v_colors[lev]; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
98 #ifdef MP_ANNOY_ME |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
99 /* that's only a silly color test */ |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
100 { |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
101 int c; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
102 static int flag = 1; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
103 if (flag) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
104 for(c = 0; c < 24; c++) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
105 printf("\033[%d;3%dm*** COLOR TEST %d ***\n", c>7, c&7, c); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
106 flag = 0; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
107 } |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
108 #endif |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
109 if (mp_msg_color) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
110 fprintf(stream, "\033[%d;3%dm", c >> 3, c & 7); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
111 } |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
112 |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
113 static void print_msg_module(FILE* stream, int mod) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
114 { |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
115 static const char *module_text[MSGT_MAX] = { |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
116 "GLOBAL", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
117 "CPLAYER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
118 "GPLAYER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
119 "VIDEOOUT", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
120 "AUDIOOUT", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
121 "DEMUXER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
122 "DS", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
123 "DEMUX", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
124 "HEADER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
125 "AVSYNC", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
126 "AUTOQ", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
127 "CFGPARSER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
128 "DECAUDIO", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
129 "DECVIDEO", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
130 "SEEK", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
131 "WIN32", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
132 "OPEN", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
133 "DVD", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
134 "PARSEES", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
135 "LIRC", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
136 "STREAM", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
137 "CACHE", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
138 "MENCODER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
139 "XACODEC", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
140 "TV", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
141 "OSDEP", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
142 "SPUDEC", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
143 "PLAYTREE", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
144 "INPUT", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
145 "VFILTER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
146 "OSD", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
147 "NETWORK", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
148 "CPUDETECT", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
149 "CODECCFG", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
150 "SWS", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
151 "VOBSUB", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
152 "SUBREADER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
153 "AFILTER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
154 "NETST", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
155 "MUXER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
156 "OSDMENU", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
157 "IDENTIFY", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
158 "RADIO", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
159 "ASS", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
160 "LOADER", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
161 "STATUSLINE", |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
162 }; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
163 int c2 = (mod + 1) % 15 + 1; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
164 |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
165 if (!mp_msg_module) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
166 return; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
167 if (mp_msg_color) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
168 fprintf(stream, "\033[%d;3%dm", c2 >> 3, c2 & 7); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
169 fprintf(stream, "%9s", module_text[mod]); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
170 if (mp_msg_color) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
171 fprintf(stream, "\033[0;37m"); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
172 fprintf(stream, ": "); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
173 } |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
174 |
16618 | 175 void mp_msg(int mod, int lev, const char *format, ... ){ |
5102 | 176 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
|
177 char tmp[MSGSIZE_MAX]; |
26370
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
178 FILE *stream = lev <= MSGL_WARN ? stderr : stdout; |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
179 static int header = 1; |
25403 | 180 |
17106
05af35012e4f
new -msglevel option, constrols msg level for every msg module
ods15
parents:
16618
diff
changeset
|
181 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
|
182 va_start(va, format); |
18000 | 183 vsnprintf(tmp, MSGSIZE_MAX, format, va); |
7195
a5b2566f3c2b
print only fatal/error/warning to stderr, others go to stdout
arpi
parents:
7058
diff
changeset
|
184 va_end(va); |
10853 | 185 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
|
186 tmp[MSGSIZE_MAX-1] = 0; |
5102 | 187 |
27343 | 188 #ifdef CONFIG_GUI |
5102 | 189 if(use_gui) |
16618 | 190 guiMessageBox(lev, tmp); |
5102 | 191 #endif |
192 | |
27393 | 193 #if defined(CONFIG_ICONV) && defined(MSG_CHARSET) |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
194 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
|
195 char tmp2[MSGSIZE_MAX]; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
196 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
|
197 char *in = tmp, *out = tmp2; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
198 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
|
199 if (old_charset) { |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
200 free(old_charset); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
201 iconv_close(msgiconv); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
202 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
203 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
|
204 old_charset = strdup(mp_msg_charset); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
205 } |
17931
ed9950b8200d
The fix in mp_msg.c avoids a core dump when iconv_open() fails, the other
albeu
parents:
17772
diff
changeset
|
206 if (msgiconv == (iconv_t)(-1)) { |
ed9950b8200d
The fix in mp_msg.c avoids a core dump when iconv_open() fails, the other
albeu
parents:
17772
diff
changeset
|
207 fprintf(stderr,"iconv: conversion from %s to %s unsupported\n" |
19549
5680696f964b
Mixed up from and to charsets in iconv open failure message.
reimar
parents:
18237
diff
changeset
|
208 ,MSG_CHARSET,mp_msg_charset); |
17931
ed9950b8200d
The fix in mp_msg.c avoids a core dump when iconv_open() fails, the other
albeu
parents:
17772
diff
changeset
|
209 }else{ |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
210 memset(tmp2, 0, MSGSIZE_MAX); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
211 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
|
212 if (!inlen || !outlen) |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
213 break; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
214 *out++ = *in++; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
215 outlen--; inlen--; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
216 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
217 strncpy(tmp, tmp2, MSGSIZE_MAX); |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
218 tmp[MSGSIZE_MAX-1] = 0; |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
219 tmp[MSGSIZE_MAX-2] = '\n'; |
17931
ed9950b8200d
The fix in mp_msg.c avoids a core dump when iconv_open() fails, the other
albeu
parents:
17772
diff
changeset
|
220 } |
17772
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
221 } |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
222 #endif |
0d7cc103ed1e
Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents:
17742
diff
changeset
|
223 |
26370
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
224 if (header) |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
225 print_msg_module(stream, mod); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
226 set_msg_color(stream, lev); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
227 header = tmp[strlen(tmp)-1] == '\n' || tmp[strlen(tmp)-1] == '\r'; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
228 |
26370
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
229 fprintf(stream, "%s", tmp); |
b450d3591845
Enable runtime control for colorful and/or module name output
zuxy
parents:
25962
diff
changeset
|
230 fflush(stream); |
1562 | 231 } |