annotate Gui/error.c @ 3148:58467d46373a

what to do...
author arpi
date Tue, 27 Nov 2001 00:12:12 +0000
parents c65abbc91c5c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
1
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
2 #include <stdlib.h>
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
3 #include <stdio.h>
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
4 #include <stdarg.h>
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
5
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
6 #include "error.h"
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
7
1860
c65abbc91c5c fix mwm bug's. faszom (C), and remove mixer.*
pontscho
parents: 1693
diff changeset
8 int debug_level = 2;
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
9 FILE * debug_file;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
10 int debug_stderr = 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
11
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
12 void defaultErrorHandler( int critical,const char * format, ... )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
13 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
14 char * p;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
15 va_list ap;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
16
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
17 if ( (p=(char *)malloc( 512 ) ) == NULL ) return;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
18 va_start( ap,format );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
19 vsnprintf( p,512,format,ap );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
20 va_end( ap );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
21 fprintf( stderr,"%s",p );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
22 free( p );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
23 if ( critical ) exit( 1 );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
24 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
25
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
26 void defaultDebugHandler( int critical,const char * format, ... )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
27 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
28 char * p;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
29 va_list ap;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
30
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
31 if ( critical >= debug_level ) return;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
32 if ( (p=(char *)malloc( 512 ) ) == NULL ) return;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
33 va_start( ap,format );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
34 vsnprintf( p,512,format,ap );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
35 va_end( ap );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
36 fprintf( debug_file,"%s",p );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
37 free( p );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
38 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
39
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
40 errorTHandler message = defaultErrorHandler;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
41 errorTHandler dbprintf = defaultDebugHandler;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
42
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
43 void initDebug( char * name )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
44 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
45 if ( name )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
46 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
47 if ( ( debug_file=fopen( name,"wt+" ) ) != NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
48 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
49 debug_stderr=0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
50 return;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
51 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
52 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
53 debug_file=stderr;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
54 debug_stderr=1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
55 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
56 void doneDebug( void )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
57 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
58 if ( !debug_stderr ) fclose( debug_file );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
59 debug_file=stderr;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
60 debug_stderr=1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
61 }