Rudiments

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