]> git.lyx.org Git - lyx.git/blob - src/debug.C
Fix bug 2195: Slowness in rendering inside insets, especially on the Mac
[lyx.git] / src / debug.C
1 /**
2  * \file debug.C
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 "debug.h"
15 #include "gettext.h"
16
17 #include "support/convert.h"
18 #include "support/lstrings.h"
19
20 #include <iostream>
21 #include <iomanip>
22
23 using lyx::support::ascii_lowercase;
24 using lyx::support::bformat;
25 using lyx::support::isStrInt;
26
27 using std::setw;
28 using std::string;
29 using std::ostream;
30
31 namespace {
32
33 struct error_item {
34         Debug::type level;
35         char const * name;
36         char const * desc;
37 };
38
39
40 error_item errorTags[] = {
41         { Debug::NONE,      "none",      N_("No debugging message")},
42         { Debug::INFO,      "info",      N_("General information")},
43         { Debug::INIT,      "init",      N_("Program initialisation")},
44         { Debug::KEY,       "key",       N_("Keyboard events handling")},
45         { Debug::GUI,       "gui",       N_("GUI handling")},
46         { Debug::PARSER,    "parser",    N_("Lyxlex grammar parser")},
47         { Debug::LYXRC,     "lyxrc",     N_("Configuration files reading")},
48         { Debug::KBMAP,     "kbmap",     N_("Custom keyboard definition")},
49         { Debug::LATEX,     "latex",     N_("LaTeX generation/execution")},
50         { Debug::MATHED,    "mathed",    N_("Math editor")},
51         { Debug::FONT,      "font",      N_("Font handling")},
52         { Debug::TCLASS,    "tclass",    N_("Textclass files reading")},
53         { Debug::LYXVC,     "lyxvc",     N_("Version control")},
54         { Debug::LYXSERVER, "lyxserver", N_("External control interface")},
55         { Debug::ROFF,      "roff",      N_("Keep *roff temporary files")},
56         { Debug::ACTION,    "action",    N_("User commands")},
57         { Debug::LYXLEX,    "lyxlex",    N_("The LyX Lexxer")},
58         { Debug::DEPEND,    "depend",    N_("Dependency information")},
59         { Debug::INSETS,    "insets",    N_("LyX Insets")},
60         { Debug::FILES,     "files",     N_("Files used by LyX")},
61         { Debug::WORKAREA,  "workarea",  N_("Workarea events")},
62         { Debug::INSETTEXT, "insettext", N_("Insettext/tabular messages")},
63         { Debug::GRAPHICS,  "graphics",  N_("Graphics conversion and loading")},
64         { Debug::CHANGES,   "changes",   N_("Change tracking")},
65         { Debug::EXTERNAL,  "external",  N_("External template/inset messages")},
66         { Debug::PAINTING,  "painting",  N_("RowPainter profiling")},
67         { Debug::DEBUG,     "debug",     N_("Developers' general debug messages")},
68         { Debug::ANY,       "any",       N_("All debugging messages")}
69 };
70
71
72 int const numErrorTags = sizeof(errorTags)/sizeof(error_item);
73
74 } // namespace anon
75
76
77 lyx_debug_trait::type lyx_debug_trait::value(string const & val)
78 {
79         type l = Debug::NONE;
80         string v(val);
81         while (!v.empty()) {
82                 string::size_type const st = v.find(',');
83                 string const tmp(ascii_lowercase(v.substr(0, st)));
84                 if (tmp.empty())
85                         break;
86                 // Is it a number?
87                 if (isStrInt(tmp))
88                         l |= static_cast<type>(convert<int>(tmp));
89                 else
90                 // Search for an explicit name
91                 for (int i = 0 ; i < numErrorTags ; ++i)
92                         if (tmp == errorTags[i].name) {
93                                 l |= errorTags[i].level;
94                                 break;
95                         }
96                 if (st == string::npos) break;
97                 v.erase(0, st + 1);
98         }
99         return l;
100 }
101
102
103 void lyx_debug_trait::showLevel(ostream & os, lyx_debug_trait::type level)
104 {
105         // Show what features are traced
106         for (int i = 0; i < numErrorTags ; ++i) {
107                 if (errorTags[i].level != Debug::ANY
108                     && errorTags[i].level != Debug::NONE
109                     && errorTags[i].level & level) {
110                         // avoid _(...) re-entrance problem
111                         string const s = _(errorTags[i].desc);
112                         os << bformat(_("Debugging `%1$s' (%2$s)"),
113                                         errorTags[i].name, s)
114                            << '\n';
115                 }
116         }
117         os.flush();
118 }
119
120
121 void lyx_debug_trait::showTags(ostream & os)
122 {
123         for (int i = 0; i < numErrorTags ; ++i)
124                 os << setw(7) << static_cast<unsigned int>(errorTags[i].level)
125                    << setw(10) << errorTags[i].name
126                    << "  " << _(errorTags[i].desc) << '\n';
127         os.flush();
128 }
129
130 LyXErr lyxerr;