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