]> git.lyx.org Git - lyx.git/blob - src/debug.C
more header disentangling
[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 <iomanip>
17
18 #include "debug.h"
19 #include "gettext.h"
20 #include "support/lstrings.h"
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 grammer 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::ANY,       "any",       N_("All debugging messages")}
58 };
59
60
61 int const numErrorTags = sizeof(errorTags)/sizeof(error_item);
62
63 } // namespace anon
64
65         
66 Debug::type const Debug::ANY = Debug::type(
67         Debug::INFO | Debug::INIT | Debug::KEY | Debug::GUI |
68         Debug::PARSER | Debug::LYXRC | Debug::KBMAP | Debug::LATEX |
69         Debug::MATHED | Debug::FONT | Debug::TCLASS | Debug::LYXVC |
70         Debug::LYXSERVER | Debug::ROFF | Debug::ACTION | Debug::LYXLEX |
71         Debug::DEPEND | Debug::INSETS | Debug::FILES | Debug::WORKAREA);
72
73
74 Debug::type Debug::value(string const & val) 
75 {
76         type l = Debug::NONE;
77         string v(val);
78         while (!v.empty()) {
79                 string::size_type st = v.find(',');
80                 string tmp(lowercase(v.substr(0, st)));
81                 if (tmp.empty())
82                         break;
83                 // Is it a number?
84                 if (isStrInt(tmp)) 
85                         l |= static_cast<type>(strToInt(tmp));
86                 else
87                 // Search for an explicit name
88                 for (int i = 0 ; i < numErrorTags ; ++i) 
89                         if (tmp == errorTags[i].name) {
90                                 l |= errorTags[i].level;
91                                 break;
92                         }
93                 if (st == string::npos) break;
94                 v.erase(0, st + 1);
95         }
96         return l;
97 }
98
99
100 void Debug::showLevel(ostream & o, Debug::type level)
101 {
102         // Show what features are traced
103         for (int i = 0 ; i < numErrorTags ; ++i)
104                 if (errorTags[i].level != Debug::ANY
105                     && errorTags[i].level != Debug::NONE
106                     && errorTags[i].level & level)
107                         o << _("Debugging `") << errorTags[i].name
108                           << "' (" << _(errorTags[i].desc) << ')' << endl;
109 }
110
111
112 void Debug::showTags(ostream & os) 
113 {
114         for (int i = 0 ; i < numErrorTags ; ++i)
115                 os << setw(7) << errorTags[i].level
116                    << setw(10) << errorTags[i].name
117                    << "  " << _(errorTags[i].desc) << '\n';
118         os.flush();
119 }