-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.c
68 lines (53 loc) · 1.71 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "utils.h"
#ifndef GLOBAL_DEBUG_LEVEL
#define GLOBAL_DEBUG_LEVEL
int globalDebugLevel;
#endif
#ifndef DEBUG_OUTPUT_STREAM
#define DEBUG_OUTPUT_STREAM
FILE *debugOutputStream = NULL;
#endif
void setDebuggingLevel( int debugLevel ) {
globalDebugLevel = debugLevel;
debug( E_INFO, "Debug level set to 0x%X\n", globalDebugLevel );
}
void setDebugOutputStream( FILE *outputStream ) {
if(outputStream ) {
debugOutputStream = outputStream;
}
}
void _debug(int debugType, const char *format, ...) {
if( (globalDebugLevel & debugType) == debugType ) {
va_list args;
va_start(args, format);
vfprintf(debugOutputStream ? debugOutputStream : stdout, format, args);
va_end(args);
}
}
void vdebug( int debugType, const char *format, va_list args ) {
if( (globalDebugLevel & debugType) == debugType ) {
vfprintf(debugOutputStream, format, args);
}
}
void __assert( int assertionValue, const char *srcFilename, int lineNumber,
const char *functionName, char *msgFormat, ... ) {
if( (globalDebugLevel & E_ERROR) != E_ERROR ) return;
if( ! assertionValue ) {
if( debugOutputStream ) {
fprintf( debugOutputStream, "%s:%d %s: ", srcFilename, lineNumber, functionName );
va_list args;
va_start(args, msgFormat);
vfprintf(debugOutputStream, msgFormat, args);
va_end(args);
} else {
fprintf( stdout, "%s:%d %s: ", srcFilename, lineNumber, functionName );
va_list args;
va_start(args, msgFormat);
vfprintf(stdout, msgFormat, args);
va_end(args);
}
}
}