]> git.lyx.org Git - lyx.git/blob - src/client/debug.C
5da41b9f67398abb4820664bd78dafcffcb5dde7
[lyx.git] / src / client / debug.C
1 /**
2  * \file debug.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "debug.h"
15 #include "gettext.h"
16
17 #include "support/lstrings.h"
18
19 #include <iostream>
20 #include <iomanip>
21
22 using lyx::support::ascii_lowercase;
23 using lyx::support::bformat;
24 using lyx::support::isStrInt;
25 using lyx::support::strToInt;
26
27 using std::setw;
28 using std::string;
29 using std::ostream;
30
31 namespace {
32
33 struct error_item {
34         Debug::type level;
35         char const * name;
36         char const * desc;
37 };
38
39
40 error_item errorTags[] = {
41         { Debug::NONE,      "none",      N_("No debugging message")},
42         { Debug::INFO,      "info",      N_("General information")},
43         { Debug::DEBUG,  "debug",  N_("Developers general debug messages")},
44         { Debug::ANY,       "any",       N_("All debugging messages")}
45 };
46
47
48 int const numErrorTags = sizeof(errorTags)/sizeof(error_item);
49
50 } // namespace anon
51
52
53 lyx_debug_trait::type lyx_debug_trait::value(string const & val)
54 {
55         type l = Debug::NONE;
56         string v(val);
57         while (!v.empty()) {
58                 string::size_type st = v.find(',');
59                 string tmp(ascii_lowercase(v.substr(0, st)));
60                 if (tmp.empty())
61                         break;
62                 // Is it a number?
63                 if (isStrInt(tmp))
64                         l |= static_cast<type>(strToInt(tmp));
65                 else
66                 // Search for an explicit name
67                 for (int i = 0 ; i < numErrorTags ; ++i)
68                         if (tmp == errorTags[i].name) {
69                                 l |= errorTags[i].level;
70                                 break;
71                         }
72                 if (st == string::npos) break;
73                 v.erase(0, st + 1);
74         }
75         return l;
76 }
77
78
79 void lyx_debug_trait::showLevel(ostream & os, lyx_debug_trait::type level)
80 {
81         // Show what features are traced
82         for (int i = 0; i < numErrorTags ; ++i) {
83                 if (errorTags[i].level != Debug::ANY
84                     && errorTags[i].level != Debug::NONE
85                     && errorTags[i].level & level) {
86                         // avoid _(...) re-entrance problem
87                         string const s = _(errorTags[i].desc);
88                         os << bformat(_("Debugging `%1$s' (%2$s)"),
89                                         errorTags[i].name, s)
90                            << '\n';
91                 }
92         }
93         os.flush();
94 }
95
96
97 void lyx_debug_trait::showTags(ostream & os)
98 {
99         for (int i = 0; i < numErrorTags ; ++i)
100                 os << setw(7) << static_cast<unsigned int>(errorTags[i].level)
101                    << setw(10) << errorTags[i].name
102                    << "  " << _(errorTags[i].desc) << '\n';
103         os.flush();
104 }
105
106 LyXErr lyxerr;