]> git.lyx.org Git - lyx.git/blob - src/debug.C
ws changes only
[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 <iostream>
20 #include <iomanip>
21
22 using lyx::support::ascii_lowercase;
23 using lyx::support::bformat;
24 using lyx::support::isStrInt;
25 using lyx::support::strToInt;
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::ANY,       "any",       N_("All debugging messages")}
67 };
68
69
70 int const numErrorTags = sizeof(errorTags)/sizeof(error_item);
71
72 } // namespace anon
73
74
75 lyx_debug_trait::type lyx_debug_trait::value(string const & val)
76 {
77         type l = Debug::NONE;
78         string v(val);
79         while (!v.empty()) {
80                 string::size_type st = v.find(',');
81                 string tmp(ascii_lowercase(v.substr(0, st)));
82                 if (tmp.empty())
83                         break;
84                 // Is it a number?
85                 if (isStrInt(tmp))
86                         l |= static_cast<type>(strToInt(tmp));
87                 else
88                 // Search for an explicit name
89                 for (int i = 0 ; i < numErrorTags ; ++i)
90                         if (tmp == errorTags[i].name) {
91                                 l |= errorTags[i].level;
92                                 break;
93                         }
94                 if (st == string::npos) break;
95                 v.erase(0, st + 1);
96         }
97         return l;
98 }
99
100
101 void lyx_debug_trait::showLevel(ostream & os, lyx_debug_trait::type level)
102 {
103         // Show what features are traced
104         for (int i = 0; i < numErrorTags ; ++i) {
105                 if (errorTags[i].level != Debug::ANY
106                     && errorTags[i].level != Debug::NONE
107                     && errorTags[i].level & level) {
108                         // avoid _(...) re-entrance problem
109                         string const s = _(errorTags[i].desc);
110                         os << bformat(_("Debugging `%1$s' (%2$s)"),
111                                         errorTags[i].name, s);
112                 }
113         }
114 }
115
116
117 void lyx_debug_trait::showTags(ostream & os)
118 {
119         for (int i = 0; i < numErrorTags ; ++i)
120                 os << setw(7) << errorTags[i].level
121                    << setw(10) << errorTags[i].name
122                    << "  " << _(errorTags[i].desc) << '\n';
123         os.flush();
124 }
125
126 LyXErr lyxerr(std::cerr.rdbuf());