summaryrefslogtreecommitdiffstats
path: root/src/trace.cpp
blob: effcd64cf5854fabbc1e2af55a9eb90af5aa5a75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifdef ENABLE_TRACING
#include <tqapplication.h>
#include <tqtextedit.h>
#include <tqfile.h>
#include <stdio.h>

static TQTextEdit *tracer = NULL;

void TRACER(TQtMsgType, const char *msg)
{
  tracer->append(&msg[*msg == '~' ? 1 : 0]);
  if (msg[0] != '~')
  {
    fprintf(stderr, msg);
    fprintf(stderr, "\r\n");
  }
}

void INIT_TRACE()
{
  if (tracer) return;     // de javu
  tracer = new TQTextEdit();
  tracer->setTextFormat(TQt::LogText);
  tracer->setMaxLogLines(10000);
  tracer->resize(750, 300);
  qInstallMsgHandler(TRACER);
}

void SHOW_TRACE()
{
  tracer->show();
}

void DUMP_TRACE(const char *f)
{
  TQFile file(f); // Write the text to a file
  if (file.open(IO_WriteOnly))
  {
    TQTextStream stream(&file);
    stream << tracer->text();
  }
}

#endif // ENABLE_TRACER