]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Move dprintf and the debug system out into misc.c, to centralise it.
authorSimon Tatham <anakin@pobox.com>
Wed, 1 Nov 2000 19:54:46 +0000 (19:54 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 1 Nov 2000 19:54:46 +0000 (19:54 +0000)
Saves binary space and also allows redirection of debug statements
to a file `debug.log'.

[originally from svn r791]

misc.c
putty.h

diff --git a/misc.c b/misc.c
index 6bb09c535d612db0cae34efe8752af49c6e3a9fb..eb522256eeed7252f6e3fdd058d5c52041772eb9 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -67,3 +67,29 @@ void safefree(void *ptr) {
        fprintf(fp, "freeing null pointer - no action taken\n");
 #endif
 }
+
+#ifdef DEBUG
+static FILE *debug_fp = NULL;
+static int debug_got_console = 0;
+
+void dprintf(char *fmt, ...) {
+    char buf[2048];
+    DWORD dw;
+    va_list ap;
+
+    if (!debug_got_console) {
+       AllocConsole();
+       debug_got_console = 1;
+    }
+    if (!debug_fp) {
+       debug_fp = fopen("debug.log", "w");
+    }
+
+    va_start(ap, fmt);
+    vsprintf(buf, fmt, ap);
+    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
+    fputs(buf, debug_fp);
+    fflush(debug_fp);
+    va_end(ap);
+}
+#endif
diff --git a/putty.h b/putty.h
index bd867f36bc7c07a95e00f394d5fbf893ad71a325..f25930f23d25c1313990a14ba15667fcdb54e7d7 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -400,28 +400,9 @@ void crypto_wrapup();
 void agent_query(void *in, int inlen, void **out, int *outlen);
 int agent_exists(void);
 
-/*
- * A debug system.
- */
 #ifdef DEBUG
-#include <stdarg.h>
+void dprintf(char *fmt, ...);
 #define debug(x) (dprintf x)
-static void dprintf(char *fmt, ...) {
-    char buf[2048];
-    DWORD dw;
-    va_list ap;
-    static int gotconsole = 0;
-
-    if (!gotconsole) {
-       AllocConsole();
-       gotconsole = 1;
-    }
-
-    va_start(ap, fmt);
-    vsprintf(buf, fmt, ap);
-    WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
-    va_end(ap);
-}
 #else
 #define debug(x)
 #endif