3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
14 #include "support/debug.h"
16 #include "support/convert.h"
17 #include "support/gettext.h"
18 #include "support/lstrings.h"
19 #include "support/FileName.h"
25 using namespace lyx::support;
38 ErrorItem errorTags[] = {
39 { Debug::NONE, "none", N_("No debugging message")},
40 { Debug::INFO, "info", N_("General information")},
41 { Debug::INIT, "init", N_("Program initialisation")},
42 { Debug::KEY, "key", N_("Keyboard events handling")},
43 { Debug::GUI, "gui", N_("GUI handling")},
44 { Debug::PARSER, "parser", N_("Lyxlex grammar parser")},
45 { Debug::LYXRC, "lyxrc", N_("Configuration files reading")},
46 { Debug::KBMAP, "kbmap", N_("Custom keyboard definition")},
47 { Debug::LATEX, "latex", N_("LaTeX generation/execution")},
48 { Debug::MATHED, "mathed", N_("Math editor")},
49 { Debug::FONT, "font", N_("Font handling")},
50 { Debug::TCLASS, "tclass", N_("Textclass files reading")},
51 { Debug::LYXVC, "lyxvc", N_("Version control")},
52 { Debug::LYXSERVER, "lyxserver", N_("External control interface")},
53 { Debug::ROFF, "roff", N_("Keep *roff temporary files")},
54 { Debug::ACTION, "action", N_("User commands")},
55 { Debug::LYXLEX, "lyxlex", N_("The LyX Lexxer")},
56 { Debug::DEPEND, "depend", N_("Dependency information")},
57 { Debug::INSETS, "insets", N_("LyX Insets")},
58 { Debug::FILES, "files", N_("Files used by LyX")},
59 { Debug::WORKAREA, "workarea", N_("Workarea events")},
60 { Debug::INSETTEXT, "insettext", N_("Insettext/tabular messages")},
61 { Debug::GRAPHICS, "graphics", N_("Graphics conversion and loading")},
62 { Debug::CHANGES, "changes", N_("Change tracking")},
63 { Debug::EXTERNAL, "external", N_("External template/inset messages")},
64 { Debug::PAINTING, "painting", N_("RowPainter profiling")},
65 { Debug::DEBUG, "debug", N_("Developers' general debug messages")},
66 { Debug::ANY, "any", N_("All debugging messages")}
70 int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]);
75 Debug::Type Debug::value(string const & val)
80 size_t const st = v.find(',');
81 string const tmp = ascii_lowercase(v.substr(0, st));
86 l |= static_cast<Type>(convert<int>(tmp));
88 // Search for an explicit name
89 for (int i = 0 ; i < numErrorTags ; ++i)
90 if (tmp == errorTags[i].name) {
91 l |= errorTags[i].level;
94 if (st == string::npos)
102 void Debug::showLevel(ostream & os, Debug::Type level)
104 // Show what features are traced
105 for (int i = 0; i != numErrorTags; ++i) {
106 if (errorTags[i].level != Debug::ANY
107 && errorTags[i].level != Debug::NONE
108 && errorTags[i].level & level) {
109 // avoid to_utf8(_(...)) re-entrance problem
110 docstring const s = _(errorTags[i].desc);
111 os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
112 from_utf8(errorTags[i].name), s))
120 void Debug::showTags(ostream & os)
122 for (int i = 0; i != numErrorTags ; ++i)
123 os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
124 << setw(13) << errorTags[i].name
125 << " " << to_utf8(_(errorTags[i].desc)) << '\n';
130 void LyXErr::disable()
136 void LyXErr::enable()
142 bool LyXErr::debugging(Debug::Type t) const
151 stream() << std::endl;
155 LyXErr & operator<<(LyXErr & l, void const * t)
156 { if (l.enabled()) l.stream() << t; return l; }
157 LyXErr & operator<<(LyXErr & l, char const * t)
158 { if (l.enabled()) l.stream() << t; return l; }
159 LyXErr & operator<<(LyXErr & l, char t)
160 { if (l.enabled()) l.stream() << t; return l; }
161 LyXErr & operator<<(LyXErr & l, int t)
162 { if (l.enabled()) l.stream() << t; return l; }
163 LyXErr & operator<<(LyXErr & l, unsigned int t)
164 { if (l.enabled()) l.stream() << t; return l; }
165 LyXErr & operator<<(LyXErr & l, long t)
166 { if (l.enabled()) l.stream() << t; return l; }
167 LyXErr & operator<<(LyXErr & l, unsigned long t)
168 { if (l.enabled()) l.stream() << t; return l; }
169 LyXErr & operator<<(LyXErr & l, double t)
170 { if (l.enabled()) l.stream() << t; return l; }
171 LyXErr & operator<<(LyXErr & l, string const & t)
172 { if (l.enabled()) l.stream() << t; return l; }
173 LyXErr & operator<<(LyXErr & l, docstring const & t)
174 { if (l.enabled()) l.stream() << to_utf8(t); return l; }
175 LyXErr & operator<<(LyXErr & l, support::FileName const & t)
176 { if (l.enabled()) l.stream() << t; return l; }
177 LyXErr & operator<<(LyXErr & l, ostream &(*t)(ostream &))
178 { if (l.enabled()) l.stream() << t; return l; }
179 LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &))
180 { if (l.enabled()) l.stream() << t; return l; }
183 // The global instance