My Project
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
debug.cpp
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
*
4
*
5
* Copyright (C) 1997-2015 by Dimitri van Heesch.
6
*
7
* Permission to use, copy, modify, and distribute this software and its
8
* documentation under the terms of the GNU General Public License is hereby
9
* granted. No representations are made about the suitability of this software
10
* for any purpose. It is provided "as is" without express or implied warranty.
11
* See the GNU General Public License for more details.
12
*
13
* Documents produced by Doxygen are derivative works derived from the
14
* input used in their production; they are not affected by this license.
15
*
16
*/
17
18
#include <stdarg.h>
19
#include <stdio.h>
20
21
#include <qdict.h>
22
23
#include "
debug.h
"
24
#include "
message.h
"
25
26
//------------------------------------------------------------------------
27
29
struct
LabelMap
30
{
31
const
char
*
name
;
32
Debug::DebugMask
event
;
33
};
34
35
static
LabelMap
s_labels
[] =
36
{
37
{
"findmembers"
,
Debug::FindMembers
},
38
{
"functions"
,
Debug::Functions
},
39
{
"variables"
,
Debug::Variables
},
40
{
"preprocessor"
,
Debug::Preprocessor
},
41
{
"classes"
,
Debug::Classes
},
42
{
"commentcnv"
,
Debug::CommentCnv
},
43
{
"commentscan"
,
Debug::CommentScan
},
44
{
"validate"
,
Debug::Validate
},
45
{
"printtree"
,
Debug::PrintTree
},
46
{
"time"
,
Debug::Time
},
47
{
"extcmd"
,
Debug::ExtCmd
},
48
{
"markdown"
,
Debug::Markdown
},
49
{
"filteroutput"
,
Debug::FilterOutput
},
50
{
"lex"
,
Debug::Lex
},
51
{ 0, (
Debug::DebugMask
)0 }
52
};
53
55
class
LabelMapper
56
{
57
public
:
58
LabelMapper
() :
m_map
(17)
59
{
60
m_map
.setAutoDelete(TRUE);
61
LabelMap
*p =
s_labels
;
62
while
(p->
name
)
63
{
64
m_map
.insert(p->
name
,
new
Debug::DebugMask
(p->
event
));
65
p++;
66
}
67
}
68
Debug::DebugMask
*
find
(
const
char
*s)
const
69
{
70
if
(s==0)
return
0;
71
return
m_map
.find(s);
72
}
73
private
:
74
QDict<Debug::DebugMask>
m_map
;
75
};
76
77
static
LabelMapper
g_labelMapper
;
78
79
//------------------------------------------------------------------------
80
81
Debug::DebugMask
Debug::curMask
=
Debug::Quiet
;
82
int
Debug::curPrio
= 0;
83
84
void
Debug::print
(
DebugMask
mask,
int
prio,
const
char
*fmt,...)
85
{
86
if
((
curMask
&mask) && prio<=
curPrio
)
87
{
88
va_list args;
89
va_start(args,fmt);
90
vfprintf(stdout, fmt, args);
91
va_end(args);
92
}
93
}
94
95
static
int
labelToEnumValue
(
const
char
*l)
96
{
97
QCString label=l;
98
Debug::DebugMask
*
event
= g_labelMapper.
find
(label.lower());
99
if
(event)
return
*event;
else
return
0;
100
}
101
102
int
Debug::setFlag
(
const
char
*lab)
103
{
104
int
retVal =
labelToEnumValue
(lab);
105
curMask
= (
DebugMask
)(
curMask
|
labelToEnumValue
(lab));
106
return
retVal;
107
}
108
109
void
Debug::clearFlag
(
const
char
*lab)
110
{
111
curMask
= (
DebugMask
)(
curMask
& ~
labelToEnumValue
(lab));
112
}
113
114
void
Debug::setPriority
(
int
p)
115
{
116
curPrio
= p;
117
}
118
119
bool
Debug::isFlagSet
(
DebugMask
mask)
120
{
121
return
(
curMask
& mask)!=0;
122
}
123
124
void
Debug::printFlags
(
void
)
125
{
126
int
i;
127
for
(i = 0; i < (int)(
sizeof
(s_labels)/
sizeof
(*s_labels)); i++)
128
{
129
if
(s_labels[i].name)
130
{
131
msg
(
"\t%s\n"
,s_labels[i].name);
132
}
133
}
134
}