annotate mp_msg.c @ 6017:12460040d86b

partial fix
author arpi
date Wed, 08 May 2002 20:53:00 +0000
parents 60cf2bca993f
children 4301077b29d0
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
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
13 #include "mp_msg.h"
2caba2f48026 new message printing system
arpi
parents:
diff changeset
14
2caba2f48026 new message printing system
arpi
parents:
diff changeset
15 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module
2caba2f48026 new message printing system
arpi
parents:
diff changeset
16
2caba2f48026 new message printing system
arpi
parents:
diff changeset
17 #if 1
2caba2f48026 new message printing system
arpi
parents:
diff changeset
18
5220
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
19 void mp_msg_init(){
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
20 #ifdef USE_I18N
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
21 fprintf(stdout, "Using GNU internationalization\n");
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
22 fprintf(stdout, "Original domain: %s\n", textdomain(NULL));
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
23 fprintf(stdout, "Original dirname: %s\n", bindtextdomain(textdomain(NULL),NULL));
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
24 setlocale(LC_ALL, ""); /* set from the environment variables */
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
25 bindtextdomain("mplayer", PREFIX"/share/locale");
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
26 textdomain("mplayer");
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
27 fprintf(stdout, "Current domain: %s\n", textdomain(NULL));
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
28 fprintf(stdout, "Current dirname: %s\n", bindtextdomain(textdomain(NULL),NULL));
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
29 #endif
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
30 mp_msg_set_level(MSGL_STATUS);
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
31 }
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
32
4afbe13150e6 splitted mp_msg_init and mp_msg_set_level and added i18n support to init
alex
parents: 5102
diff changeset
33 void mp_msg_set_level(int verbose){
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
34 int i;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
35 for(i=0;i<MSGT_MAX;i++){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
36 mp_msg_levels[i]=verbose;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
37 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
38 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
39
2caba2f48026 new message printing system
arpi
parents:
diff changeset
40 void mp_msg_c( int x, const char *format, ... ){
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
41 #if 1
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
42 va_list va;
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
43 char tmp[2048];
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
44
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
45 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
5286
30caf02c0eae 10l - va_start needs teh pointer to stack - not the translated message
arpi
parents: 5220
diff changeset
46 va_start(va, format);
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
47 vsnprintf(tmp, 2048, mp_gettext(format), va);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
48 tmp[2047] = 0;
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
49
5919
60cf2bca993f some bug fix
pontscho
parents: 5901
diff changeset
50 #if defined(HAVE_NEW_GUI) && !defined(HAVE_MENCODER)
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
51 if(use_gui)
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
52 {
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
53 switch(x & 255)
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
54 {
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
55 case MSGL_FATAL:
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
56 gtkMessageBox(GTK_MB_FATAL|GTK_MB_SIMPLE, tmp);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
57 break;
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
58 case MSGL_ERR:
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
59 gtkMessageBox(GTK_MB_ERROR|GTK_MB_SIMPLE, tmp);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
60 break;
5919
60cf2bca993f some bug fix
pontscho
parents: 5901
diff changeset
61 // case MSGL_WARN:
60cf2bca993f some bug fix
pontscho
parents: 5901
diff changeset
62 // gtkMessageBox(GTK_MB_WARNING|GTK_MB_SIMPLE, tmp);
60cf2bca993f some bug fix
pontscho
parents: 5901
diff changeset
63 // break;
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
64 }
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
65 }
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
66 #endif
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
67
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
68 fprintf(stderr, "%s", tmp);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
69 if ((x & 255) <= MSGL_ERR)
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
70 fflush(stderr);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
71 else
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
72 fflush(stdout);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
73
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
74 va_end(va);
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
75 #else
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
76 va_list va;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
77 if((x&255)>mp_msg_levels[x>>8]) return; // do not display
2caba2f48026 new message printing system
arpi
parents:
diff changeset
78 va_start(va, format);
5901
6d7131d79ce0 disabling gtk messagebox - fixes gtk crashes
arpi
parents: 5286
diff changeset
79 #if defined( HAVE_NEW_GUI ) && !defined( HAVE_MENCODER ) && 0
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
80 if(use_gui){
3293
fc74fe43eb89 msg limit increased
arpi
parents: 1971
diff changeset
81 char tmp[16*80];
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
82 vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0;
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
83 switch( x&255 ) {
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
84 case MSGL_FATAL:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
85 fprintf( stderr,"%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
86 fflush(stderr);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
87 gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
88 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
89 case MSGL_ERR:
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
90 fprintf( stderr,"%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
91 fflush(stderr);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
92 gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
93 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
94 case MSGL_WARN:
4888
cb2adf32c356 Use stdout as default mencoder's output if no filename specified
nick
parents: 4176
diff changeset
95 fprintf( stderr, "%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
96 fflush(stdout);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
97 gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp );
1925
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
98 break;
633a7f0d72a4 add gui error handling jol.
pontscho
parents: 1566
diff changeset
99 default:
4888
cb2adf32c356 Use stdout as default mencoder's output if no filename specified
nick
parents: 4176
diff changeset
100 fprintf(stderr, "%s",tmp );
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
101 fflush(stdout);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
102 }
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
103 } else
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
104 #endif
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
105 if((x&255)<=MSGL_ERR){
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
106 // fprintf(stderr,"%%%%%% ");
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
107 vfprintf(stderr,format, va);
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
108 fflush(stderr);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
109 } else {
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
110 // printf("%%%%%% ");
4888
cb2adf32c356 Use stdout as default mencoder's output if no filename specified
nick
parents: 4176
diff changeset
111 vfprintf(stderr,format, va);
3780
9eb4aa623ab6 fflush disappeared? .so?
arpi
parents: 3293
diff changeset
112 fflush(stdout);
1971
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
113 }
7d6116e415a3 cleanup
arpi
parents: 1934
diff changeset
114 va_end(va);
5102
17f97ed8259e added i18n support
alex
parents: 4888
diff changeset
115 #endif
1562
2caba2f48026 new message printing system
arpi
parents:
diff changeset
116 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
117
2caba2f48026 new message printing system
arpi
parents:
diff changeset
118 #else
2caba2f48026 new message printing system
arpi
parents:
diff changeset
119
2caba2f48026 new message printing system
arpi
parents:
diff changeset
120 FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
2caba2f48026 new message printing system
arpi
parents:
diff changeset
121 static FILE* mp_msg_last_file=NULL;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
122
2caba2f48026 new message printing system
arpi
parents:
diff changeset
123 // how to handle errors->stderr messages->stdout ?
2caba2f48026 new message printing system
arpi
parents:
diff changeset
124 void mp_msg( int x, const char *format, ... ){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
125 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
126 va_list va;
2caba2f48026 new message printing system
arpi
parents:
diff changeset
127 va_start(va, format);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
128 vfprintf(mp_msg_file[x>>8],format, va);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
129 if(mp_msg_last_file!=mp_msg_file[x>>8]){
2caba2f48026 new message printing system
arpi
parents:
diff changeset
130 fflush(mp_msg_file[x>>8]);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
131 mp_msg_last_file=mp_msg_file[x>>8];
2caba2f48026 new message printing system
arpi
parents:
diff changeset
132 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
133 va_end(va);
2caba2f48026 new message printing system
arpi
parents:
diff changeset
134 }
2caba2f48026 new message printing system
arpi
parents:
diff changeset
135
2caba2f48026 new message printing system
arpi
parents:
diff changeset
136 #endif