Root/
Source at commit 1322 created 12 years 8 months ago. By meklort, Add doxygen to utils folder | |
---|---|
1 | /******************************************************************************␊ |
2 | *␊ |
3 | * $Id: debug.cpp,v 1.7 2001/03/19 19:27:40 root Exp $␊ |
4 | *␊ |
5 | * Copyright (C) 1997-2011 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 | struct LabelMap␊ |
29 | {␊ |
30 | const char *name;␊ |
31 | Debug::DebugMask event;␊ |
32 | };␊ |
33 | ␊ |
34 | static LabelMap s_labels[] =␊ |
35 | {␊ |
36 | { "findmembers", Debug::FindMembers },␊ |
37 | { "functions", Debug::Functions },␊ |
38 | { "variables", Debug::Variables },␊ |
39 | { "preprocessor", Debug::Preprocessor },␊ |
40 | { "classes", Debug::Classes },␊ |
41 | { "commentcnv", Debug::CommentCnv },␊ |
42 | { "commentscan", Debug::CommentScan },␊ |
43 | { "validate", Debug::Validate },␊ |
44 | { "printtree", Debug::PrintTree },␊ |
45 | { "time", Debug::Time },␊ |
46 | { "extcmd", Debug::ExtCmd },␊ |
47 | { 0, (Debug::DebugMask)0 }␊ |
48 | };␊ |
49 | ␊ |
50 | class LabelMapper␊ |
51 | {␊ |
52 | public:␊ |
53 | LabelMapper() : m_map(17) ␊ |
54 | {␊ |
55 | m_map.setAutoDelete(TRUE);␊ |
56 | LabelMap *p = s_labels;␊ |
57 | while (p->name)␊ |
58 | {␊ |
59 | m_map.insert(p->name,new Debug::DebugMask(p->event));␊ |
60 | p++;␊ |
61 | }␊ |
62 | }␊ |
63 | Debug::DebugMask *find(const char *s) const ␊ |
64 | {␊ |
65 | if (s==0) return 0;␊ |
66 | return m_map.find(s);␊ |
67 | }␊ |
68 | private:␊ |
69 | QDict<Debug::DebugMask> m_map;␊ |
70 | };␊ |
71 | ␊ |
72 | static LabelMapper g_labelMapper;␊ |
73 | ␊ |
74 | //------------------------------------------------------------------------␊ |
75 | ␊ |
76 | Debug::DebugMask Debug::curMask = Debug::Quiet;␊ |
77 | int Debug::curPrio = 0;␊ |
78 | ␊ |
79 | void Debug::print(DebugMask mask,int prio,const char *fmt,...)␊ |
80 | {␊ |
81 | if ((curMask&mask) && prio<=curPrio)␊ |
82 | {␊ |
83 | va_list args;␊ |
84 | va_start(args,fmt);␊ |
85 | vfprintf(stdout, fmt, args);␊ |
86 | va_end(args);␊ |
87 | }␊ |
88 | }␊ |
89 | ␊ |
90 | static int labelToEnumValue(const char *l)␊ |
91 | {␊ |
92 | QCString label=l;␊ |
93 | Debug::DebugMask *event = g_labelMapper.find(label.lower());␊ |
94 | if (event) return *event; else return 0;␊ |
95 | }␊ |
96 | ␊ |
97 | void Debug::setFlag(const char *lab)␊ |
98 | {␊ |
99 | curMask = (DebugMask)(curMask | labelToEnumValue(lab)); ␊ |
100 | }␊ |
101 | ␊ |
102 | void Debug::clearFlag(const char *lab)␊ |
103 | {␊ |
104 | curMask = (DebugMask)(curMask & ~labelToEnumValue(lab));␊ |
105 | }␊ |
106 | ␊ |
107 | void Debug::setPriority(int p)␊ |
108 | {␊ |
109 | curPrio = p;␊ |
110 | }␊ |
111 | ␊ |
112 | bool Debug::isFlagSet(DebugMask mask)␊ |
113 | {␊ |
114 | return (curMask & mask)!=0;␊ |
115 | }␊ |
116 | ␊ |
117 |