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