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