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