annotate mp_msg.c @ 2752:b7eb3840b134

Somebody wanna drink some cola?
author lgb
date Tue, 06 Nov 2001 22:58:12 +0000
parents 7d6116e415a3
children fc74fe43eb89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
1
2caba2f48026 new message printing system
arpi
parents:
diff changeset
2 #include <stdio.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
3 #include <stdlib.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
4 #include <stdarg.h>
2caba2f48026 new message printing system
arpi
parents:
diff changeset
5
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
6 #include "config.h"
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
7
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
8 #ifdef HAVE_NEW_GUI
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
9 #include "Gui/mplayer/widgets.h"
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
10 extern void gtkMessageBox( int type,char * str );
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
11 extern int use_gui;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
12 #endif
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
13
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
14 #include "mp_msg.h"
2caba2f48026 new message printing system
arpi
parents:
diff changeset
15
2caba2f48026 new message printing system
arpi
parents:
diff changeset
16 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module
2caba2f48026 new message printing system
arpi
parents:
diff changeset
17
2caba2f48026 new message printing system
arpi
parents:
diff changeset
18 #if 1
2caba2f48026 new message printing system
arpi
parents:
diff changeset
19
2caba2f48026 new message printing system
arpi
parents:
diff changeset
20 void mp_msg_init(int verbose){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
21 int i;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
22 for(i=0;i<MSGT_MAX;i++){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
23 mp_msg_levels[i]=verbose;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
24 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
25 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
26
2caba2f48026 new message printing system
arpi
parents:
diff changeset
27 void mp_msg_c( int x, const char *format, ... ){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
28 va_list va;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
29 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
2caba2f48026 new message printing system
arpi
parents:
diff changeset
30 va_start(va, format);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
31 #ifdef HAVE_NEW_GUI
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
32 if(use_gui){
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
33 char tmp[8*80];
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
34 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0;
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
35 switch( x&255 ) {
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
36 case MSGL_FATAL:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
37 fprintf( stderr,"%s",tmp );
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
38 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
39 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
40 case MSGL_ERR:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
41 fprintf( stderr,"%s",tmp );
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
42 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
43 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
44 case MSGL_WARN:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
45 printf( "%s",tmp );
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
46 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
47 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
48 default:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
49 printf( "%s",tmp );
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
50 }
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
51 } else
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
52 #endif
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
53 if((x&255)<=MSGL_ERR){
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
54 // fprintf(stderr,"%%%%%% ");
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
55 vfprintf(stderr,format, va);
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
56 } else {
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
57 // printf("%%%%%% ");
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
58 vprintf(format, va);
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
59 }
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
60 va_end(va);
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
61 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
62
2caba2f48026 new message printing system
arpi
parents:
diff changeset
63 #else
2caba2f48026 new message printing system
arpi
parents:
diff changeset
64
2caba2f48026 new message printing system
arpi
parents:
diff changeset
65 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
2caba2f48026 new message printing system
arpi
parents:
diff changeset
66 static FILE* mp_msg_last_file=NULL;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
67
2caba2f48026 new message printing system
arpi
parents:
diff changeset
68 // how to handle errors->stderr messages->stdout ?
2caba2f48026 new message printing system
arpi
parents:
diff changeset
69 void mp_msg( int x, const char *format, ... ){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
70 if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display
2caba2f48026 new message printing system
arpi
parents:
diff changeset
71 va_list va;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
72 va_start(va, format);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
73 vfprintf(mp_msg_file[x>>8],format, va);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
74 if(mp_msg_last_file!=mp_msg_file[x>>8]){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
75 fflush(mp_msg_file[x>>8]);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
76 mp_msg_last_file=mp_msg_file[x>>8];
2caba2f48026 new message printing system
arpi
parents:
diff changeset
77 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
78 va_end(va);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
79 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
80
2caba2f48026 new message printing system
arpi
parents:
diff changeset
81 #endif