Fix for UBSan build
[platform/upstream/doxygen.git] / src / debug.cpp
1 /******************************************************************************
2  *
3  * $Id: debug.cpp,v 1.7 2001/03/19 19:27:40 root Exp $
4  *
5  * Copyright (C) 1997-2012 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 "qtbc.h"
24 #include "debug.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;
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   { 0,             (Debug::DebugMask)0  }
51 };
52
53 /** Class representing a mapping from debug labels to debug IDs. */
54 class LabelMapper
55 {
56   public:
57     LabelMapper() : m_map(17) 
58     {
59       m_map.setAutoDelete(TRUE);
60       LabelMap *p = s_labels;
61       while (p->name)
62       {
63         m_map.insert(p->name,new Debug::DebugMask(p->event));
64         p++;
65       }
66     }
67     Debug::DebugMask *find(const char *s) const 
68     {
69       if (s==0) return 0;
70       return m_map.find(s);
71     }
72   private:
73     QDict<Debug::DebugMask> m_map;
74 };
75
76 static LabelMapper g_labelMapper;
77
78 //------------------------------------------------------------------------
79
80 Debug::DebugMask Debug::curMask = Debug::Quiet;
81 int Debug::curPrio = 0;
82
83 void Debug::print(DebugMask mask,int prio,const char *fmt,...)
84 {
85   if ((curMask&mask) && prio<=curPrio)
86   {
87     va_list args;
88     va_start(args,fmt);
89     vfprintf(stdout, fmt, args);
90     va_end(args);
91   }
92 }
93
94 static int labelToEnumValue(const char *l)
95 {
96   QCString label=l;
97   Debug::DebugMask *event = g_labelMapper.find(label.lower());
98   if (event) return *event; else return 0;
99 }
100
101 void Debug::setFlag(const char *lab)
102 {
103   curMask = (DebugMask)(curMask | labelToEnumValue(lab));   
104 }
105
106 void Debug::clearFlag(const char *lab)
107 {
108   curMask = (DebugMask)(curMask & ~labelToEnumValue(lab));
109 }
110
111 void Debug::setPriority(int p)
112 {
113   curPrio = p;
114 }
115
116 bool Debug::isFlagSet(DebugMask mask)
117 {
118   return (curMask & mask)!=0;
119 }
120