]> git.lyx.org Git - lyx.git/blob - src/debug.C
Fix crash when entering unhandled math objects in toolbar
[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 const Debug::ANY = Debug::type(
57         Debug::INFO | Debug::INIT | Debug::KEY | Debug::GUI |
58         Debug::PARSER | Debug::LYXRC | Debug::KBMAP | Debug::LATEX |
59         Debug::MATHED | Debug::FONT | Debug::TCLASS | Debug::LYXVC |
60         Debug::LYXSERVER | Debug::ROFF | Debug::ACTION | Debug::LYXLEX |
61         Debug::DEPEND | Debug::INSETS);
62
63
64 Debug::type Debug::value(string const & val) 
65 {
66         type l = Debug::NONE;
67         string v(val);
68         while (!v.empty()) {
69                 string::size_type st = v.find(',');
70                 string tmp(lowercase(v.substr(0, st)));
71                 if (tmp.empty())
72                         break;
73                 // Is it a number?
74                 if (isStrInt(tmp)) 
75                         l |= static_cast<type>(strToInt(tmp));
76                 else
77                 // Search for an explicit name
78                 for (int i = 0 ; i < numErrorTags ; ++i) 
79                         if (tmp == errorTags[i].name) {
80                                 l |= errorTags[i].level;
81                                 break;
82                         }
83                 if (st == string::npos) break;
84                 v.erase(0, st + 1);
85         }
86         return l;
87 }
88
89
90 void Debug::showLevel(ostream & o, Debug::type level)
91 {
92         // Show what features are traced
93         for (int i = 0 ; i < numErrorTags ; ++i)
94                 if (errorTags[i].level != Debug::ANY
95                     && errorTags[i].level != Debug::NONE
96                     && errorTags[i].level & level)
97                         o << "Debugging `" << errorTags[i].name
98                           << "' (" << errorTags[i].desc << ')' << endl;
99 }
100
101
102 void Debug::showTags(ostream & os) 
103 {
104         for (int i = 0 ; i < numErrorTags ; ++i)
105                 os << setw(7) << errorTags[i].level
106                    << setw(10) << errorTags[i].name
107                    << "  " << errorTags[i].desc << '\n';
108         os.flush();
109 }