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