msg: cosmetic changes

In particular, condense the legacy MSGT_ defines and move them to the
end of the file.
This commit is contained in:
wm4 2013-12-18 16:55:10 +01:00
parent 591a6722d2
commit 5162c2709e
2 changed files with 88 additions and 125 deletions

View File

@ -25,14 +25,14 @@
#include "talloc.h"
#include "config.h"
#include "common/global.h"
#include "osdep/terminal.h"
#include "osdep/io.h"
#include "common/msg.h"
bool mp_msg_stdout_in_use = 0;
/* maximum message length of mp_msg */
#define MSGSIZE_MAX 6144
struct mp_log_root {
/* This should, at some point, contain all mp_msg related state, instead
@ -53,20 +53,19 @@ struct mp_log {
static bool initialized;
static struct mp_log *legacy_logs[MSGT_MAX];
/* maximum message length of mp_msg */
#define MSGSIZE_MAX 6144
bool mp_msg_stdout_in_use;
int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized to -2
int mp_msg_level_all = MSGL_STATUS;
int verbose = 0;
int verbose;
bool mp_msg_mute;
int mp_msg_color = 1;
int mp_msg_module = 0;
int mp_msg_cancolor = 0;
int mp_msg_module;
int mp_msg_cancolor;
static int mp_msg_docolor(void) {
return mp_msg_cancolor && mp_msg_color;
}
// indicate if last line printed ended with \n or \r
static int header = 1;
// indicates if last line printed was a status line
static int statusline;
static void mp_msg_do_init(void){
int i;
@ -95,12 +94,16 @@ bool mp_msg_test_log(struct mp_log *log, int lev)
return mp_msg_test(log->legacy_mod, lev);
}
static int mp_msg_docolor(void)
{
return mp_msg_cancolor && mp_msg_color;
}
static void set_msg_color(FILE* stream, int lev)
{
static const int v_colors[10] = {9, 1, 3, 3, -1, -1, 2, 8, 8, 8};
int c = v_colors[lev];
if (mp_msg_docolor())
terminal_set_foreground_color(stream, c);
terminal_set_foreground_color(stream, v_colors[lev]);
}
static void mp_msg_log_va(struct mp_log *log, int lev, const char *format,
@ -109,14 +112,13 @@ static void mp_msg_log_va(struct mp_log *log, int lev, const char *format,
char tmp[MSGSIZE_MAX];
FILE *stream =
(mp_msg_stdout_in_use || (lev == MSGL_STATUS)) ? stderr : stdout;
static int header = 1;
// indicates if last line printed was a status line
static int statusline;
if (!mp_msg_test_log(log, lev)) return; // do not display
if (!mp_msg_test_log(log, lev))
return; // do not display
vsnprintf(tmp, MSGSIZE_MAX, format, va);
tmp[MSGSIZE_MAX-2] = '\n';
tmp[MSGSIZE_MAX-1] = 0;
tmp[MSGSIZE_MAX - 2] = '\n';
tmp[MSGSIZE_MAX - 1] = 0;
/* A status line is normally intended to be overwritten by the next
* status line, and does not end with a '\n'. If we're printing a normal
@ -135,7 +137,7 @@ static void mp_msg_log_va(struct mp_log *log, int lev, const char *format,
}
size_t len = strlen(tmp);
header = len && (tmp[len-1] == '\n' || tmp[len-1] == '\r');
header = len && (tmp[len - 1] == '\n' || tmp[len - 1] == '\r');
fprintf(stream, "%s", tmp);

View File

@ -30,114 +30,20 @@ struct mp_log;
extern int verbose;
extern bool mp_msg_mute;
extern bool mp_msg_stdout_in_use;
// verbosity elevel:
/* Only messages level MSGL_FATAL-MSGL_STATUS should be translated,
* messages level MSGL_V and above should not be translated. */
#define MSGL_FATAL 0 // will exit/abort
// Verbosity levels.
#define MSGL_FATAL 0 // will exit/abort (note: msg.c doesn't exit or abort)
#define MSGL_ERR 1 // continues
#define MSGL_WARN 2 // only warning
#define MSGL_HINT 3 // short help message
#define MSGL_HINT 3 // (to be phased out)
#define MSGL_INFO 4 // -quiet
#define MSGL_STATUS 5 // v=0
#define MSGL_V 6 // v=1
#define MSGL_DBG2 7 // v=2
#define MSGL_DBG3 8 // v=3
#define MSGL_DBG4 9 // v=4
#define MSGL_DBG5 10 // v=5
#define MSGL_FIXME 1 // for conversions from printf where the appropriate MSGL is not known; set equal to ERR for obtrusiveness
#define MSGT_FIXME 0 // for conversions from printf where the appropriate MSGT is not known; set equal to GLOBAL for obtrusiveness
// code/module:
#define MSGT_GLOBAL 0 // common player stuff errors
#define MSGT_CPLAYER 1 // console player (mplayer.c)
#define MSGT_VO 3 // libvo
#define MSGT_AO 4 // libao
#define MSGT_DEMUXER 5 // demuxer.c (general stuff)
#define MSGT_DS 6 // demux stream (add/read packet etc)
#define MSGT_DEMUX 7 // fileformat-specific stuff (demux_*.c)
#define MSGT_HEADER 8 // fileformat-specific header (*header.c)
#define MSGT_AVSYNC 9 // mplayer.c timer stuff
#define MSGT_AUTOQ 10 // mplayer.c auto-quality stuff
#define MSGT_CFGPARSER 11 // cfgparser.c
#define MSGT_DECAUDIO 12 // av decoder
#define MSGT_DECVIDEO 13
#define MSGT_SEEK 14 // seeking code
#define MSGT_WIN32 15 // win32 dll stuff
#define MSGT_OPEN 16 // open.c (stream opening)
#define MSGT_DVD 17 // open.c (DVD init/read/seek)
#define MSGT_PARSEES 18 // parse_es.c (mpeg stream parser)
#define MSGT_LIRC 19 // lirc_mp.c and input lirc driver
#define MSGT_STREAM 20 // stream.c
#define MSGT_CACHE 21 // cache2.c
#define MSGT_ENCODE 22 // now encode_lavc.c
#define MSGT_XACODEC 23 // XAnim codecs
#define MSGT_TV 24 // TV input subsystem
#define MSGT_OSDEP 25 // OS-dependent parts
#define MSGT_SPUDEC 26 // spudec.c
#define MSGT_PLAYTREE 27 // Playtree handeling (playtree.c, playtreeparser.c)
#define MSGT_INPUT 28
#define MSGT_VFILTER 29
#define MSGT_OSD 30
#define MSGT_NETWORK 31
#define MSGT_CPUDETECT 32
#define MSGT_CODECCFG 33
#define MSGT_SWS 34
#define MSGT_VOBSUB 35
#define MSGT_SUBREADER 36
#define MSGT_AFILTER 37 // Audio filter messages
#define MSGT_NETST 38 // Netstream
#define MSGT_MUXER 39 // muxer layer
#define MSGT_IDENTIFY 41 // -identify output
#define MSGT_RADIO 42
#define MSGT_ASS 43 // libass messages
#define MSGT_LOADER 44 // dll loader messages
#define MSGT_STATUSLINE 45 // playback/encoding status line
#define MSGT_TELETEXT 46 // Teletext decoder
#define MSGT_MAX 47
int mp_msg_test(int mod, int lev);
bool mp_msg_test_log(struct mp_log *log, int lev);
// Note: using mp_msg_log or the MP_ERR/... macros is preferred.
void mp_msg_va(int mod, int lev, const char *format, va_list va);
void mp_msg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
#define MSGL_STATUS 5 // exclusively for the playback status line
#define MSGL_V 6 // -v
#define MSGL_DBG2 7 // -v -v
#define MSGL_DBG3 8 // ...
#define MSGL_DBG4 9 // ....
#define MSGL_DBG5 10 // .....
struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
const char *name);
@ -173,6 +79,61 @@ void mp_msg_uninit(struct mpv_global *global);
struct mpv_global *mp_log_get_global(struct mp_log *log);
extern bool mp_msg_stdout_in_use;
// --- Legacy
// Note: using mp_msg_log or the MP_ERR/... macros is preferred.
int mp_msg_test(int mod, int lev);
bool mp_msg_test_log(struct mp_log *log, int lev);
void mp_msg_va(int mod, int lev, const char *format, va_list va);
void mp_msg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
#define MSGL_FIXME 1 // for conversions from printf where the appropriate MSGL is not known; set equal to ERR for obtrusiveness
#define MSGT_FIXME 0 // for conversions from printf where the appropriate MSGT is not known; set equal to GLOBAL for
#define MSGT_GLOBAL 0 // common player stuff errors
#define MSGT_CPLAYER 1 // console player (mplayer.c)
#define MSGT_VO 3 // libvo
#define MSGT_AO 4 // libao
#define MSGT_DEMUXER 5 // demuxer.c (general stuff)
#define MSGT_DS 6 // demux stream (add/read packet etc)
#define MSGT_DEMUX 7 // fileformat-specific stuff (demux_*.c)
#define MSGT_HEADER 8 // fileformat-specific header (*header.c)
#define MSGT_AVSYNC 9 // mplayer.c timer stuff
#define MSGT_AUTOQ 10 // mplayer.c auto-quality stuff
#define MSGT_CFGPARSER 11 // cfgparser.c
#define MSGT_DECAUDIO 12 // av decoder
#define MSGT_DECVIDEO 13
#define MSGT_SEEK 14 // seeking code
#define MSGT_WIN32 15 // win32 dll stuff
#define MSGT_OPEN 16 // open.c (stream opening)
#define MSGT_DVD 17 // open.c (DVD init/read/seek)
#define MSGT_PARSEES 18 // parse_es.c (mpeg stream parser)
#define MSGT_LIRC 19 // lirc_mp.c and input lirc driver
#define MSGT_STREAM 20 // stream.c
#define MSGT_CACHE 21 // cache2.c
#define MSGT_ENCODE 22 // now encode_lavc.c
#define MSGT_XACODEC 23 // XAnim codecs
#define MSGT_TV 24 // TV input subsystem
#define MSGT_OSDEP 25 // OS-dependent parts
#define MSGT_SPUDEC 26 // spudec.c
#define MSGT_PLAYTREE 27 // Playtree handeling (playtree.c, playtreeparser.c)
#define MSGT_INPUT 28
#define MSGT_VFILTER 29
#define MSGT_OSD 30
#define MSGT_NETWORK 31
#define MSGT_CPUDETECT 32
#define MSGT_CODECCFG 33
#define MSGT_SWS 34
#define MSGT_VOBSUB 35
#define MSGT_SUBREADER 36
#define MSGT_AFILTER 37 // Audio filter messages
#define MSGT_NETST 38 // Netstream
#define MSGT_MUXER 39 // muxer layer
#define MSGT_IDENTIFY 41 // -identify output
#define MSGT_RADIO 42
#define MSGT_ASS 43 // libass messages
#define MSGT_LOADER 44 // dll loader messages
#define MSGT_STATUSLINE 45 // playback/encoding status line
#define MSGT_TELETEXT 46 // Teletext decoder
#define MSGT_MAX 47
#endif /* MPLAYER_MP_MSG_H */