summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/functions.c b/functions.c
index 0d4380b..0c814a3 100644
--- a/functions.c
+++ b/functions.c
@@ -2,6 +2,8 @@
// Global debug control
extern int debug;
+extern char debugpath[PATH_MAX];
+extern int background;
// Internal function just to replace nick in server greeting strings
// (as in ":servername 00x oldnick :Blablabla" -> ":servername 00x newnick :Blablabla")
@@ -59,13 +61,26 @@ void updategreetingnick(char *greeting, char *greetingnum, char *newnick, char *
}
// Print debugging output if enabled
+// (To screen or to file depending on settings)
void debugprint(char *format, ...) {
- if (!debug) return;
+ if (debug == DEBUG_NONE) return;
va_list args;
-
va_start(args, format);
- vprintf(format, args);
+
+ if (debug == DEBUG_FILE) {
+ FILE *fp;
+ int bytes = 0;
+ fp = fopen(debugpath, "a");
+ if ((bytes = vfprintf(fp, format, args)) < 0) {
+ printf("error: could not write to debug file.\n");
+ exit(1);
+ }
+ fclose(fp);
+ } else if (debug == DEBUG_SCREEN) {
+ vprintf(format, args);
+ }
+
va_end(args);
}