diff --git a/curspriv.h b/curspriv.h index 95169c4c..654c2e3d 100644 --- a/curspriv.h +++ b/curspriv.h @@ -50,7 +50,7 @@ typedef struct /* structure for ripped off lines */ #define _DLCHAR 0x15 /* Delete Line char (^U) */ extern WINDOW *pdc_lastscr; -extern bool pdc_trace_on; /* tracing flag */ +extern FILE *pdc_dbfp; /* tracing file pointer (NULL = off) */ extern bool pdc_color_started; extern unsigned long pdc_key_modifiers; extern MOUSE_STATUS pdc_mouse_status; @@ -105,7 +105,7 @@ size_t PDC_wcstombs(char *, const wchar_t *, size_t); #endif #ifdef PDCDEBUG -# define PDC_LOG(x) if (pdc_trace_on) PDC_debug x +# define PDC_LOG(x) if (pdc_dbfp) PDC_debug x #else # define PDC_LOG(x) #endif diff --git a/pdcurses/debug.c b/pdcurses/debug.c index da1b8faf..8321cdca 100644 --- a/pdcurses/debug.c +++ b/pdcurses/debug.c @@ -35,49 +35,50 @@ debug #include #include -bool pdc_trace_on = FALSE; +FILE *pdc_dbfp = NULL; void PDC_debug(const char *fmt, ...) { va_list args; - FILE *dbfp; char hms[9]; time_t now; - if (!pdc_trace_on) + if (!pdc_dbfp) return; - /* open debug log file append */ + time(&now); + strftime(hms, 9, "%H:%M:%S", localtime(&now)); + fprintf(pdc_dbfp, "At: %8.8ld - %s ", (long) clock(), hms); - dbfp = fopen("trace", "a"); - if (!dbfp) + va_start(args, fmt); + vfprintf(pdc_dbfp, fmt, args); + va_end(args); +} + +void traceon(void) +{ + if (pdc_dbfp) + fclose(pdc_dbfp); + + /* open debug log file append */ + pdc_dbfp = fopen("trace", "a"); + if (!pdc_dbfp) { fprintf(stderr, "PDC_debug(): Unable to open debug log file\n"); return; } - time(&now); - strftime(hms, 9, "%H:%M:%S", localtime(&now)); - fprintf(dbfp, "At: %8.8ld - %s ", (long) clock(), hms); - - va_start(args, fmt); - vfprintf(dbfp, fmt, args); - va_end(args); - - fclose(dbfp); -} - -void traceon(void) -{ - pdc_trace_on = TRUE; - PDC_LOG(("traceon() - called\n")); } void traceoff(void) { + if (!pdc_dbfp) + return; + PDC_LOG(("traceoff() - called\n")); - pdc_trace_on = FALSE; + fclose(pdc_dbfp); + pdc_dbfp = NULL; }