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 
28 /** Helper struct representing a mapping from debug label to a debug ID */
29 struct LabelMap
30 {
31  const char *name;
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 
54 /** Class representing a mapping from debug labels to debug IDs. */
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 
78 
79 //------------------------------------------------------------------------
80 
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 {
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 
115 {
116  curPrio = p;
117 }
118 
120 {
121  return (curMask & mask)!=0;
122 }
123 
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 }
void msg(const char *fmt,...)
Definition: message.cpp:107
const char * name
Definition: debug.cpp:31
DebugMask
Definition: debug.h:26
static void printFlags(void)
Definition: debug.cpp:124
Debug::DebugMask event
Definition: debug.cpp:32
static LabelMap s_labels[]
Definition: debug.cpp:35
static QCString args
Definition: declinfo.cpp:674
static QStrList * l
Definition: config.cpp:1044
QDict< Debug::DebugMask > m_map
Definition: debug.cpp:74
static DebugMask curMask
Definition: debug.h:50
LabelMapper()
Definition: debug.cpp:58
static int setFlag(const char *label)
Definition: debug.cpp:102
static void print(DebugMask mask, int prio, const char *fmt,...)
Definition: debug.cpp:84
p
Definition: test.py:223
static int curPrio
Definition: debug.h:51
static void clearFlag(const char *label)
Definition: debug.cpp:109
static LabelMapper g_labelMapper
Definition: debug.cpp:77
Debug::DebugMask * find(const char *s) const
Definition: debug.cpp:68
static void setPriority(int p)
Definition: debug.cpp:114
static int labelToEnumValue(const char *l)
Definition: debug.cpp:95
static bool isFlagSet(DebugMask mask)
Definition: debug.cpp:119
QCString lower() const
Definition: qcstring.cpp:263
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371
Event finding and building.