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