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