1562
|
1
|
|
2 #include <stdio.h>
|
|
3 #include <stdlib.h>
|
|
4 #include <stdarg.h>
|
|
5
|
|
6 #include "mp_msg.h"
|
|
7
|
|
8 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module
|
|
9
|
|
10 #if 1
|
|
11
|
|
12 void mp_msg_init(int verbose){
|
|
13 int i;
|
|
14 for(i=0;i<MSGT_MAX;i++){
|
|
15 mp_msg_levels[i]=verbose;
|
|
16 }
|
|
17 }
|
|
18
|
|
19 void mp_msg_c( int x, const char *format, ... ){
|
|
20 va_list va;
|
|
21 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
|
|
22 va_start(va, format);
|
1563
|
23 if((x&255)<=MSGL_ERR){
|
1566
|
24 // fprintf(stderr,"%%%%%% ");
|
1562
|
25 vfprintf(stderr,format, va);
|
|
26 } else {
|
1566
|
27 // printf("%%%%%% ");
|
1562
|
28 vprintf(format, va);
|
|
29 }
|
|
30 va_end(va);
|
|
31 }
|
|
32
|
|
33 #else
|
|
34
|
|
35 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
|
|
36 static FILE* mp_msg_last_file=NULL;
|
|
37
|
|
38 // how to handle errors->stderr messages->stdout ?
|
|
39 void mp_msg( int x, const char *format, ... ){
|
|
40 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display
|
|
41 va_list va;
|
|
42 va_start(va, format);
|
|
43 vfprintf(mp_msg_file[x>>8],format, va);
|
|
44 if(mp_msg_last_file!=mp_msg_file[x>>8]){
|
|
45 fflush(mp_msg_file[x>>8]);
|
|
46 mp_msg_last_file=mp_msg_file[x>>8];
|
|
47 }
|
|
48 va_end(va);
|
|
49 }
|
|
50
|
|
51 #endif
|