43
|
1 /* {{{ Generic.h - thigns every program does:
|
|
2 *
|
|
3 * - user output (log, debug, etc)
|
|
4 * - crash and burn
|
|
5 * - allocate memory (or explode)
|
|
6 * }}} */
|
|
7 #ifndef GENERIC_H
|
|
8 #define GENERIC_H
|
|
9 #include <stdlib.h>
|
|
10 #include <stdio.h>
|
|
11 #include <stdarg.h>
|
|
12 /***************************************************/
|
|
13
|
|
14 #define LOAD_DEBUG 1
|
|
15
|
|
16 #define DIE(...) { fprintf(stderr, "Fatal Error at %s,%d: ", __FILE__, __LINE__); pDIE(__VA_ARGS__); }
|
|
17
|
|
18 //#define WARN(...) { fprintf(stderr, "WARN: %s,%d: ", __FILE__, __LINE__); pWARN(__VA_ARGS__); }
|
|
19 void pDIE( char *fmt, ... );
|
|
20 //void pWARN( char *fmt, ... );
|
|
21
|
|
22 #define WARN(...) DB( DB_WARN, __VA_ARGS__ )
|
|
23 #define ASSERT(x,...) { if( !(x) ) DIE( __VA_ARGS__ ); }
|
|
24
|
|
25 void *F_MALLOC( size_t size );
|
|
26 void *F_REALLOC( void *p, size_t size );
|
|
27
|
|
28 #define DO_DEBUG 0
|
|
29 #define DEBUG(x) if( DO_DEBUG ) { x; }
|
|
30 #define STUPID_CR "\r\n"
|
|
31
|
|
32 #define DB_CRASH 0 // crashing
|
|
33 #define DB_ERR 1 // error
|
|
34 #define DB_WARN 2 // warning
|
|
35 #define DB_INFO 3 // normal, but significant, condition
|
|
36 #define DB_VERB 4 // verbose information
|
|
37 #define DB_0 5 // debug-level message
|
|
38 #define DB_1 6 // debug-level message
|
|
39 #define DB_2 7 // debug-level message
|
|
40
|
|
41 extern int DEBUG_LEVEL;
|
|
42 extern void (*dbfunc)(char *file, int line, int level, char *fmt, ...);
|
|
43
|
|
44 #define DB(...) { dbfunc( __FILE__, __LINE__, __VA_ARGS__ ); }
|
|
45
|
|
46 int set_db_function( void (*func)( char *file, int line, int level, char *fmt, ...) );
|
|
47
|
|
48 #endif
|