Commit f7431879 authored by Dominik Haumann's avatar Dominik Haumann

run astyle with kdelibs coding style

astyle -n -Q \
      --indent=spaces=4 --style=otbs \
      --indent-labels --pad-oper --unpad-paren --pad-header \
      --keep-one-line-statements \
      --convert-tabs \
      --indent-preprocessor \
      --align-pointer=name \
      *.h *.cpp
parent dad4ca3a
/* This file is part of the KDE project
Copyright 2008 Dominik Haumann <dhaumann kde org>
Copyright 2008-2014 Dominik Haumann <dhaumann kde org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -24,69 +24,69 @@
#include <QDebug>
void KateBtDatabase::loadFromFile(const QString& url)
void KateBtDatabase::loadFromFile(const QString &url)
{
QFile file(url);
if (file.open(QIODevice::ReadOnly)) {
QMutexLocker locker(&mutex);
QDataStream ds(&file);
ds >> db;
}
qDebug() << "Number of entries in the backtrace database:" << db.size();
QFile file(url);
if (file.open(QIODevice::ReadOnly)) {
QMutexLocker locker(&mutex);
QDataStream ds(&file);
ds >> db;
}
qDebug() << "Number of entries in the backtrace database:" << db.size();
}
void KateBtDatabase::saveToFile(const QString& url) const
void KateBtDatabase::saveToFile(const QString &url) const
{
QFile file(url);
if (file.open(QIODevice::WriteOnly)) {
QMutexLocker locker(&mutex);
QDataStream ds(&file);
ds << db;
}
QFile file(url);
if (file.open(QIODevice::WriteOnly)) {
QMutexLocker locker(&mutex);
QDataStream ds(&file);
ds << db;
}
}
QString KateBtDatabase::value(const QString& key)
QString KateBtDatabase::value(const QString &key)
{
// key is either of the form "foo/bar.txt" or only "bar.txt"
QString file = key;
QStringList sl = key.split(QLatin1Char('/'));
if (sl.size() > 1) {
file = sl[1];
}
QMutexLocker locker(&mutex);
if (db.contains(file)) {
const QStringList& sl = db.value(file);
for (int i = 0; i < sl.size(); ++i) {
if (sl[i].indexOf(key) != -1) {
return sl[i];
}
// key is either of the form "foo/bar.txt" or only "bar.txt"
QString file = key;
QStringList sl = key.split(QLatin1Char('/'));
if (sl.size() > 1) {
file = sl[1];
}
// try to use the first one
if (sl.size() > 0) {
return sl[0];
QMutexLocker locker(&mutex);
if (db.contains(file)) {
const QStringList &sl = db.value(file);
for (int i = 0; i < sl.size(); ++i) {
if (sl[i].indexOf(key) != -1) {
return sl[i];
}
}
// try to use the first one
if (sl.size() > 0) {
return sl[0];
}
}
}
return QString();
return QString();
}
void KateBtDatabase::add(const QString& folder, const QStringList& files)
void KateBtDatabase::add(const QString &folder, const QStringList &files)
{
QMutexLocker locker(&mutex);
foreach (const QString& file, files) {
QStringList& sl = db[file];
QString entry = QDir::fromNativeSeparators(folder + QLatin1Char('/') + file);
if (!sl.contains(entry)) {
sl << entry;
QMutexLocker locker(&mutex);
foreach(const QString & file, files) {
QStringList &sl = db[file];
QString entry = QDir::fromNativeSeparators(folder + QLatin1Char('/') + file);
if (!sl.contains(entry)) {
sl << entry;
}
}
}
}
int KateBtDatabase::size() const
{
QMutexLocker locker(&mutex);
return db.size();
QMutexLocker locker(&mutex);
return db.size();
}
// kate: space-indent on; indent-width 2; replace-tabs on;
// kate: space-indent on; indent-width 4; replace-tabs on;
/* This file is part of the KDE project
Copyright 2008 Dominik Haumann <dhaumann kde org>
Copyright 2008-2014 Dominik Haumann <dhaumann kde org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -26,24 +26,24 @@
class KateBtDatabase
{
public:
public:
KateBtDatabase() {}
~KateBtDatabase() {}
void loadFromFile(const QString& url);
void saveToFile(const QString& url) const;
void loadFromFile(const QString &url);
void saveToFile(const QString &url) const;
QString value(const QString& key);
QString value(const QString &key);
void add(const QString& folder, const QStringList& files);
void add(const QString &folder, const QStringList &files);
int size() const;
private:
private:
mutable QMutex mutex;
QHash<QString, QStringList> db;
};
#endif //KATE_BACKTRACEDB_H
// kate: space-indent on; indent-width 2; replace-tabs on;
// kate: space-indent on; indent-width 4; replace-tabs on;
/* This file is part of the KDE project
Copyright 2008 Dominik Haumann <dhaumann kde org>
Copyright 2008-2014 Dominik Haumann <dhaumann kde org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -22,10 +22,10 @@
#include <QDir>
#include <QDebug>
BtFileIndexer::BtFileIndexer(KateBtDatabase* database)
: QThread()
, cancelAsap(false)
, db(database)
BtFileIndexer::BtFileIndexer(KateBtDatabase *database)
: QThread()
, cancelAsap(false)
, db(database)
{
}
......@@ -33,57 +33,61 @@ BtFileIndexer::~BtFileIndexer()
{
}
void BtFileIndexer::setSearchPaths(const QStringList& urls)
void BtFileIndexer::setSearchPaths(const QStringList &urls)
{
searchPaths.clear();
foreach (const QString& url, urls) {
if (!searchPaths.contains(url)) {
searchPaths += url;
searchPaths.clear();
foreach(const QString & url, urls) {
if (!searchPaths.contains(url)) {
searchPaths += url;
}
}
}
}
void BtFileIndexer::setFilter(const QStringList& fileFilter)
void BtFileIndexer::setFilter(const QStringList &fileFilter)
{
filter = fileFilter;
qDebug() << filter;
filter = fileFilter;
qDebug() << filter;
}
void BtFileIndexer::run()
{
if (filter.size() == 0) {
qDebug() << "Filter is empty. Aborting.";
return;
}
cancelAsap = false;
for (int i = 0; i < searchPaths.size(); ++i) {
if (cancelAsap) { break; }
indexFiles(searchPaths[i]);
}
qDebug() << QStringLiteral("Backtrace file database contains %1 files").arg(db->size());
if (filter.size() == 0) {
qDebug() << "Filter is empty. Aborting.";
return;
}
cancelAsap = false;
for (int i = 0; i < searchPaths.size(); ++i) {
if (cancelAsap) {
break;
}
indexFiles(searchPaths[i]);
}
qDebug() << QStringLiteral("Backtrace file database contains %1 files").arg(db->size());
}
void BtFileIndexer::cancel()
{
cancelAsap = true;
cancelAsap = true;
}
void BtFileIndexer::indexFiles(const QString& url)
void BtFileIndexer::indexFiles(const QString &url)
{
QDir dir(url);
if (!dir.exists()) {
return;
}
QStringList files = dir.entryList(filter, QDir::Files | QDir::NoSymLinks | QDir::Readable | QDir::NoDotAndDotDot | QDir::CaseSensitive);
db->add(url, files);
QStringList subdirs = dir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::Readable | QDir::NoDotAndDotDot | QDir::CaseSensitive);
for (int i = 0; i < subdirs.size(); ++i) {
if (cancelAsap) { break; }
indexFiles(url + QLatin1Char('/') + subdirs[i]);
}
QDir dir(url);
if (!dir.exists()) {
return;
}
QStringList files = dir.entryList(filter, QDir::Files | QDir::NoSymLinks | QDir::Readable | QDir::NoDotAndDotDot | QDir::CaseSensitive);
db->add(url, files);
QStringList subdirs = dir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::Readable | QDir::NoDotAndDotDot | QDir::CaseSensitive);
for (int i = 0; i < subdirs.size(); ++i) {
if (cancelAsap) {
break;
}
indexFiles(url + QLatin1Char('/') + subdirs[i]);
}
}
// kate: space-indent on; indent-width 2; replace-tabs on;
// kate: space-indent on; indent-width 4; replace-tabs on;
/* This file is part of the KDE project
Copyright 2008 Dominik Haumann <dhaumann kde org>
Copyright 2008-2014 Dominik Haumann <dhaumann kde org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -27,28 +27,28 @@ class KateBtDatabase;
class BtFileIndexer : public QThread
{
Q_OBJECT
public:
BtFileIndexer(KateBtDatabase* db);
Q_OBJECT
public:
BtFileIndexer(KateBtDatabase *db);
virtual ~BtFileIndexer();
void setSearchPaths(const QStringList& urls);
void setSearchPaths(const QStringList &urls);
void setFilter(const QStringList& filter);
void setFilter(const QStringList &filter);
void cancel();
protected:
protected:
virtual void run();
void indexFiles(const QString& url);
void indexFiles(const QString &url);
private:
private:
bool cancelAsap;
QStringList searchPaths;
QStringList filter;
KateBtDatabase* db;
KateBtDatabase *db;
};
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
// kate: space-indent on; indent-width 4; replace-tabs on;
/* This file is part of the KDE project
Copyright 2008 Dominik Haumann <dhaumann kde org>
Copyright 2008-2014 Dominik Haumann <dhaumann kde org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -22,151 +22,151 @@
#include <QDebug>
static QString eolDelimiter(const QString& str)
static QString eolDelimiter(const QString &str)
{
// find the split character
QString separator(QLatin1Char('\n'));
if (str.indexOf(QLatin1String("\r\n")) != -1) {
separator = QLatin1String("\r\n");
} else if (str.indexOf(QLatin1Char('\r')) != -1 ) {
separator = QLatin1Char('\r');
}
return separator;
// find the split character
QString separator(QLatin1Char('\n'));
if (str.indexOf(QLatin1String("\r\n")) != -1) {
separator = QLatin1String("\r\n");
} else if (str.indexOf(QLatin1Char('\r')) != -1) {
separator = QLatin1Char('\r');
}
return separator;
}
static bool lineNoLessThan(const QString& lhs, const QString& rhs)
static bool lineNoLessThan(const QString &lhs, const QString &rhs)
{
QRegExp rx(QLatin1String("^#(\\d+)"));
int ilhs = rx.indexIn(lhs);
int lhsLn = rx.cap(1).toInt();
int irhs = rx.indexIn(rhs);
int rhsLn = rx.cap(1).toInt();
if (ilhs != -1 && irhs != -1) {
return lhsLn < rhsLn;
} else {
return lhs < rhs;
}
QRegExp rx(QLatin1String("^#(\\d+)"));
int ilhs = rx.indexIn(lhs);
int lhsLn = rx.cap(1).toInt();
int irhs = rx.indexIn(rhs);
int rhsLn = rx.cap(1).toInt();
if (ilhs != -1 && irhs != -1) {
return lhsLn < rhsLn;
} else {
return lhs < rhs;
}
}
static QStringList normalizeBt(const QStringList& l)
static QStringList normalizeBt(const QStringList &l)
{
QStringList normalized;
bool append = false;
for (int i = 0; i < l.size(); ++i) {
QString str = l[i].trimmed();
if (str.length()) {
if (str[0] == QLatin1Char('#')) {
normalized << str;
append = true;
} else if (append) {
normalized.last() += QLatin1Char(' ') + str;
}
} else {
append = false;
QStringList normalized;
bool append = false;
for (int i = 0; i < l.size(); ++i) {
QString str = l[i].trimmed();
if (str.length()) {
if (str[0] == QLatin1Char('#')) {
normalized << str;
append = true;
} else if (append) {
normalized.last() += QLatin1Char(' ') + str;
}
} else {
append = false;
}
}
}
qSort(normalized.begin(), normalized.end(), lineNoLessThan);
qSort(normalized.begin(), normalized.end(), lineNoLessThan);
// now every single line contains a whole backtrace info
return normalized;
// now every single line contains a whole backtrace info
return normalized;
}
static BtInfo parseBtLine(const QString& line)
static BtInfo parseBtLine(const QString &line)
{
int index;
// the syntax types we support are
// a) #24 0xb688ff8e in QApplication::notify (this=0xbf997e8c, receiver=0x82607e8, e=0xbf997074) at kernel/qapplication.cpp:3115
// b) #39 0xb634211c in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
// c) #41 0x0805e690 in ?? ()
// d) #5 0xffffe410 in __kernel_vsyscall ()
int index;
// the syntax types we support are
// a) #24 0xb688ff8e in QApplication::notify (this=0xbf997e8c, receiver=0x82607e8, e=0xbf997074) at kernel/qapplication.cpp:3115
// b) #39 0xb634211c in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
// c) #41 0x0805e690 in ?? ()
// d) #5 0xffffe410 in __kernel_vsyscall ()
// try a) cap #number(1), address(2), function(3), filename(4), linenumber(5)
static QRegExp rxa(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+(.+)\\s+at\\s+(.+):(\\d+)$"));
index = rxa.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = rxa.cap(4);
info.function = rxa.cap(3);
info.address = rxa.cap(2);
info.line = rxa.cap(5).toInt();
info.step = rxa.cap(1).toInt();
info.type = BtInfo::Source;
return info;
}
// try b) cap #number(1), address(2), function(3), lib(4)
static QRegExp rxb(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+(.+)\\s+from\\s+(.+)$"));
index = rxb.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = rxb.cap(4);
info.function = rxb.cap(3);
info.address = rxb.cap(2);
info.line = -1;
info.step = rxb.cap(1).toInt();
info.type = BtInfo::Lib;
return info;
}
// try a) cap #number(1), address(2), function(3), filename(4), linenumber(5)
static QRegExp rxa(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+(.+)\\s+at\\s+(.+):(\\d+)$"));
index = rxa.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = rxa.cap(4);
info.function = rxa.cap(3);
info.address = rxa.cap(2);
info.line = rxa.cap(5).toInt();
info.step = rxa.cap(1).toInt();
info.type = BtInfo::Source;
return info;
}
// try c) #41 0x0805e690 in ?? ()
static QRegExp rxc(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+\\?\\?\\s+\\(\\)$"));
index = rxc.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = QString();
info.function = QString();
info.address = rxc.cap(2);
info.line = -1;
info.step = rxc.cap(1).toInt();
info.type = BtInfo::Unknown;
return info;
}
// try b) cap #number(1), address(2), function(3), lib(4)
static QRegExp rxb(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+(.+)\\s+from\\s+(.+)$"));
index = rxb.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = rxb.cap(4);
info.function = rxb.cap(3);
info.address = rxb.cap(2);
info.line = -1;
info.step = rxb.cap(1).toInt();
info.type = BtInfo::Lib;
return info;
}
// try d) #5 0xffffe410 in __kernel_vsyscall ()
static QRegExp rxd(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+(.+)$"));
index = rxd.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = QString();
info.function = rxd.cap(3);
info.address = rxd.cap(2);
info.line = -1;
info.step = rxd.cap(1).toInt();
info.type = BtInfo::Unknown;
return info;
}
// try c) #41 0x0805e690 in ?? ()
static QRegExp rxc(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+\\?\\?\\s+\\(\\)$"));
index = rxc.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = QString();
info.function = QString();
info.address = rxc.cap(2);
info.line = -1;
info.step = rxc.cap(1).toInt();
info.type = BtInfo::Unknown;
return info;
}
qDebug() << "Unknown backtrace line:" << line;
// try d) #5 0xffffe410 in __kernel_vsyscall ()
static QRegExp rxd(QLatin1String("^#(\\d+)\\s+(0x\\w+)\\s+in\\s+(.+)$"));
index = rxd.indexIn(line);
if (index == 0) {
BtInfo info;
info.original = line;
info.filename = QString();
info.function = rxd.cap(3);
info.address = rxd.cap(2);
info.line = -1;
info.step = rxd.cap(1).toInt();
info.type = BtInfo::Unknown;
info.type = BtInfo::Invalid;
return info;
}
qDebug() << "Unknown backtrace line:" << line;
BtInfo info;
info.type = BtInfo::Invalid;
return info;
}
QList<BtInfo> KateBtParser::parseBacktrace(const QString& bt)
QList<BtInfo> KateBtParser::parseBacktrace(const QString &bt)
{
QStringList l = bt.split(eolDelimiter(bt), QString::SkipEmptyParts);
QStringList l = bt.split(eolDelimiter(bt), QString::SkipEmptyParts);
l = normalizeBt(l);
l = normalizeBt(l);
QList<BtInfo> btList;
for (int i = 0; i < l.size(); ++i) {
BtInfo info = parseBtLine(l[i]);
if (info.type != BtInfo::Invalid) {
btList.append(parseBtLine(l[i]));
QList<BtInfo> btList;
for (int i = 0; i < l.size(); ++i) {
BtInfo info = parseBtLine(l[i]);
if (info.type != BtInfo::Invalid) {
btList.append(parseBtLine(l[i]));
}
}
}
return btList;
return btList;
}
// kate: space-indent on; indent-width 2; replace-tabs on;
// kate: space-indent on; indent-width 4; replace-tabs on;
/* This file is part of the KDE project
Copyright 2008 Dominik Haumann <dhaumann kde org>
Copyright 2008-2014 Dominik Haumann <dhaumann kde org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -24,25 +24,24 @@
class BtInfo
{