summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-28 23:24:54 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-28 23:33:53 +0100
commit92d106733468893d921dc678296a6716ddf979a4 (patch)
tree4b9d9563c09d90714d273bcaa96b7d3623a4f6a1 /functions.c
parent8a9732c33888462d6fb34f693688e43ff1e31eaa (diff)
Implement debugging to file and set the default configuration file to be that.
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);
}