summaryrefslogtreecommitdiffstats
path: root/src/trace.cpp
blob: 5756a56653e05b07c5dfd6bcd7eb959b6cd67ef8 (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 <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, "%s", 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();
    file.close();
  }
}

#endif // ENABLE_TRACER