From 92e3cc456f11f465a5b76b03e4b418379081dba4 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 11 Jun 2012 15:03:29 +0200 Subject: [PATCH] Make debug messages more readable Shorten the file names output by LYXERR so that they start right after /src/. --- src/support/debug.cpp | 21 +++++++++++++++++++-- src/support/debug.h | 5 ++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/support/debug.cpp b/src/support/debug.cpp index 29a167af91..3a6f9018fe 100644 --- a/src/support/debug.cpp +++ b/src/support/debug.cpp @@ -14,10 +14,11 @@ #include "support/convert.h" #include "support/debug.h" +#include "support/FileName.h" #include "support/gettext.h" #include "support/lstrings.h" -#include "support/FileName.h" #include "support/ProgressInterface.h" +#include "support/regex.h" #include #include @@ -197,13 +198,29 @@ void LyXErr::endl() } +char const * LyXErr::stripName(char const * n) +{ + string const name = n; + // find the last occurence of /src/ in name + static regex re("[\\/]src[\\/]"); + 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); +} + + // It seems not possible to instantiate operator template out of class body template LyXErr & toStream(LyXErr & l, T t) { if (l.enabled()){ l.stream() << t; - if (l.secondEnabled()) { + if (l.secondEnabled()) { l.secondStream() << t; ProgressInterface::instance()->lyxerrFlush(); } diff --git a/src/support/debug.h b/src/support/debug.h index d636e4c5c3..a883e67d74 100644 --- a/src/support/debug.h +++ b/src/support/debug.h @@ -171,6 +171,9 @@ public: /// Returns true if t is part of the current debug level bool debugging(Debug::Type t = Debug::ANY) const; + /// + static char const * stripName(char const *); + private: /// The current debug level Debug::Type dt_; @@ -208,7 +211,7 @@ extern LyXErr lyxerr; # include # define CURRENT_POSITION BOOST_CURRENT_FUNCTION ": " #else -# define CURRENT_POSITION __FILE__ << "(" << __LINE__ << "): " +# define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): " #endif #define LYXERR(type, msg) \