]> git.lyx.org Git - lyx.git/blob - src/debug.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[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::docstring;
24 using lyx::support::ascii_lowercase;
25 using lyx::support::bformat;
26 using lyx::support::isStrInt;
27
28 using std::setw;
29 using std::string;
30 using std::ostream;
31
32 namespace {
33
34 struct error_item {
35         Debug::type level;
36         char const * name;
37         char const * desc;
38 };
39
40
41 error_item 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(error_item);
74
75 } // namespace anon
76
77
78 lyx_debug_trait::type lyx_debug_trait::value(string const & val)
79 {
80         type l = Debug::NONE;
81         string v(val);
82         while (!v.empty()) {
83                 string::size_type 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) break;
98                 v.erase(0, st + 1);
99         }
100         return l;
101 }
102
103
104 void lyx_debug_trait::showLevel(ostream & os, lyx_debug_trait::type level)
105 {
106         // Show what features are traced
107         for (int i = 0; i < numErrorTags ; ++i) {
108                 if (errorTags[i].level != Debug::ANY
109                     && errorTags[i].level != Debug::NONE
110                     && errorTags[i].level & level) {
111                         // avoid lyx::to_utf8(_(...)) re-entrance problem
112                         docstring const s = _(errorTags[i].desc);
113                         os << lyx::to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
114                                         lyx::from_utf8(errorTags[i].name), s))
115                            << '\n';
116                 }
117         }
118         os.flush();
119 }
120
121
122 void lyx_debug_trait::showTags(ostream & os)
123 {
124         for (int i = 0; i < numErrorTags ; ++i)
125                 os << setw(7) << static_cast<unsigned int>(errorTags[i].level)
126                    << setw(10) << errorTags[i].name
127                    << "  " << lyx::to_utf8(_(errorTags[i].desc)) << '\n';
128         os.flush();
129 }
130
131
132 LyXErr lyxerr;