2003-08-23 00:17:00 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file debug.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
2009-12-29 15:05:37 +00:00
|
|
|
* \author Pavel Sanda
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
1999-12-13 15:31:52 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2012-06-11 13:03:29 +00:00
|
|
|
#include "support/FileName.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2009-12-29 15:05:37 +00:00
|
|
|
#include "support/ProgressInterface.h"
|
2012-06-11 13:03:29 +00:00
|
|
|
#include "support/regex.h"
|
2000-11-14 02:01:57 +00:00
|
|
|
|
2003-09-26 14:27:20 +00:00
|
|
|
#include <iostream>
|
2002-11-21 18:33:09 +00:00
|
|
|
#include <iomanip>
|
|
|
|
|
2011-04-11 19:39:40 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-11-27 20:37:08 +00:00
|
|
|
struct ErrorItem {
|
2007-11-28 22:12:03 +00:00
|
|
|
Debug::Type level;
|
1999-12-13 15:31:52 +00:00
|
|
|
char const * name;
|
|
|
|
char const * desc;
|
|
|
|
};
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2007-11-27 20:37:08 +00:00
|
|
|
ErrorItem errorTags[] = {
|
2010-01-03 17:40:34 +00:00
|
|
|
{ Debug::NONE, "none", N_("No debugging messages")},
|
2000-11-14 02:01:57 +00:00
|
|
|
{ Debug::INFO, "info", N_("General information")},
|
|
|
|
{ Debug::INIT, "init", N_("Program initialisation")},
|
|
|
|
{ Debug::KEY, "key", N_("Keyboard events handling")},
|
|
|
|
{ Debug::GUI, "gui", N_("GUI handling")},
|
2003-06-24 10:41:22 +00:00
|
|
|
{ Debug::PARSER, "parser", N_("Lyxlex grammar parser")},
|
2000-11-14 02:01:57 +00:00
|
|
|
{ Debug::LYXRC, "lyxrc", N_("Configuration files reading")},
|
|
|
|
{ Debug::KBMAP, "kbmap", N_("Custom keyboard definition")},
|
|
|
|
{ Debug::LATEX, "latex", N_("LaTeX generation/execution")},
|
|
|
|
{ Debug::MATHED, "mathed", N_("Math editor")},
|
|
|
|
{ Debug::FONT, "font", N_("Font handling")},
|
|
|
|
{ Debug::TCLASS, "tclass", N_("Textclass files reading")},
|
|
|
|
{ Debug::LYXVC, "lyxvc", N_("Version control")},
|
|
|
|
{ Debug::LYXSERVER, "lyxserver", N_("External control interface")},
|
2008-08-15 19:09:42 +00:00
|
|
|
{ Debug::UNDO, "undo", N_("Undo/Redo mechanism")},
|
2000-11-14 02:01:57 +00:00
|
|
|
{ Debug::ACTION, "action", N_("User commands")},
|
2009-06-28 21:53:31 +00:00
|
|
|
{ Debug::LYXLEX, "lyxlex", N_("The LyX Lexer")},
|
2000-11-14 02:01:57 +00:00
|
|
|
{ Debug::DEPEND, "depend", N_("Dependency information")},
|
|
|
|
{ Debug::INSETS, "insets", N_("LyX Insets")},
|
|
|
|
{ Debug::FILES, "files", N_("Files used by LyX")},
|
2001-11-09 13:44:48 +00:00
|
|
|
{ Debug::WORKAREA, "workarea", N_("Workarea events")},
|
2015-07-08 08:57:04 +00:00
|
|
|
{ Debug::CLIPBOARD, "clipboard", N_("Clipboard handling")},
|
2002-02-16 12:33:19 +00:00
|
|
|
{ Debug::GRAPHICS, "graphics", N_("Graphics conversion and loading")},
|
2003-02-08 19:18:01 +00:00
|
|
|
{ Debug::CHANGES, "changes", N_("Change tracking")},
|
2003-09-04 17:01:00 +00:00
|
|
|
{ Debug::EXTERNAL, "external", N_("External template/inset messages")},
|
2006-03-10 16:10:35 +00:00
|
|
|
{ Debug::PAINTING, "painting", N_("RowPainter profiling")},
|
2009-06-28 22:02:47 +00:00
|
|
|
{ Debug::SCROLLING, "scrolling", N_("Scrolling debugging")},
|
2007-12-21 20:43:21 +00:00
|
|
|
{ Debug::MACROS, "macros", N_("Math macros")},
|
2008-02-10 19:52:45 +00:00
|
|
|
{ Debug::RTL, "rtl", N_("RTL/Bidi")},
|
2008-06-25 10:53:34 +00:00
|
|
|
{ Debug::LOCALE, "locale", N_("Locale/Internationalisation")},
|
2008-07-14 23:47:54 +00:00
|
|
|
{ Debug::SELECTION, "selection", N_("Selection copy/paste mechanism")},
|
2009-08-17 14:39:00 +00:00
|
|
|
{ Debug::FIND, "find", N_("Find and replace mechanism")},
|
2005-07-17 12:39:56 +00:00
|
|
|
{ Debug::DEBUG, "debug", N_("Developers' general debug messages")},
|
2001-11-29 12:58:59 +00:00
|
|
|
{ Debug::ANY, "any", N_("All debugging messages")}
|
1999-12-13 15:31:52 +00:00
|
|
|
};
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
2007-11-27 20:37:08 +00:00
|
|
|
int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]);
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
} // namespace anon
|
1999-12-13 15:31:52 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2009-12-30 15:09:49 +00:00
|
|
|
int Debug::levelCount()
|
2009-12-29 15:05:37 +00:00
|
|
|
{
|
2009-12-30 15:09:49 +00:00
|
|
|
return numErrorTags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Debug::Type Debug::value(int idx)
|
|
|
|
{
|
|
|
|
if (idx > 0 && idx < numErrorTags)
|
|
|
|
return errorTags[idx].level;
|
|
|
|
return Debug::NONE;
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
2009-12-30 15:09:49 +00:00
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
string const Debug::description(Debug::Type val)
|
|
|
|
{
|
|
|
|
for (int i = 0 ; i < numErrorTags ; ++i) {
|
|
|
|
if (errorTags[i].level == val)
|
|
|
|
return errorTags[i].desc;
|
|
|
|
}
|
|
|
|
return "unknown level";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const Debug::name(Debug::Type val)
|
|
|
|
{
|
|
|
|
for (int i = 0 ; i < numErrorTags ; ++i) {
|
|
|
|
if (errorTags[i].level == val)
|
|
|
|
return errorTags[i].name;
|
|
|
|
}
|
|
|
|
return "unknown level";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
Debug::Type Debug::value(string const & val)
|
1999-12-13 15:31:52 +00:00
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
Type l = Debug::NONE;
|
2007-11-14 22:29:20 +00:00
|
|
|
string v = val;
|
1999-12-13 15:31:52 +00:00
|
|
|
while (!v.empty()) {
|
2007-11-14 22:29:20 +00:00
|
|
|
size_t const st = v.find(',');
|
2007-11-28 22:12:03 +00:00
|
|
|
string const tmp = ascii_lowercase(v.substr(0, st));
|
2000-01-25 12:35:27 +00:00
|
|
|
if (tmp.empty())
|
1999-12-13 15:31:52 +00:00
|
|
|
break;
|
|
|
|
// Is it a number?
|
2002-03-21 17:27:08 +00:00
|
|
|
if (isStrInt(tmp))
|
2007-11-28 22:12:03 +00:00
|
|
|
l |= static_cast<Type>(convert<int>(tmp));
|
1999-12-13 15:31:52 +00:00
|
|
|
else
|
|
|
|
// Search for an explicit name
|
2002-03-21 17:27:08 +00:00
|
|
|
for (int i = 0 ; i < numErrorTags ; ++i)
|
1999-12-13 15:31:52 +00:00
|
|
|
if (tmp == errorTags[i].name) {
|
|
|
|
l |= errorTags[i].level;
|
|
|
|
break;
|
|
|
|
}
|
2007-11-28 22:12:03 +00:00
|
|
|
if (st == string::npos)
|
|
|
|
break;
|
1999-12-13 15:31:52 +00:00
|
|
|
v.erase(0, st + 1);
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
void Debug::showLevel(ostream & os, Debug::Type level)
|
1999-12-13 15:31:52 +00:00
|
|
|
{
|
|
|
|
// Show what features are traced
|
2010-11-06 00:22:47 +00:00
|
|
|
for (int i = 0; i < numErrorTags; ++i) {
|
1999-12-13 15:31:52 +00:00
|
|
|
if (errorTags[i].level != Debug::ANY
|
2010-11-06 00:22:47 +00:00
|
|
|
&& errorTags[i].level != Debug::NONE
|
|
|
|
&& errorTags[i].level & level) {
|
2006-10-21 00:16:43 +00:00
|
|
|
// avoid to_utf8(_(...)) re-entrance problem
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const s = _(errorTags[i].desc);
|
2006-10-21 00:16:43 +00:00
|
|
|
os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
|
|
|
|
from_utf8(errorTags[i].name), s))
|
2004-04-29 15:25:56 +00:00
|
|
|
<< '\n';
|
2002-11-24 15:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-29 15:25:56 +00:00
|
|
|
os.flush();
|
1999-12-13 15:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-27 20:25:18 +00:00
|
|
|
void Debug::showTags(ostream & os)
|
1999-12-13 15:31:52 +00:00
|
|
|
{
|
2007-11-14 22:29:20 +00:00
|
|
|
for (int i = 0; i != numErrorTags ; ++i)
|
2006-12-10 16:51:25 +00:00
|
|
|
os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
|
|
|
|
<< setw(13) << errorTags[i].name
|
2006-10-21 00:16:43 +00:00
|
|
|
<< " " << to_utf8(_(errorTags[i].desc)) << '\n';
|
1999-12-13 21:59:26 +00:00
|
|
|
os.flush();
|
1999-12-13 15:31:52 +00:00
|
|
|
}
|
2003-09-26 14:27:20 +00:00
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
void LyXErr::disable()
|
|
|
|
{
|
|
|
|
enabled_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXErr::enable()
|
|
|
|
{
|
|
|
|
enabled_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXErr::debugging(Debug::Type t) const
|
|
|
|
{
|
2010-11-06 00:22:47 +00:00
|
|
|
return (dt_ & t);
|
2007-11-28 22:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXErr::endl()
|
|
|
|
{
|
2009-12-29 15:05:37 +00:00
|
|
|
if (enabled_) {
|
2007-12-08 15:02:34 +00:00
|
|
|
stream() << std::endl;
|
2010-11-06 00:22:47 +00:00
|
|
|
if (second_enabled_)
|
|
|
|
secondStream() << std::endl;
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 13:03:29 +00:00
|
|
|
char const * LyXErr::stripName(char const * n)
|
|
|
|
{
|
|
|
|
string const name = n;
|
|
|
|
// find the last occurence of /src/ in name
|
2013-10-07 22:59:05 +00:00
|
|
|
static const regex re("[\\/]src[\\/]");
|
2012-06-11 13:03:29 +00:00
|
|
|
string::const_iterator const begin = name.begin();
|
|
|
|
string::const_iterator it = begin;
|
|
|
|
string::const_iterator const end = name.end();
|
|
|
|
smatch results;
|
|
|
|
while (regex_search(it, end, results, re)) {
|
|
|
|
it = results[0].second;
|
|
|
|
}
|
|
|
|
return n + std::distance(begin, it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
// It seems not possible to instantiate operator template out of class body
|
2009-12-30 15:37:14 +00:00
|
|
|
template<class T>
|
|
|
|
LyXErr & toStream(LyXErr & l, T t)
|
|
|
|
{
|
|
|
|
if (l.enabled()){
|
|
|
|
l.stream() << t;
|
2012-06-11 13:03:29 +00:00
|
|
|
if (l.secondEnabled()) {
|
2010-11-06 00:22:47 +00:00
|
|
|
l.secondStream() << t;
|
2009-12-30 15:37:14 +00:00
|
|
|
ProgressInterface::instance()->lyxerrFlush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l;
|
2007-11-28 22:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXErr & operator<<(LyXErr & l, void const * t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, char const * t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, char t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, int t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, unsigned int t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, long t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, unsigned long t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, double t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-12-12 19:28:07 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, string const & t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, docstring const & t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, to_utf8(t)); }
|
2007-12-12 19:57:42 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, FileName const & t)
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-12-12 19:28:07 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, ostream &(*t)(ostream &))
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-12-12 19:28:07 +00:00
|
|
|
LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &))
|
2009-12-30 15:37:14 +00:00
|
|
|
{ return toStream(l, t); }
|
2007-11-28 22:12:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
// The global instance
|
2003-11-01 13:03:03 +00:00
|
|
|
LyXErr lyxerr;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2011-04-11 19:39:40 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|