diff --git a/gui/gui.cppcheck b/gui/gui.cppcheck
new file mode 100644
index 000000000..3d33c7c2f
--- /dev/null
+++ b/gui/gui.cppcheck
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/gui/gui.pro b/gui/gui.pro
index 8864232c7..bd374e4ca 100644
--- a/gui/gui.pro
+++ b/gui/gui.pro
@@ -4,6 +4,7 @@
TEMPLATE = app
TARGET =
+QT += xml
DEPENDPATH += .
INCLUDEPATH += .
MOC_DIR = temp
@@ -27,6 +28,7 @@ HEADERS += mainwindow.h \
aboutdialog.h \
common.h \
fileviewdialog.h \
+ projectfile.h \
../src/checkautovariables.h \
../src/checkdangerousfunctions.h \
../src/checkheaders.h \
@@ -62,6 +64,7 @@ SOURCES += main.cpp \
applicationdialog.cpp \
aboutdialog.cpp \
fileviewdialog.cpp \
+ projectfile.cpp \
../src/checkautovariables.cpp \
../src/checkdangerousfunctions.cpp \
../src/checkmemoryleak.cpp \
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 4f9fe29c4..382468bc5 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -30,6 +30,7 @@
#include "aboutdialog.h"
#include "threadhandler.h"
#include "fileviewdialog.h"
+#include "projectfile.h"
#include "../src/filelister.h"
#include "../src/cppcheckexecutor.h"
@@ -230,6 +231,8 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
selected = QFileDialog::getOpenFileNames(this,
tr("Select files to check"),
mSettings.value(tr("Check path"), "").toString());
+ if (selected.isEmpty())
+ mCurrentDirectory.clear();
}
else if (mode == QFileDialog::DirectoryOnly)
{
@@ -237,7 +240,10 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
tr("Select directory to check"),
mSettings.value(tr("Check path"), "").toString());
if (!dir.isEmpty())
+ {
+ mCurrentDirectory = dir;
selected.append(dir);
+ }
}
if (selected.count() > 0)
@@ -275,7 +281,9 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
EnableCheckButtons(false);
mActionSettings.setEnabled(false);
mResults.SetCheckDirectory(absDirectory);
- mThread->Check(GetCppcheckSettings(), false);
+
+ Settings checkSettings = GetCppcheckSettings();
+ mThread->Check(checkSettings, false);
}
}
@@ -291,7 +299,30 @@ void MainWindow::CheckDirectory()
Settings MainWindow::GetCppcheckSettings()
{
+ ProjectFile pfile;
Settings result;
+
+ if (!mCurrentDirectory.isEmpty())
+ {
+ // Format project filename (directory name + .cppcheck) and load
+ // the project file if it is found.
+ QStringList parts = mCurrentDirectory.split("/");
+ QString projfile = parts[parts.count() - 1] + ".cppcheck";
+ bool projectRead = false;
+ if (QFile::exists(projfile))
+ projectRead = pfile.Read(mCurrentDirectory + "/" + projfile);
+
+ if (projectRead)
+ {
+ QStringList classes = pfile.GetDeAllocatedClasses();
+ QString classname;
+ foreach(classname, classes)
+ {
+ result.addAutoAllocClass(classname.toStdString());
+ }
+ }
+ }
+
result._debug = false;
result._showAll = true;
result._checkCodingStyle = true;
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 09a7b5ca6..a447d9bac 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -197,7 +197,7 @@ protected:
QStringList GetFilesRecursively(const QString &path);
/**
- * @brief Get our default cppcheck settings
+ * @brief Get our default cppcheck settings and read project file.
*
* @return Default cppcheck settings
*/
@@ -368,6 +368,11 @@ protected:
ApplicationList mApplications;
private:
+
+ /**
+ * @brief Current checked directory.
+ */
+ QString mCurrentDirectory;
};
#endif // MAINWINDOW_H
diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp
new file mode 100644
index 000000000..19cc0a6f9
--- /dev/null
+++ b/gui/projectfile.cpp
@@ -0,0 +1,106 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+#include
+#include
+#include
+#include "projectfile.h"
+
+static const char ProjectElementName[] = "project";
+static const char AllocElementName[] = "autodealloc";
+static const char ClassElementName[] = "class";
+static const char ClassNameAttrib[] = "name";
+
+ProjectFile::ProjectFile(QObject *parent) :
+ QObject(parent)
+{
+}
+
+ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
+ QObject(parent),
+ mFilename(filename)
+{
+}
+
+bool ProjectFile::Read(const QString &filename)
+{
+ if (!filename.isEmpty())
+ mFilename = filename;
+
+ QFile file(mFilename);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return false;
+
+ QXmlStreamReader xmlReader(&file);
+ bool insideProject = false;
+ while (!xmlReader.atEnd())
+ {
+ switch (xmlReader.readNext())
+ {
+ case QXmlStreamReader::StartElement:
+ if (xmlReader.name() == ProjectElementName)
+ insideProject = true;
+ if (insideProject && xmlReader.name() == AllocElementName)
+ ReadAutoAllocClasses(xmlReader);
+ break;
+
+ case QXmlStreamReader::EndElement:
+ if (xmlReader.name() == ProjectElementName)
+ insideProject = false;
+ break;
+ }
+ }
+
+ file.close();
+ return true;
+}
+
+QStringList ProjectFile::GetDeAllocatedClasses() const
+{
+ return mDeAllocatedClasses;
+}
+
+void ProjectFile::ReadAutoAllocClasses(QXmlStreamReader &reader)
+{
+ QXmlStreamReader::TokenType type;
+ bool allRead = false;
+ do
+ {
+ type = reader.readNext();
+ switch (type)
+ {
+ case QXmlStreamReader::StartElement:
+ if (reader.name().toString() == ClassElementName)
+ {
+ QXmlStreamAttributes attribs = reader.attributes();
+ QString name = attribs.value("", ClassNameAttrib).toString();
+ if (!name.isEmpty())
+ mDeAllocatedClasses << name;
+ }
+ break;
+
+ case QXmlStreamReader::EndElement:
+ if (reader.name().toString() == AllocElementName)
+ allRead = true;
+ break;
+ }
+
+ }
+ while (!allRead);
+}
diff --git a/gui/projectfile.h b/gui/projectfile.h
new file mode 100644
index 000000000..074badf86
--- /dev/null
+++ b/gui/projectfile.h
@@ -0,0 +1,63 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+#include
+#include
+#include
+
+/**
+* @brief A class that reads and writes (TODO) project files.
+* The project files contain project-specific settings for checking. For
+* example a list of automatically deallocated classes.
+*/
+class ProjectFile : public QObject
+{
+ Q_OBJECT
+
+public:
+ ProjectFile(QObject *parent = 0);
+ ProjectFile(const QString &filename, QObject *parent = 0);
+
+ /**
+ * @brief Read the project file.
+ * @param filename Filename (can be also given to constructor).
+ */
+ bool Read(const QString &filename = QString());
+
+ /**
+ * @brief Get list of automatically deallocated classes.
+ * @return list of classes.
+ */
+ QStringList GetDeAllocatedClasses() const;
+
+protected:
+ void ReadAutoAllocClasses(QXmlStreamReader &reader);
+
+private:
+
+ /**
+ * @brief Filename (+path) of the project file.
+ */
+ QString mFilename;
+
+ /**
+ * @brief List of automatically deallocated classes.
+ */
+ QStringList mDeAllocatedClasses;
+};
diff --git a/gui/projectfile.txt b/gui/projectfile.txt
new file mode 100644
index 000000000..589f0a7b2
--- /dev/null
+++ b/gui/projectfile.txt
@@ -0,0 +1,27 @@
+Project files
+-------------
+
+cppcheck GUI handles per-project settings in project files instead of global
+program settings. This allows customizing cppcheck for each project's needs.
+
+Currently there is no GUI to edit the project file. The cppcheck automatically
+loads a project file which has same name than selected directory and extension
+".cppcheck". For example in "gui"-directory cppcheck loads "gui.cppcheck"
+project file.
+
+The project file is simple XML file easy to edit with your favourite editor
+program. The format is:
+
+
+
+
+
+
+
+
+
+
+
+
+
+See also gui.cppcheck file in gui-directory of cppcheck sources.
diff --git a/src/settings.cpp b/src/settings.cpp
index 89661ab6a..087019b83 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -55,6 +55,10 @@ void Settings::autoDealloc(std::istream &istr)
}
}
+void Settings::addAutoAllocClass(const std::string &name)
+{
+ _autoDealloc.push_back(name);
+}
bool Settings::isAutoDealloc(const char classname[]) const
{
diff --git a/src/settings.h b/src/settings.h
index 5186d06bf..ff2084aaf 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -67,6 +67,9 @@ public:
/** Fill list of automaticly deallocated classes */
void autoDealloc(std::istream &istr);
+ /** Add class to list of automatically deallocated classes */
+ void addAutoAllocClass(const std::string &name);
+
/** is a class automaticly deallocated? */
bool isAutoDealloc(const char classname[]) const;
};