|
1 /* Public Domain Curses */ |
|
2 |
|
3 #include <curspriv.h> |
|
4 |
|
5 RCSID("$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: |
|
17 traceon() and traceoff() toggle the recording of debugging |
|
18 information to the file "trace". Although not standard, similar |
|
19 functions are in some other curses implementations. |
|
20 |
|
21 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() |
|
23 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 |
|
36 bool pdc_trace_on = FALSE; |
|
37 |
|
38 void 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) |
|
46 return; |
|
47 |
|
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 |
|
69 void traceon(void) |
|
70 { |
|
71 PDC_LOG(("traceon() - called\n")); |
|
72 |
|
73 pdc_trace_on = TRUE; |
|
74 } |
|
75 |
|
76 void traceoff(void) |
|
77 { |
|
78 PDC_LOG(("traceoff() - called\n")); |
|
79 |
|
80 pdc_trace_on = FALSE; |
|
81 } |