summaryrefslogtreecommitdiff
path: root/src/debug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug.cpp')
-rw-r--r--src/debug.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/debug.cpp b/src/debug.cpp
index f697041..f234442 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -19,10 +19,17 @@
// -------------------------------------------------------------------------
//
#include "w32dlib/base.h"
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
namespace W32DLib
{
+// Just to save any cstdio is it a define or function worries
+//
+using namespace std;
+
#ifdef W32D_DEBUG
const char *MsgName(UINT msg)
@@ -217,6 +224,35 @@ const char *MsgName(UINT msg)
}
}
+void W32Debug(const char *func, const char *file, const char *msg)
+{
+ static const char *filter=std::getenv("W32DEBUGFILTER");
+ static FILE *fp=0;
+ int len;
+
+ if (!fp)
+ {
+ fp=fopen("debug.out","w");
+ setbuf(fp,0);
+ }
+
+ if (filter && !std::strstr(filter,file))
+ {
+ return;
+ }
+
+ len=35-std::strlen(func)-std::strlen(file)-3;
+
+ if (len<1)
+ {
+ fprintf(fp,"%s (%s): %s\n",func,file,msg);
+ }
+ else
+ {
+ fprintf(fp,"%s (%s)%-*.*s: %s\n",func,file,len,len,"",msg);
+ }
+}
+
#else
const char *MsgName(UINT msg)
@@ -224,8 +260,57 @@ const char *MsgName(UINT msg)
return "";
}
+void W32Debug(const char *func, const char *file, const char *msg)
+{
+}
+
#endif // W32D_DEBUG
+
+std::string EncodeCString(const char *p)
+{
+ std::string ret("\"");
+
+ while(*p)
+ {
+ switch(*p)
+ {
+ case '"':
+ ret+="\\\"";
+ break;
+
+ case '\r':
+ ret+="\\r";
+ break;
+
+ case '\n':
+ ret+="\\n";
+ break;
+
+ default:
+ if (*p<32 || *p>126)
+ {
+ char s[32];
+
+ sprintf(s,"\\0%o",static_cast<unsigned int>(*p));
+
+ ret+=s;
+ }
+ else
+ {
+ ret+=*p;
+ }
+ break;
+ }
+
+ p++;
+ }
+
+ ret+="\"";
+
+ return ret;
+}
+
}; // namespace W32DLib
// END OF FILE