PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/native/external/espeak/src/debug.cpp

http://eyes-free.googlecode.com/
C++ | 74 lines | 55 code | 13 blank | 6 comment | 8 complexity | 08c4d01904db84384d144b07e0f39d19 MD5 | raw file
 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
10static FILE* fd_log=NULL;
11static const char* FILENAME="/tmp/espeak.log";
12
13void debug_init()
14{
15	if((fd_log = fopen(FILENAME,"a")) != NULL)
16		setvbuf(fd_log, NULL, _IONBF, 0);
17}
18
19void 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
39void 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
56void 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