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