blob: 812b0ee0408a42ded7e6b8db6293d2874dc210c6 [file] [log] [blame]
Patrick Georgi3b77b722011-07-07 15:41:53 +02001/* Public Domain Curses */
2
3#include <curspriv.h>
4
5RCSID("$Id: debug.c,v 1.7 2008/07/13 16:08:18 wmcbrine Exp $")
6
7/*man-start**************************************************************
8
9 Name: debug
10
11 Synopsis:
12 void traceon(void);
13 void traceoff(void);
14 void PDC_debug(const char *, ...);
15
16 Description:
Stefan Reinauere11835e2011-10-31 12:54:00 -070017 traceon() and traceoff() toggle the recording of debugging
18 information to the file "trace". Although not standard, similar
Patrick Georgi3b77b722011-07-07 15:41:53 +020019 functions are in some other curses implementations.
20
Stefan Reinauere11835e2011-10-31 12:54:00 -070021 PDC_debug() is the function that writes to the file, based on
22 whether traceon() has been called. It's used from the PDC_LOG()
Patrick Georgi3b77b722011-07-07 15:41:53 +020023 macro.
24
25 Portability X/Open BSD SYS V
26 traceon - - -
27 traceoff - - -
28 PDC_debug - - -
29
30**man-end****************************************************************/
31
32#include <string.h>
33#include <sys/types.h>
34#include <time.h>
35
36bool pdc_trace_on = FALSE;
37
38void PDC_debug(const char *fmt, ...)
39{
40 va_list args;
41 FILE *dbfp;
42 char hms[9];
43 time_t now;
44
45 if (!pdc_trace_on)
Stefan Reinauere11835e2011-10-31 12:54:00 -070046 return;
Patrick Georgi3b77b722011-07-07 15:41:53 +020047
48 /* open debug log file append */
49
50 dbfp = fopen("trace", "a");
51 if (!dbfp)
52 {
53 fprintf(stderr,
54 "PDC_debug(): Unable to open debug log file\n");
55 return;
56 }
57
58 time(&now);
59 strftime(hms, 9, "%H:%M:%S", localtime(&now));
60 fprintf(dbfp, "At: %8.8ld - %s ", (long) clock(), hms);
61
62 va_start(args, fmt);
63 vfprintf(dbfp, fmt, args);
64 va_end(args);
65
66 fclose(dbfp);
67}
68
69void traceon(void)
70{
71 PDC_LOG(("traceon() - called\n"));
72
73 pdc_trace_on = TRUE;
74}
75
76void traceoff(void)
77{
78 PDC_LOG(("traceoff() - called\n"));
79
80 pdc_trace_on = FALSE;
81}