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