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