--- /dev/null
+/*\r
+ * Defines the functions only necessary while debugging is active\r
+ */\r
+\r
+#include "config.h"\r
+\r
+#ifdef DEBUG\r
+\r
+#include <conio.h>\r
+#include <stdarg.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+#include <alloc.h>\r
+\r
+#include "command.h"\r
+\r
+FILE *dbg_logfile = stdout;\r
+char *dbg_logname = 0;\r
+unsigned firstMem = 0;\r
+\r
+void dbg_print(const char * const fmt, ...)\r
+{ va_list ap;\r
+\r
+ va_start(ap, fmt);\r
+ vfprintf(dbg_logfile, fmt, ap);\r
+ va_end(ap);\r
+ fflush(dbg_logfile);\r
+}\r
+\r
+void dbg_outc(int ch)\r
+{ putc(ch, dbg_logfile);\r
+}\r
+void dbg_outs(const char * const s)\r
+{ if(s) fputs(s, dbg_logfile);\r
+ fflush(dbg_logfile);\r
+}\r
+void dbg_outsn(const char * const s)\r
+{ if(s) fputs(s, dbg_logfile);\r
+ putc('\n', dbg_logfile);\r
+ fflush(dbg_logfile);\r
+}\r
+\r
+\r
+void dbg_printmem(void)\r
+{ static unsigned nearLast = 0;\r
+ static unsigned long farLast = 0;\r
+\r
+ unsigned nearThis;\r
+ unsigned long farThis;\r
+\r
+ switch(heapcheck()) {\r
+ case _HEAPCORRUPT:\r
+ cputs("HEAP CORRUPTED. Cannot proceed!\r\n");\r
+ abort();\r
+ case _HEAPEMPTY:\r
+ cputs("NO HEAP. Cannot proceed!\r\n");\r
+ abort();\r
+ default:\r
+ cputs("Unknown heapcheck() error. Cannot proceed!\r\n");\r
+ abort();\r
+ case _HEAPOK:\r
+ break;\r
+ }\r
+\r
+ nearThis = coreleft();\r
+ farThis = farcoreleft();\r
+\r
+ dprintf(("[free memory: near=%6u far=%13lu]\n", nearThis, farThis));\r
+ if(nearLast)\r
+ dprintf(("[changed : near=%6d far=%13ld]\n"\r
+ , nearThis - nearLast , farThis - farLast));\r
+\r
+ nearLast = nearThis;\r
+ farLast = farThis;\r
+}\r
+\r
+#endif /* defined(DEBUG) */\r