annotate mp_msg.c @ 37195:ac6c37d85d65 default tip

configure: Fix initialization of variable def_local_aligned_32 It contiained the #define of HAVE_LOCAL_ALIGNED_16 instead of HAVE_LOCAL_ALIGNED_32.
author al
date Sun, 28 Sep 2014 18:38:41 +0000
parents 389d43c448b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
1 /*
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
2 * This file is part of MPlayer.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
3 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
5 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
7 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
8 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
12 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
13 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
14 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
17 */
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29429
diff changeset
18
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
19 #include <stdio.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
20 #include <stdlib.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
21 #include <stdarg.h>
17972
03170287aea9 10l missing header for strdup
ods15
parents: 17931
diff changeset
22 #include <string.h>
35903
389d43c448b3 Add missing strings.h #includes for strcasecmp().
diego
parents: 32378
diff changeset
23 #include <strings.h>
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
24
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
25 #include "config.h"
30668
46e7233f1faa Properly declare get_term_charset() instead of forward declaring it.
diego
parents: 30429
diff changeset
26 #include "osdep/getch2.h"
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
27
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
28 #ifdef CONFIG_ICONV
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
29 #include <iconv.h>
22002
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
30 #include <errno.h>
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
31 #endif
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
32
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
33 #include "mp_msg.h"
2caba2f48026 new message printing system
arpi
parents:
diff changeset
34
6306
786ab42c10be Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents: 6048
diff changeset
35 /* 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
36 #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
37
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25403
diff changeset
38 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
39 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
40 int verbose = 0;
26370
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
41 int mp_msg_color = 0;
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
42 int mp_msg_module = 0;
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
43 #ifdef CONFIG_ICONV
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
44 char *mp_msg_charset = NULL;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
45 static char *old_charset = NULL;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
46 static iconv_t msgiconv;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
47 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
48
22002
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
49 const char* filename_recode(const char* filename)
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
50 {
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
51 #if !defined(CONFIG_ICONV) || !defined(MSG_CHARSET)
22002
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
52 return filename;
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
53 #else
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
54 static iconv_t inv_msgiconv = (iconv_t)(-1);
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
55 static char recoded_filename[MSGSIZE_MAX];
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
56 size_t filename_len, max_path;
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
57 char* precoded;
22006
b79ca70e0cad Handle mp_msg_charset == NULL correctly in filename_recode.
reimar
parents: 22005
diff changeset
58 if (!mp_msg_charset ||
b79ca70e0cad Handle mp_msg_charset == NULL correctly in filename_recode.
reimar
parents: 22005
diff changeset
59 !strcasecmp(mp_msg_charset, MSG_CHARSET) ||
22005
77c4ad229db6 Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents: 22002
diff changeset
60 !strcasecmp(mp_msg_charset, "noconv"))
77c4ad229db6 Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents: 22002
diff changeset
61 return filename;
22002
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
62 if (inv_msgiconv == (iconv_t)(-1)) {
22005
77c4ad229db6 Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents: 22002
diff changeset
63 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
64 if (inv_msgiconv == (iconv_t)(-1))
77c4ad229db6 Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents: 22002
diff changeset
65 return filename;
22002
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
66 }
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
67 filename_len = strlen(filename);
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
68 max_path = MSGSIZE_MAX - 4;
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
69 precoded = recoded_filename;
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
70 if (iconv(inv_msgiconv, &filename, &filename_len,
22005
77c4ad229db6 Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents: 22002
diff changeset
71 &precoded, &max_path) == (size_t)(-1) && errno == E2BIG) {
77c4ad229db6 Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents: 22002
diff changeset
72 precoded[0] = precoded[1] = precoded[2] = '.';
77c4ad229db6 Cosmetics: remove tabs, almost all added during last patch, from
reimar
parents: 22002
diff changeset
73 precoded += 3;
22002
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
74 }
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
75 *precoded = '\0';
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
76 return recoded_filename;
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
77 #endif
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
78 }
ebd2d5efb11b filename double-conversion, especially usefull for CJK users :-)
gpoirier
parents: 21653
diff changeset
79
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17440
diff changeset
80 void mp_msg_init(void){
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
81 int i;
17440
de9a36b1082c MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents: 17120
diff changeset
82 char *env = getenv("MPLAYER_VERBOSE");
de9a36b1082c MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents: 17120
diff changeset
83 if (env)
de9a36b1082c MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents: 17120
diff changeset
84 verbose = atoi(env);
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
85 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
86 mp_msg_levels[MSGT_IDENTIFY] = -1; // no -identify output by default
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
87 #ifdef CONFIG_ICONV
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
88 mp_msg_charset = getenv("MPLAYER_CHARSET");
22442
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22006
diff changeset
89 if (!mp_msg_charset)
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22006
diff changeset
90 mp_msg_charset = get_term_charset();
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
91 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
92 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
93
7058
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
94 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
95 {
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
96 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
97 }
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
98
26370
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
99 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
100 {
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
101 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
102 int c = v_colors[lev];
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
103 #ifdef MP_ANNOY_ME
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
104 /* that's only a silly color test */
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
105 {
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
106 int c;
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
107 static int flag = 1;
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
108 if (flag)
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
109 for(c = 0; c < 24; c++)
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
110 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
111 flag = 0;
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 #endif
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
114 if (mp_msg_color)
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
115 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
116 }
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
117
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
118 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
119 {
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
120 static const char *module_text[MSGT_MAX] = {
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
121 "GLOBAL",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
122 "CPLAYER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
123 "GPLAYER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
124 "VIDEOOUT",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
125 "AUDIOOUT",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
126 "DEMUXER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
127 "DS",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
128 "DEMUX",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
129 "HEADER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
130 "AVSYNC",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
131 "AUTOQ",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
132 "CFGPARSER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
133 "DECAUDIO",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
134 "DECVIDEO",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
135 "SEEK",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
136 "WIN32",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
137 "OPEN",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
138 "DVD",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
139 "PARSEES",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
140 "LIRC",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
141 "STREAM",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
142 "CACHE",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
143 "MENCODER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
144 "XACODEC",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
145 "TV",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
146 "OSDEP",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
147 "SPUDEC",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
148 "PLAYTREE",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
149 "INPUT",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
150 "VFILTER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
151 "OSD",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
152 "NETWORK",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
153 "CPUDETECT",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
154 "CODECCFG",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
155 "SWS",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
156 "VOBSUB",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
157 "SUBREADER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
158 "AFILTER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
159 "NETST",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
160 "MUXER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
161 "OSDMENU",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
162 "IDENTIFY",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
163 "RADIO",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
164 "ASS",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
165 "LOADER",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
166 "STATUSLINE",
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
167 };
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
168 int c2 = (mod + 1) % 15 + 1;
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
169
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
170 if (!mp_msg_module)
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
171 return;
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
172 if (mp_msg_color)
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
173 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
174 fprintf(stream, "%9s", module_text[mod]);
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
175 if (mp_msg_color)
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
176 fprintf(stream, "\033[0;37m");
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
177 fprintf(stream, ": ");
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
178 }
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
179
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
180 void mp_msg(int mod, int lev, const char *format, ... ){
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
181 va_list va;
32378
150df72e808f Add a va_list version of mp_msg and use it to avoid yet another intermediate
reimar
parents: 31625
diff changeset
182 va_start(va, format);
150df72e808f Add a va_list version of mp_msg and use it to avoid yet another intermediate
reimar
parents: 31625
diff changeset
183 mp_msg_va(mod, lev, format, va);
150df72e808f Add a va_list version of mp_msg and use it to avoid yet another intermediate
reimar
parents: 31625
diff changeset
184 va_end(va);
150df72e808f Add a va_list version of mp_msg and use it to avoid yet another intermediate
reimar
parents: 31625
diff changeset
185 }
150df72e808f Add a va_list version of mp_msg and use it to avoid yet another intermediate
reimar
parents: 31625
diff changeset
186
150df72e808f Add a va_list version of mp_msg and use it to avoid yet another intermediate
reimar
parents: 31625
diff changeset
187 void mp_msg_va(int mod, int lev, const char *format, 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
188 char tmp[MSGSIZE_MAX];
26370
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
189 FILE *stream = lev <= MSGL_WARN ? stderr : stdout;
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
190 static int header = 1;
31625
7c76f46056c9 Avoid status line being mangled together with error messages and other
reimar
parents: 31560
diff changeset
191 // indicates if last line printed was a status line
7c76f46056c9 Avoid status line being mangled together with error messages and other
reimar
parents: 31560
diff changeset
192 static int statusline;
31560
6e550be9e418 Avoid out-of-bounds read if mp_msg prints an empty string.
reimar
parents: 31311
diff changeset
193 size_t len;
25403
e256d72c1f7a cosmetics: Remove trailing whitespace.
diego
parents: 24697
diff changeset
194
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
195 if (!mp_msg_test(mod, lev)) return; // do not display
18000
3b4e03cb518d more cruft
rfelker
parents: 17998
diff changeset
196 vsnprintf(tmp, MSGSIZE_MAX, format, va);
10853
1e04ac498440 force a new line if a message is very long
pl
parents: 10415
diff changeset
197 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
198 tmp[MSGSIZE_MAX-1] = 0;
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
199
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
200 #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
201 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
202 char tmp2[MSGSIZE_MAX];
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
203 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
204 char *in = tmp, *out = tmp2;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
205 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
206 if (old_charset) {
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
207 free(old_charset);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
208 iconv_close(msgiconv);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
209 }
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
210 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
211 old_charset = strdup(mp_msg_charset);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
212 }
17931
ed9950b8200d The fix in mp_msg.c avoids a core dump when iconv_open() fails, the other
albeu
parents: 17772
diff changeset
213 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
214 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
215 ,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
216 }else{
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
217 memset(tmp2, 0, MSGSIZE_MAX);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
218 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
219 if (!inlen || !outlen)
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
220 break;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
221 *out++ = *in++;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
222 outlen--; inlen--;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
223 }
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
224 strncpy(tmp, tmp2, MSGSIZE_MAX);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
225 tmp[MSGSIZE_MAX-1] = 0;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
226 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
227 }
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
228 }
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
229 #endif
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
230
31625
7c76f46056c9 Avoid status line being mangled together with error messages and other
reimar
parents: 31560
diff changeset
231 // as a status line normally is intended to be overwitten by next status line
7c76f46056c9 Avoid status line being mangled together with error messages and other
reimar
parents: 31560
diff changeset
232 // output a '\n' to get a normal message on a separate line
7c76f46056c9 Avoid status line being mangled together with error messages and other
reimar
parents: 31560
diff changeset
233 if (statusline && lev != MSGL_STATUS) fprintf(stream, "\n");
7c76f46056c9 Avoid status line being mangled together with error messages and other
reimar
parents: 31560
diff changeset
234 statusline = lev == MSGL_STATUS;
7c76f46056c9 Avoid status line being mangled together with error messages and other
reimar
parents: 31560
diff changeset
235
26370
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
236 if (header)
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
237 print_msg_module(stream, mod);
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
238 set_msg_color(stream, lev);
31560
6e550be9e418 Avoid out-of-bounds read if mp_msg prints an empty string.
reimar
parents: 31311
diff changeset
239 len = strlen(tmp);
6e550be9e418 Avoid out-of-bounds read if mp_msg prints an empty string.
reimar
parents: 31311
diff changeset
240 header = len && (tmp[len-1] == '\n' || tmp[len-1] == '\r');
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28051
diff changeset
241
26370
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
242 fprintf(stream, "%s", tmp);
30674
553f53cffabf Reset output color after each line.
zuxy
parents: 30668
diff changeset
243 if (mp_msg_color)
553f53cffabf Reset output color after each line.
zuxy
parents: 30668
diff changeset
244 fprintf(stream, "\033[0m");
26370
b450d3591845 Enable runtime control for colorful and/or module name output
zuxy
parents: 25962
diff changeset
245 fflush(stream);
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
246 }