]> git.lyx.org Git - lyx.git/blob - src/client/debug.cpp
fix client linking
[lyx.git] / src / client / debug.cpp
1 /**
2  * \file debug.cpp
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/convert.h"
18 #include "support/lstrings.h"
19
20 #include <iostream>
21 #include <iomanip>
22
23
24 namespace lyx {
25
26 using support::ascii_lowercase;
27 using support::bformat;
28 using support::isStrInt;
29
30 using std::setw;
31 using std::string;
32 using std::ostream;
33
34 namespace {
35
36 struct error_item {
37         Debug::type level;
38         char const * name;
39         char const * desc;
40 };
41
42
43 error_item errorTags[] = {
44         { Debug::NONE,      "none",      N_("No debugging message")},
45         { Debug::INFO,      "info",      N_("General information")},
46         { Debug::DEBUG,     "debug",     N_("Developers' general debug messages")},
47         { Debug::ANY,       "any",       N_("All debugging messages")}
48 };
49
50
51 int const numErrorTags = sizeof(errorTags)/sizeof(error_item);
52
53 } // namespace anon
54
55
56 lyx_debug_trait::type lyx_debug_trait::value(string const & val)
57 {
58         type l = Debug::NONE;
59         string v(val);
60         while (!v.empty()) {
61                 string::size_type const st = v.find(',');
62                 string const tmp(ascii_lowercase(v.substr(0, st)));
63                 if (tmp.empty())
64                         break;
65                 // Is it a number?
66                 if (isStrInt(tmp))
67                         l |= static_cast<type>(convert<int>(tmp));
68                 else
69                 // Search for an explicit name
70                 for (int i = 0 ; i < numErrorTags ; ++i)
71                         if (tmp == errorTags[i].name) {
72                                 l |= errorTags[i].level;
73                                 break;
74                         }
75                 if (st == string::npos) break;
76                 v.erase(0, st + 1);
77         }
78         return l;
79 }
80
81
82 void lyx_debug_trait::showLevel(ostream & os, lyx_debug_trait::type level)
83 {
84         // Show what features are traced
85         for (int i = 0; i < numErrorTags ; ++i) {
86                 if (errorTags[i].level != Debug::ANY
87                     && errorTags[i].level != Debug::NONE
88                     && errorTags[i].level & level) {
89                         // avoid to_utf8(_(...)) re-entrance problem
90                         docstring const s = _(errorTags[i].desc);
91                         os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
92                                         from_utf8(errorTags[i].name), s))
93                            << '\n';
94                 }
95         }
96         os.flush();
97 }
98
99
100 void lyx_debug_trait::showTags(ostream & os)
101 {
102         for (int i = 0; i < numErrorTags ; ++i)
103                 os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
104                    << setw(13) << errorTags[i].name
105                    << "  " << to_utf8(_(errorTags[i].desc)) << '\n';
106         os.flush();
107 }
108
109
110 LyXErr lyxerr;
111
112
113 } // namespace lyx