annotate mp_msg.c @ 21653:04cea12cd324

Fix possible crashes with colorized mplayer output
author reimar
date Mon, 18 Dec 2006 18:50:46 +0000
parents 5680696f964b
children ebd2d5efb11b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
1
17108
f9a03e3c8e23 1000l, reverting 2 more unrelated changes with last commit
ods15
parents: 17106
diff changeset
2 //#define MSG_USE_COLORS
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
3
2caba2f48026 new message printing system
arpi
parents:
diff changeset
4 #include <stdio.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
5 #include <stdlib.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
6 #include <stdarg.h>
17972
03170287aea9 10l missing header for strdup
ods15
parents: 17931
diff changeset
7 #include <string.h>
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
8
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
9 #include "config.h"
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
10
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
11 #ifdef USE_LANGINFO
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
12 #include <locale.h>
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
13 #include <langinfo.h>
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
14 #endif
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
15 #ifdef USE_ICONV
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
16 #include <iconv.h>
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
17 #endif
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
18
8573
b2e4f9dab7ad codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents: 7205
diff changeset
19 #if defined(FOR_MENCODER) || defined(CODECS2HTML)
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
20 #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
21 #endif
b2e4f9dab7ad codec-cfg cannot be built when the gui is enabled - it fails to link with a
jkeil
parents: 7205
diff changeset
22
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
23 #ifdef HAVE_NEW_GUI
16374
e2e231134056 Remove many annoying GTK includes in every compile line and remove GTK
ods15
parents: 14542
diff changeset
24 #include "Gui/interface.h"
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
25 extern int use_gui;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
26 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
27 #include "mp_msg.h"
2caba2f48026 new message printing system
arpi
parents:
diff changeset
28
6306
786ab42c10be Extend maximum mp_msg message size, some translations need it or help message will be cutted.
atmos4
parents: 6048
diff changeset
29 /* 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
30 #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
31
17742
c95961832830 Comment fix: mp_msg_levels[] is inited to -2, not 2.
diego
parents: 17672
diff changeset
32 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
33 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
34 int verbose = 0;
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
35 #ifdef USE_ICONV
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
36 char *mp_msg_charset = NULL;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
37 static char *old_charset = NULL;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
38 static iconv_t msgiconv;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
39 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
40
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17440
diff changeset
41 void mp_msg_init(void){
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
42 int i;
17440
de9a36b1082c MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents: 17120
diff changeset
43 char *env = getenv("MPLAYER_VERBOSE");
de9a36b1082c MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents: 17120
diff changeset
44 if (env)
de9a36b1082c MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
ods15
parents: 17120
diff changeset
45 verbose = atoi(env);
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
46 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
47 mp_msg_levels[MSGT_IDENTIFY] = -1; // no -identify output by default
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
48 #ifdef USE_ICONV
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
49 mp_msg_charset = getenv("MPLAYER_CHARSET");
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
50 #ifdef USE_LANGINFO
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
51 if (!mp_msg_charset) {
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
52 setlocale(LC_CTYPE, "");
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
53 mp_msg_charset = nl_langinfo(CODESET);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
54 setlocale(LC_CTYPE, "C");
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
55 }
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
56 #endif
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
57 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
58 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
59
7058
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
60 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
61 {
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
62 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
63 }
2e5c07262861 new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents: 6306
diff changeset
64
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
65 void mp_msg(int mod, int lev, const char *format, ... ){
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
66 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
67 char tmp[MSGSIZE_MAX];
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
68
17106
05af35012e4f new -msglevel option, constrols msg level for every msg module
ods15
parents: 16618
diff changeset
69 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
70 va_start(va, format);
18000
3b4e03cb518d more cruft
rfelker
parents: 17998
diff changeset
71 vsnprintf(tmp, MSGSIZE_MAX, format, va);
7195
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
72 va_end(va);
10853
1e04ac498440 force a new line if a message is very long
pl
parents: 10415
diff changeset
73 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
74 tmp[MSGSIZE_MAX-1] = 0;
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
75
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
76 #ifdef HAVE_NEW_GUI
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
77 if(use_gui)
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
78 guiMessageBox(lev, tmp);
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
79 #endif
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
80
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
81 #if defined(USE_ICONV) && defined(MSG_CHARSET)
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
82 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
83 char tmp2[MSGSIZE_MAX];
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
84 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
85 char *in = tmp, *out = tmp2;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
86 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
87 if (old_charset) {
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
88 free(old_charset);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
89 iconv_close(msgiconv);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
90 }
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
91 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
92 old_charset = strdup(mp_msg_charset);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
93 }
17931
ed9950b8200d The fix in mp_msg.c avoids a core dump when iconv_open() fails, the other
albeu
parents: 17772
diff changeset
94 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
95 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
96 ,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
97 }else{
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
98 memset(tmp2, 0, MSGSIZE_MAX);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
99 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
100 if (!inlen || !outlen)
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
101 break;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
102 *out++ = *in++;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
103 outlen--; inlen--;
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 strncpy(tmp, tmp2, MSGSIZE_MAX);
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
106 tmp[MSGSIZE_MAX-1] = 0;
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
107 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
108 }
17772
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
109 }
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
110 #endif
0d7cc103ed1e Automaticall convert message to console charset, use utf8 for GTK2 Gui
reimar
parents: 17742
diff changeset
111
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
112 #ifdef MSG_USE_COLORS
10415
c1247b33c424 moved some annonying messages to debug mode only
alex
parents: 8573
diff changeset
113 /* that's only a silly color test */
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
114 #ifdef MP_ANNOY_ME
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
115 { int c;
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
116 static int flag=1;
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
117 if(flag)
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
118 for(c=0;c<24;c++)
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
119 printf("\033[%d;3%dm*** COLOR TEST %d ***\n",(c>7),c&7,c);
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
120 flag=0;
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
121 }
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
122 #endif
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
123 { unsigned char v_colors[10]={9,1,3,15,7,2,2,8,8,8};
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
124 static const char *lev_text[]= {
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
125 "FATAL",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
126 "ERROR",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
127 "WARN",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
128 "HINT",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
129 "INFO",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
130 "STATUS",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
131 "V",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
132 "DGB2",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
133 "DGB3",
21653
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
134 "DGB4",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
135 "DBG5",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
136 };
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
137 static const char *mod_text[MSGT_MAX]= {
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
138 "GLOBAL",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
139 "CPLAYER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
140 "GPLAYER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
141 "VIDEOOUT",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
142 "AUDIOOUT",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
143 "DEMUXER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
144 "DS",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
145 "DEMUX",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
146 "HEADER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
147 "AVSYNC",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
148 "AUTOQ",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
149 "CFGPARSER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
150 "DECAUDIO",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
151 "DECVIDEO",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
152 "SEEK",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
153 "WIN32",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
154 "OPEN",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
155 "DVD",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
156 "PARSEES",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
157 "LIRC",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
158 "STREAM",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
159 "CACHE",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
160 "MENCODER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
161 "XACODEC",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
162 "TV",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
163 "OSDEP",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
164 "SPUDEC",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
165 "PLAYTREE",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
166 "INPUT",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
167 "VFILTER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
168 "OSD",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
169 "NETWORK",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
170 "CPUDETECT",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
171 "CODECCFG",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
172 "SWS",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
173 "VOBSUB",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
174 "SUBREADER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
175 "AFILTER",
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
176 "NETST",
21653
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
177 "MUXER",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
178 "OSDMENU",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
179 "IDENTIFY",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
180 "RADIO",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
181 "ASS",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
182 "LOADER",
04cea12cd324 Fix possible crashes with colorized mplayer output
reimar
parents: 19549
diff changeset
183 };
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
184
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
185 int c=v_colors[lev];
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
186 int c2=(mod+1)%15+1;
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
187 static int header=1;
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
188 FILE *stream= (lev) <= MSGL_WARN ? stderr : stdout;
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
189 if(header){
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
190 fprintf(stream, "\033[%d;3%dm%9s\033[0;37m: ",c2>>3,c2&7, mod_text[mod]);
16379
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
191 }
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
192 fprintf(stream, "\033[%d;3%dm",c>>3,c&7);
cdd8c0dfc19b improve colorization
michael
parents: 16374
diff changeset
193 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
194 ||tmp[strlen(tmp)-1] == '\r';
7200
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
195 }
9a123ba671fd - warnings enabled for GUI mode
arpi
parents: 7195
diff changeset
196 #endif
16618
bad73cd81b23 mp_msg cleanup.
ods15
parents: 16379
diff changeset
197 if (lev <= MSGL_WARN){
7195
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
198 fprintf(stderr, "%s", tmp);fflush(stderr);
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
199 } else {
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
200 printf("%s", tmp);fflush(stdout);
a5b2566f3c2b print only fatal/error/warning to stderr, others go to stdout
arpi
parents: 7058
diff changeset
201 }
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
202 }