Rudiments

- Main Page
- Classes

debugprint.h
1 // Copyright (c) 1999-2015 David Muse
2 // See the file COPYING for more information
3
4 #ifdef DEBUG_TO_FILE
5 #include <rudiments/file.h>
6 #include <rudiments/permissions.h>
7 static file f;
8 #else
9 #include <rudiments/stdio.h>
10 #endif
11
12 #if (defined(_MSC_VER) && (_MSC_VER <= 1300)) || \
13 (defined(__USLC__) && !defined(__GNUC__))
14
15 // degenerate debug macros for really incapable compilers
16 // (old microsoft compilers, unixware native compiler)
17 static void debugFunction() {}
18 static void debugPrintf(const char *format, ...) {}
19 static void debugSafePrint(const char *data, int32_t length) {}
20 static void debugSafePrint(const unsigned char *data, int32_t length) {}
21 static void debugPrintBits(unsigned char value) {}
22 static void debugPrintBits(uint16_t value) {}
23 static void debugPrintBits(uint32_t value) {}
24 static void debugPrintBits(uint64_t value) {}
25 static void debugPrintBits(char value) {}
26 static void debugPrintBits(int16_t value) {}
27 static void debugPrintBits(int32_t value) {}
28 static void debugPrintBits(int64_t value) {}
29
30 #else
31
32 // working debug macros for more modern compilers
33 #ifdef DEBUG_MESSAGES
34 #ifdef DEBUG_TO_FILE
35 #define debugFunction() { if (f.getFileDescriptor()==-1) { f.dontGetCurrentPropertiesOnOpen(); f.open(debugfile,O_RDWR|O_APPEND|O_CREAT,permissions::evalPermString("rw-r--r--")); } f.printf("%s:%s():%d:\n",__FILE__,__FUNCTION__,__LINE__); }
36 #ifdef _MSC_VER
37 #define debugPrintf(args,...) { if (f.getFileDescriptor()==-1) { f.dontGetCurrentPropertiesOnOpen(); f.open(debugfile,O_RDWR|O_APPEND|O_CREAT,permissions::evalPermString("rw-r--r--")); } f.printf(args,__VA_ARGS__); }
38 #else
39 #define debugPrintf(args...) { if (f.getFileDescriptor()==-1) { f.dontGetCurrentPropertiesOnOpen(); f.open(debugfile,O_RDWR|O_APPEND|O_CREAT,permissions::evalPermString("rw-r--r--")); } f.printf(args); }
40 #endif
41 #define debugSafePrint(a,b) { if (f.getFileDescriptor()==-1) { f.dontGetCurrentPropertiesOnOpen(); f.open(debugfile,O_RDWR|O_APPEND|O_CREAT,permissions::evalPermString("rw-r--r--")); } f.safePrint(a,b); }
42 #define debugPrintBits(a) { if (f.getFileDescriptor()==-1) { f.dontGetCurrentPropertiesOnOpen(); f.open(debugfile,O_RDWR|O_APPEND|O_CREAT,permissions::evalPermString("rw-r--r--")); } f.printBits(a); }
43 #else
44 #define debugFunction() stdoutput.printf("%s:%s():%d:\n",__FILE__,__FUNCTION__,__LINE__); stdoutput.flush();
45 #ifdef _MSC_VER
46 #define debugPrintf(args,...) stdoutput.printf(args,__VA_ARGS__); stdoutput.flush();
47 #else
48 #define debugPrintf(args...) stdoutput.printf(args); stdoutput.flush();
49 #endif
50 #define debugSafePrint(a,b) stdoutput.safePrint(a,b); stdoutput.flush();
51 #define debugPrintBits(a) stdoutput.printBits(a); stdoutput.flush();
52 #endif
53 #else
54 #define debugFunction() /* */
55 #ifdef _MSC_VER
56 #define debugPrintf(args,...) /* */
57 #else
58 #define debugPrintf(args...) /* */
59 #endif
60 #define debugSafePrint(a,b) /* */
61 #define debugPrintBits(a) /* */
62 #endif
63
64 #endif
file
Definition: file.h:21