]> git.lyx.org Git - lyx.git/blob - src/debug.cpp
use FileName::isDirectory()
[lyx.git] / src / 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 using std::setw;
24 using std::string;
25 using std::ostream;
26
27
28 namespace lyx {
29
30 using support::ascii_lowercase;
31 using support::bformat;
32 using support::isStrInt;
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::INIT,      "init",      N_("Program initialisation")},
47         { Debug::KEY,       "key",       N_("Keyboard events handling")},
48         { Debug::GUI,       "gui",       N_("GUI handling")},
49         { Debug::PARSER,    "parser",    N_("Lyxlex grammar parser")},
50         { Debug::LYXRC,     "lyxrc",     N_("Configuration files reading")},
51         { Debug::KBMAP,     "kbmap",     N_("Custom keyboard definition")},
52         { Debug::LATEX,     "latex",     N_("LaTeX generation/execution")},
53         { Debug::MATHED,    "mathed",    N_("Math editor")},
54         { Debug::FONT,      "font",      N_("Font handling")},
55         { Debug::TCLASS,    "tclass",    N_("Textclass files reading")},
56         { Debug::LYXVC,     "lyxvc",     N_("Version control")},
57         { Debug::LYXSERVER, "lyxserver", N_("External control interface")},
58         { Debug::ROFF,      "roff",      N_("Keep *roff temporary files")},
59         { Debug::ACTION,    "action",    N_("User commands")},
60         { Debug::LYXLEX,    "lyxlex",    N_("The LyX Lexxer")},
61         { Debug::DEPEND,    "depend",    N_("Dependency information")},
62         { Debug::INSETS,    "insets",    N_("LyX Insets")},
63         { Debug::FILES,     "files",     N_("Files used by LyX")},
64         { Debug::WORKAREA,  "workarea",  N_("Workarea events")},
65         { Debug::INSETTEXT, "insettext", N_("Insettext/tabular messages")},
66         { Debug::GRAPHICS,  "graphics",  N_("Graphics conversion and loading")},
67         { Debug::CHANGES,   "changes",   N_("Change tracking")},
68         { Debug::EXTERNAL,  "external",  N_("External template/inset messages")},
69         { Debug::PAINTING,  "painting",  N_("RowPainter profiling")},
70         { Debug::DEBUG,     "debug",     N_("Developers' general debug messages")},
71         { Debug::ANY,       "any",       N_("All debugging messages")}
72 };
73
74
75 int const numErrorTags = sizeof(errorTags)/sizeof(error_item);
76
77 } // namespace anon
78
79
80 lyx_debug_trait::type lyx_debug_trait::value(string const & val)
81 {
82         type l = Debug::NONE;
83         string v(val);
84         while (!v.empty()) {
85                 string::size_type const st = v.find(',');
86                 string const tmp(ascii_lowercase(v.substr(0, st)));
87                 if (tmp.empty())
88                         break;
89                 // Is it a number?
90                 if (isStrInt(tmp))
91                         l |= static_cast<type>(convert<int>(tmp));
92                 else
93                 // Search for an explicit name
94                 for (int i = 0 ; i < numErrorTags ; ++i)
95                         if (tmp == errorTags[i].name) {
96                                 l |= errorTags[i].level;
97                                 break;
98                         }
99                 if (st == string::npos) break;
100                 v.erase(0, st + 1);
101         }
102         return l;
103 }
104
105
106 void lyx_debug_trait::showLevel(ostream & os, lyx_debug_trait::type level)
107 {
108         // Show what features are traced
109         for (int i = 0; i < numErrorTags ; ++i) {
110                 if (errorTags[i].level != Debug::ANY
111                     && errorTags[i].level != Debug::NONE
112                     && errorTags[i].level & level) {
113                         // avoid to_utf8(_(...)) re-entrance problem
114                         docstring const s = _(errorTags[i].desc);
115                         os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
116                                         from_utf8(errorTags[i].name), s))
117                            << '\n';
118                 }
119         }
120         os.flush();
121 }
122
123
124 void lyx_debug_trait::showTags(ostream & os)
125 {
126         for (int i = 0; i < numErrorTags ; ++i)
127                 os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
128                    << setw(13) << errorTags[i].name
129                    << "  " << to_utf8(_(errorTags[i].desc)) << '\n';
130         os.flush();
131 }
132
133
134 LyXErr lyxerr;
135
136
137 } // namespace lyx