]> git.lyx.org Git - lyx.git/blob - src/client/debug.cpp
* new function to set border around selection
[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 "support/debug.h"
15 #include "support/gettext.h"
16
17 #include "support/convert.h"
18 #include "support/lstrings.h"
19 #include "support/FileName.h"
20
21 #include <iostream>
22 #include <iomanip>
23
24 using namespace std;
25 using namespace lyx::support;
26
27 namespace lyx {
28
29 namespace {
30
31 struct ErrorItem {
32         Debug::Type level;
33         char const * name;
34         char const * desc;
35 };
36
37
38 ErrorItem errorTags[] = {
39         { Debug::NONE,      "none",      N_("No debugging message")},
40         { Debug::INFO,      "info",      N_("General information")},
41         { Debug::DEBUG,     "debug",     N_("Developers' general debug messages")},
42         { Debug::ANY,       "any",       N_("All debugging messages")}
43 };
44
45
46 int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]);
47
48 } // namespace anon
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 const st = v.find(',');
57                 string const tmp(ascii_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>(convert<int>(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 & os, 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                         // avoid to_utf8(_(...)) re-entrance problem
85                         docstring const s = _(errorTags[i].desc);
86                         os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
87                                         from_utf8(errorTags[i].name), s))
88                            << '\n';
89                 }
90         }
91         os.flush();
92 }
93
94
95 void Debug::showTags(ostream & os)
96 {
97         for (int i = 0; i < numErrorTags ; ++i)
98                 os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
99                    << setw(13) << errorTags[i].name
100                    << "  " << to_utf8(_(errorTags[i].desc)) << '\n';
101         os.flush();
102 }
103
104
105 void LyXErr::disable()
106 {
107         enabled_ = false;
108 }
109
110
111 void LyXErr::enable()
112 {
113         enabled_ = true;
114 }
115
116
117 bool LyXErr::debugging(Debug::Type t) const
118 {
119         return (dt & t);
120 }
121
122
123 void LyXErr::endl()
124 {
125         stream() << std::endl;
126 }
127
128
129 LyXErr & operator<<(LyXErr & l, void const * t)
130 { l.stream() << t; return l; }
131 LyXErr & operator<<(LyXErr & l, char const * t)
132 { l.stream() << t; return l; }
133 LyXErr & operator<<(LyXErr & l, char t)
134 { l.stream() << t; return l; }
135 LyXErr & operator<<(LyXErr & l, int t)
136 { l.stream() << t; return l; }
137 LyXErr & operator<<(LyXErr & l, unsigned int t)
138 { l.stream() << t; return l; }
139 LyXErr & operator<<(LyXErr & l, long t)
140 { l.stream() << t; return l; }
141 LyXErr & operator<<(LyXErr & l, unsigned long t)
142 { l.stream() << t; return l; }
143 LyXErr & operator<<(LyXErr & l, double t)
144 { l.stream() << t; return l; }
145 LyXErr & operator<<(LyXErr & l, string const & t)
146 { l.stream() << t; return l; }
147 LyXErr & operator<<(LyXErr & l, docstring const & t)
148 { l.stream() << to_utf8(t); return l; }
149 LyXErr & operator<<(LyXErr & l, FileName const & t)
150 { l.stream() << t; return l; }
151 LyXErr & operator<<(LyXErr & l, ostream &(*t)(ostream &))
152 { l.stream() << t; return l; }
153 LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &))
154 { l.stream() << t; return l; }
155
156 LyXErr lyxerr;
157
158
159 } // namespace lyx