]> git.lyx.org Git - lyx.git/blob - src/support/debug.cpp
Revert qprocess code. Revisions reverted: 22026, 22030, 22044, 22048,
[lyx.git] / src / support / debug.cpp
1 /**
2  * \file debug.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/debug.h"
15
16 #include "support/convert.h"
17 #include "support/gettext.h"
18 #include "support/lstrings.h"
19 #include "support/FileName.h"
20
21 #include <iostream>
22 #include <iomanip>
23
24 using namespace std;
25
26 namespace lyx {
27
28 using support::ascii_lowercase;
29 using support::bformat;
30 using support::isStrInt;
31
32 namespace {
33
34 struct ErrorItem {
35         Debug::Type level;
36         char const * name;
37         char const * desc;
38 };
39
40
41 ErrorItem errorTags[] = {
42         { Debug::NONE,      "none",      N_("No debugging message")},
43         { Debug::INFO,      "info",      N_("General information")},
44         { Debug::INIT,      "init",      N_("Program initialisation")},
45         { Debug::KEY,       "key",       N_("Keyboard events handling")},
46         { Debug::GUI,       "gui",       N_("GUI handling")},
47         { Debug::PARSER,    "parser",    N_("Lyxlex grammar parser")},
48         { Debug::LYXRC,     "lyxrc",     N_("Configuration files reading")},
49         { Debug::KBMAP,     "kbmap",     N_("Custom keyboard definition")},
50         { Debug::LATEX,     "latex",     N_("LaTeX generation/execution")},
51         { Debug::MATHED,    "mathed",    N_("Math editor")},
52         { Debug::FONT,      "font",      N_("Font handling")},
53         { Debug::TCLASS,    "tclass",    N_("Textclass files reading")},
54         { Debug::LYXVC,     "lyxvc",     N_("Version control")},
55         { Debug::LYXSERVER, "lyxserver", N_("External control interface")},
56         { Debug::ROFF,      "roff",      N_("Keep *roff temporary files")},
57         { Debug::ACTION,    "action",    N_("User commands")},
58         { Debug::LYXLEX,    "lyxlex",    N_("The LyX Lexxer")},
59         { Debug::DEPEND,    "depend",    N_("Dependency information")},
60         { Debug::INSETS,    "insets",    N_("LyX Insets")},
61         { Debug::FILES,     "files",     N_("Files used by LyX")},
62         { Debug::WORKAREA,  "workarea",  N_("Workarea events")},
63         { Debug::INSETTEXT, "insettext", N_("Insettext/tabular messages")},
64         { Debug::GRAPHICS,  "graphics",  N_("Graphics conversion and loading")},
65         { Debug::CHANGES,   "changes",   N_("Change tracking")},
66         { Debug::EXTERNAL,  "external",  N_("External template/inset messages")},
67         { Debug::PAINTING,  "painting",  N_("RowPainter profiling")},
68         { Debug::DEBUG,     "debug",     N_("Developers' general debug messages")},
69         { Debug::ANY,       "any",       N_("All debugging messages")}
70 };
71
72
73 int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]);
74
75 } // namespace anon
76
77
78 Debug::Type Debug::value(string const & val)
79 {
80         Type l = Debug::NONE;
81         string v = val;
82         while (!v.empty()) {
83                 size_t const st = v.find(',');
84                 string const tmp = ascii_lowercase(v.substr(0, st));
85                 if (tmp.empty())
86                         break;
87                 // Is it a number?
88                 if (isStrInt(tmp))
89                         l |= static_cast<Type>(convert<int>(tmp));
90                 else
91                 // Search for an explicit name
92                 for (int i = 0 ; i < numErrorTags ; ++i)
93                         if (tmp == errorTags[i].name) {
94                                 l |= errorTags[i].level;
95                                 break;
96                         }
97                 if (st == string::npos)
98                 break;
99                 v.erase(0, st + 1);
100         }
101         return l;
102 }
103
104
105 void Debug::showLevel(ostream & os, Debug::Type level)
106 {
107         // Show what features are traced
108         for (int i = 0; i != numErrorTags; ++i) {
109                 if (errorTags[i].level != Debug::ANY
110                     && errorTags[i].level != Debug::NONE
111                     && errorTags[i].level & level) {
112                         // avoid to_utf8(_(...)) re-entrance problem
113                         docstring const s = _(errorTags[i].desc);
114                         os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
115                                         from_utf8(errorTags[i].name), s))
116                            << '\n';
117                 }
118         }
119         os.flush();
120 }
121
122
123 void Debug::showTags(ostream & os)
124 {
125         for (int i = 0; i != numErrorTags ; ++i)
126                 os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
127                    << setw(13) << errorTags[i].name
128                    << "  " << to_utf8(_(errorTags[i].desc)) << '\n';
129         os.flush();
130 }
131
132
133 void LyXErr::disable()
134 {
135         enabled_ = false;
136 }
137
138
139 void LyXErr::enable()
140 {
141         enabled_ = true;
142 }
143
144
145 bool LyXErr::debugging(Debug::Type t) const
146 {
147         return (dt & t);
148 }
149
150
151 void LyXErr::endl()
152 {
153         if (enabled_)
154                 stream() << std::endl;
155 }
156
157
158 LyXErr & operator<<(LyXErr & l, void const * t)
159 { if (l.enabled()) l.stream() << t; return l; }
160 LyXErr & operator<<(LyXErr & l, char const * t)
161 { if (l.enabled()) l.stream() << t; return l; }
162 LyXErr & operator<<(LyXErr & l, char t)
163 { if (l.enabled()) l.stream() << t; return l; }
164 LyXErr & operator<<(LyXErr & l, int t)
165 { if (l.enabled()) l.stream() << t; return l; }
166 LyXErr & operator<<(LyXErr & l, unsigned int t)
167 { if (l.enabled()) l.stream() << t; return l; }
168 LyXErr & operator<<(LyXErr & l, long t)
169 { if (l.enabled()) l.stream() << t; return l; }
170 LyXErr & operator<<(LyXErr & l, unsigned long t)
171 { if (l.enabled()) l.stream() << t; return l; }
172 LyXErr & operator<<(LyXErr & l, double t)
173 { if (l.enabled()) l.stream() << t; return l; }
174 LyXErr & operator<<(LyXErr & l, std::string const & t)
175 { if (l.enabled()) l.stream() << t; return l; }
176 LyXErr & operator<<(LyXErr & l, docstring const & t)
177 { if (l.enabled()) l.stream() << to_utf8(t); return l; }
178 LyXErr & operator<<(LyXErr & l, support::FileName const & t)
179 { if (l.enabled()) l.stream() << t; return l; }
180 LyXErr & operator<<(LyXErr & l, std::ostream &(*t)(std::ostream &))
181 { if (l.enabled()) l.stream() << t; return l; }
182 LyXErr & operator<<(LyXErr & l, std::ios_base &(*t)(std::ios_base &))
183 { if (l.enabled()) l.stream() << t; return l; }
184
185
186 // The global instance
187 LyXErr lyxerr;
188
189
190 } // namespace lyx