Restructurisation: moved debug code into general routine, and into aux file
[infodrom/cgilib] / aux.c
diff --git a/aux.c b/aux.c
index e54895c..5a8c72f 100644 (file)
--- a/aux.c
+++ b/aux.c
 
 #include <stdlib.h>
 #include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <syslog.h>
+
+int cgiDebugLevel = 0;
+int cgiDebugType = 1;
 
 char *cgiEscape (char *string)
 {
@@ -78,6 +84,32 @@ char *cgiEscape (char *string)
     return buf;
 }
 
+void cgiDebugOutput (int level, char *format, ...)
+{
+  va_list args;
+
+  if (level <= cgiDebugLevel) {
+
+      va_start (args, format);
+
+      switch (cgiDebugType) {
+      case 0:
+         printf ("<pre>\n");
+         vprintf (format, args);
+         printf ("\n</pre>\n");
+         break;
+      case 1:
+         vfprintf (stderr, format, args);
+         break;
+      case 2:
+         vsyslog (LOG_DEBUG, format, args);
+         break;
+      }
+
+      va_end (args);
+  }
+}
+
 /*
  * Local variables:
  *  c-indent-level: 4