1 #include <stdio.h>
2 #include <stdarg.h>
3 #include "speech.h"
4 #include "debug.h"
5
6 #ifdef DEBUG_ENABLED
7 #include <sys/time.h>
8 #include <unistd.h>
9
10 static FILE* fd_log=NULL;
11 static const char* FILENAME="/tmp/espeak.log";
12
debug_init()13 void debug_init()
14 {
15 if((fd_log = fopen(FILENAME,"a")) != NULL)
16 setvbuf(fd_log, NULL, _IONBF, 0);
17 }
18
debug_enter(const char * text)19 void debug_enter(const char* text)
20 {
21 struct timeval tv;
22
23 gettimeofday(&tv, NULL);
24
25 // fd_log = fopen(FILENAME,"a");
26 if (!fd_log)
27 {
28 debug_init();
29 }
30
31 if (fd_log)
32 {
33 fprintf(fd_log, "%03d.%03dms > ENTER %s\n",(int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text);
34 // fclose(fd_log);
35 }
36 }
37
38
debug_show(const char * format,...)39 void debug_show(const char *format, ...)
40 {
41 va_list args;
42 va_start(args, format);
43 // fd_log = fopen(FILENAME,"a");
44 if (!fd_log)
45 {
46 debug_init();
47 }
48 if (fd_log)
49 {
50 vfprintf(fd_log, format, args);
51 // fclose(fd_log);
52 }
53 va_end(args);
54 }
55
debug_time(const char * text)56 void debug_time(const char* text)
57 {
58 struct timeval tv;
59
60 gettimeofday(&tv, NULL);
61
62 // fd_log = fopen(FILENAME,"a");
63 if (!fd_log)
64 {
65 debug_init();
66 }
67 if (fd_log)
68 {
69 fprintf(fd_log, "%03d.%03dms > %s\n",(int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text);
70 // fclose(fd_log);
71 }
72 }
73
74 #endif
75