~ubuntu-dev/mplayer/ubuntu-feisty

1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
1
//#define MSG_USE_COLORS
2
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <stdarg.h>
6
#include <string.h>
2 by Reinhard Tartler
upgrade to pre8
7
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
8
#include "config.h"
9
2 by Reinhard Tartler
upgrade to pre8
10
#ifdef USE_LANGINFO
11
#include <locale.h>
12
#include <langinfo.h>
13
#endif
14
#ifdef USE_ICONV
15
#include <iconv.h>
16
#endif
17
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
18
#if	defined(FOR_MENCODER) || defined(CODECS2HTML)
19
#undef HAVE_NEW_GUI
20
#endif
21
22
#ifdef HAVE_NEW_GUI
23
#include "Gui/interface.h"
24
extern int use_gui;
25
#endif
26
#include "mp_msg.h"
27
28
/* maximum message length of mp_msg */
29
#define MSGSIZE_MAX 3072
30
31
int mp_msg_levels[MSGT_MAX]; // verbose level of this module. inited to -2
2 by Reinhard Tartler
upgrade to pre8
32
int mp_msg_level_all = MSGL_STATUS;
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
33
int verbose = 0;
34
#ifdef USE_ICONV
2 by Reinhard Tartler
upgrade to pre8
35
char *mp_msg_charset = NULL;
36
static char *old_charset = NULL;
37
static iconv_t msgiconv;
38
#endif
39
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
40
void mp_msg_init(void){
2 by Reinhard Tartler
upgrade to pre8
41
    int i;
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
42
    char *env = getenv("MPLAYER_VERBOSE");
2 by Reinhard Tartler
upgrade to pre8
43
    if (env)
44
        verbose = atoi(env);
45
    for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2;
46
    mp_msg_levels[MSGT_IDENTIFY] = -1; // no -identify output by default
47
#ifdef USE_ICONV
48
    mp_msg_charset = getenv("MPLAYER_CHARSET");
49
#ifdef USE_LANGINFO
50
    if (!mp_msg_charset) {
51
      setlocale(LC_CTYPE, "");
52
      mp_msg_charset = nl_langinfo(CODESET);
53
      setlocale(LC_CTYPE, "C");
54
    }
55
#endif
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
56
#endif
57
}
58
59
int mp_msg_test(int mod, int lev)
60
{
61
    return lev <= (mp_msg_levels[mod] == -2 ? mp_msg_level_all + verbose : mp_msg_levels[mod]);
62
}
63
64
void mp_msg(int mod, int lev, const char *format, ... ){
65
    va_list va;
66
    char tmp[MSGSIZE_MAX];
67
    
68
    if (!mp_msg_test(mod, lev)) return; // do not display
69
    va_start(va, format);
70
    vsnprintf(tmp, MSGSIZE_MAX, format, va);
2 by Reinhard Tartler
upgrade to pre8
71
    va_end(va);
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
72
    tmp[MSGSIZE_MAX-2] = '\n';
73
    tmp[MSGSIZE_MAX-1] = 0;
74
75
#ifdef HAVE_NEW_GUI
76
    if(use_gui)
77
        guiMessageBox(lev, tmp);
78
#endif
2 by Reinhard Tartler
upgrade to pre8
79
80
#if defined(USE_ICONV) && defined(MSG_CHARSET)
81
    if (mp_msg_charset && strcasecmp(mp_msg_charset, "noconv")) {
82
      char tmp2[MSGSIZE_MAX];
83
      size_t inlen = strlen(tmp), outlen = MSGSIZE_MAX;
84
      char *in = tmp, *out = tmp2;
85
      if (!old_charset || strcmp(old_charset, mp_msg_charset)) {
86
        if (old_charset) {
87
          free(old_charset);
88
          iconv_close(msgiconv);
89
        }
90
        msgiconv = iconv_open(mp_msg_charset, MSG_CHARSET);
91
        old_charset = strdup(mp_msg_charset);
92
      }
93
      if (msgiconv == (iconv_t)(-1)) {
94
        fprintf(stderr,"iconv: conversion from %s to %s unsupported\n"
95
               ,MSG_CHARSET,mp_msg_charset);
2.6.1 by William Grant
Update to 1.0rc1.
96
      }else{
2 by Reinhard Tartler
upgrade to pre8
97
      memset(tmp2, 0, MSGSIZE_MAX);
98
      while (iconv(msgiconv, &in, &inlen, &out, &outlen) == -1) {
99
        if (!inlen || !outlen)
100
          break;
101
        *out++ = *in++;
102
        outlen--; inlen--;
103
      }
104
      strncpy(tmp, tmp2, MSGSIZE_MAX);
105
      tmp[MSGSIZE_MAX-1] = 0;
106
      tmp[MSGSIZE_MAX-2] = '\n';
107
      }
108
    }
109
#endif
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
110
111
#ifdef MSG_USE_COLORS
112
/* that's only a silly color test */
113
#ifdef MP_ANNOY_ME
114
    { int c;
115
      static int flag=1;
116
      if(flag)
117
      for(c=0;c<24;c++)
118
          printf("\033[%d;3%dm***  COLOR TEST %d  ***\n",(c>7),c&7,c);
119
      flag=0;
120
    }
121
#endif    
122
    {	unsigned char v_colors[10]={9,1,3,15,7,2,2,8,8,8};
123
        static const char *lev_text[]= {
124
                                "FATAL",
125
                                "ERROR",
126
                                "WARN",
127
                                "HINT",
128
                                "INFO",
129
                                "STATUS",
130
                                "V",
131
                                "DGB2",
132
                                "DGB3",
133
                                "DGB4"};
134
        static const char *mod_text[]= {
135
                                "GLOBAL",
136
                                "CPLAYER",
137
                                "GPLAYER",
138
                                "VIDEOOUT",
139
                                "AUDIOOUT",
140
                                "DEMUXER",
141
                                "DS",
142
                                "DEMUX",
143
                                "HEADER",
144
                                "AVSYNC",
145
                                "AUTOQ",
146
                                "CFGPARSER",
147
                                "DECAUDIO",
148
                                "DECVIDEO",
149
                                "SEEK",
150
                                "WIN32",
151
                                "OPEN",
152
                                "DVD",
153
                                "PARSEES",
154
                                "LIRC",
155
                                "STREAM",
156
                                "CACHE",
157
                                "MENCODER",
158
                                "XACODEC",
159
                                "TV",
160
                                "OSDEP",
161
                                "SPUDEC",
162
                                "PLAYTREE",
163
                                "INPUT",
164
                                "VFILTER",
165
                                "OSD",
166
                                "NETWORK",
167
                                "CPUDETECT",
168
                                "CODECCFG",
169
                                "SWS",
170
                                "VOBSUB",
171
                                "SUBREADER",
172
                                "AFILTER",
173
                                "NETST",
174
                                "MUXER"};
175
176
        int c=v_colors[lev];
177
        int c2=(mod+1)%15+1;
178
        static int header=1;
179
        FILE *stream= (lev) <= MSGL_WARN ? stderr : stdout;
180
        if(header){
181
            fprintf(stream, "\033[%d;3%dm%9s\033[0;37m: ",c2>>3,c2&7, mod_text[mod]);
182
        }
183
        fprintf(stream, "\033[%d;3%dm",c>>3,c&7);
184
        header=    tmp[strlen(tmp)-1] == '\n'
185
                 ||tmp[strlen(tmp)-1] == '\r';
2 by Reinhard Tartler
upgrade to pre8
186
    }
1 by Reinhard Tartler
imported mplayer_0.99+1.0pre7try2+cvs20060117
187
#endif
188
    if (lev <= MSGL_WARN){
189
	fprintf(stderr, "%s", tmp);fflush(stderr);
190
    } else {
191
	printf("%s", tmp);fflush(stdout);
192
    }
193
}
194