From 92d106733468893d921dc678296a6716ddf979a4 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Tue, 28 May 2019 23:24:54 +0100 Subject: Implement debugging to file and set the default configuration file to be that. --- functions.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'functions.c') 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); } -- cgit v1.2.3