Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GUI reads per-project settings (automatically deallocated classes) from XML project file. The project file format is described in projectfile.txt. Example project file is added for gui. See also forum discussion at: https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=46
- Loading branch information
Showing
9 changed files
with
255 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
|
||
<!-- cppcheck project file --> | ||
|
||
<project version="1"> | ||
<autodealloc> | ||
<class name="AboutDialog"/> | ||
<class name="FileViewDialog"/> | ||
<class name="ThreadHandler"/> | ||
</autodealloc> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/ | ||
*/ | ||
|
||
#include <QObject> | ||
#include <QString> | ||
#include <QXmlStreamReader> | ||
#include <QFile> | ||
#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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/ | ||
*/ | ||
|
||
#include <QObject> | ||
#include <QString> | ||
#include <QStringList> | ||
#include <QXmlStreamReader> | ||
|
||
/** | ||
* @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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
|
||
<?xml version="1.0"?> | ||
<project version="1"> | ||
<autodealloc> | ||
<class name="MyClass"/> | ||
<class name="MyClass2"/> | ||
</autodealloc> | ||
<includedir> | ||
<dir name="c:/projects/framework/" /> | ||
<dir name="c:/Program Files/Visual Studio 8/VC/include/" /> | ||
</includedir> | ||
</project> | ||
|
||
See also gui.cppcheck file in gui-directory of cppcheck sources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters