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