2009-06-22 10:57:17 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2014-02-15 07:45:39 +01:00
|
|
|
* Copyright (C) 2007-2014 Daniel Marjamäki and Cppcheck team.
|
2009-06-22 10:57:17 +02:00
|
|
|
*
|
|
|
|
* 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
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-22 10:57:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QXmlStreamReader>
|
2010-07-07 23:59:02 +02:00
|
|
|
#include <QXmlStreamWriter>
|
2009-06-22 10:57:17 +02:00
|
|
|
#include <QFile>
|
2011-02-28 16:18:14 +01:00
|
|
|
#include <QDir>
|
2009-06-22 10:57:17 +02:00
|
|
|
#include "projectfile.h"
|
|
|
|
|
|
|
|
static const char ProjectElementName[] = "project";
|
2010-07-07 23:59:02 +02:00
|
|
|
static const char ProjectVersionAttrib[] = "version";
|
|
|
|
static const char ProjectFileVersion[] = "1";
|
2013-02-10 07:43:09 +01:00
|
|
|
static const char IncludeDirElementName[] = "includedir";
|
2009-07-04 00:38:47 +02:00
|
|
|
static const char DirElementName[] = "dir";
|
|
|
|
static const char DirNameAttrib[] = "name";
|
2010-05-20 07:22:19 +02:00
|
|
|
static const char DefinesElementName[] = "defines";
|
|
|
|
static const char DefineName[] = "define";
|
|
|
|
static const char DefineNameAttrib[] = "name";
|
2010-08-14 17:42:37 +02:00
|
|
|
static const char PathsElementName[] = "paths";
|
|
|
|
static const char PathName[] = "dir";
|
|
|
|
static const char PathNameAttrib[] = "name";
|
2010-08-20 22:58:00 +02:00
|
|
|
static const char RootPathName[] = "root";
|
|
|
|
static const char RootPathNameAttrib[] = "name";
|
2011-02-27 23:13:28 +01:00
|
|
|
static const char IgnoreElementName[] = "ignore";
|
2011-02-27 17:32:53 +01:00
|
|
|
static const char IgnorePathName[] = "path";
|
|
|
|
static const char IgnorePathNameAttrib[] = "name";
|
2011-08-23 18:54:53 +02:00
|
|
|
static const char ExcludeElementName[] = "exclude";
|
|
|
|
static const char ExcludePathName[] = "path";
|
|
|
|
static const char ExcludePathNameAttrib[] = "name";
|
2013-12-29 18:06:31 +01:00
|
|
|
static const char LibrariesElementName[] = "libraries";
|
|
|
|
static const char LibraryElementName[] = "library";
|
2013-12-30 22:32:50 +01:00
|
|
|
static const char SuppressionsElementName[] = "suppressions";
|
|
|
|
static const char SuppressionElementName[] = "suppression";
|
2009-06-22 10:57:17 +02:00
|
|
|
|
|
|
|
ProjectFile::ProjectFile(QObject *parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QObject(parent)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QObject(parent),
|
|
|
|
mFilename(filename)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectFile::Read(const QString &filename)
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!filename.isEmpty())
|
2009-06-22 10:57:17 +02:00
|
|
|
mFilename = filename;
|
|
|
|
|
|
|
|
QFile file(mFilename);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
2009-06-22 10:57:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
QXmlStreamReader xmlReader(&file);
|
|
|
|
bool insideProject = false;
|
2010-07-08 18:49:04 +02:00
|
|
|
bool projectTagFound = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
while (!xmlReader.atEnd()) {
|
|
|
|
switch (xmlReader.readNext()) {
|
2009-06-22 10:57:17 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
2011-10-13 20:53:06 +02:00
|
|
|
if (xmlReader.name() == ProjectElementName) {
|
2009-06-22 10:57:17 +02:00
|
|
|
insideProject = true;
|
2010-07-08 18:49:04 +02:00
|
|
|
projectTagFound = true;
|
|
|
|
}
|
2010-08-20 22:58:00 +02:00
|
|
|
// Read root path from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == RootPathName)
|
|
|
|
ReadRootPath(xmlReader);
|
|
|
|
|
2010-08-14 17:42:37 +02:00
|
|
|
// Find paths to check from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == PathsElementName)
|
|
|
|
ReadCheckPaths(xmlReader);
|
2009-06-23 08:15:00 +02:00
|
|
|
|
2010-07-03 23:15:19 +02:00
|
|
|
// Find include directory from inside project element
|
2013-02-10 07:43:09 +01:00
|
|
|
if (insideProject && xmlReader.name() == IncludeDirElementName)
|
2009-07-04 00:38:47 +02:00
|
|
|
ReadIncludeDirs(xmlReader);
|
2010-05-20 07:22:19 +02:00
|
|
|
|
2010-07-03 23:15:19 +02:00
|
|
|
// Find preprocessor define from inside project element
|
2010-05-20 07:22:19 +02:00
|
|
|
if (insideProject && xmlReader.name() == DefinesElementName)
|
|
|
|
ReadDefines(xmlReader);
|
|
|
|
|
2011-08-23 18:54:53 +02:00
|
|
|
// Find exclude list from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == ExcludeElementName)
|
|
|
|
ReadExcludes(xmlReader);
|
|
|
|
|
2011-02-27 17:32:53 +01:00
|
|
|
// Find ignore list from inside project element
|
2011-08-23 18:54:53 +02:00
|
|
|
// These are read for compatibility
|
2011-02-27 17:32:53 +01:00
|
|
|
if (insideProject && xmlReader.name() == IgnoreElementName)
|
2011-08-23 18:54:53 +02:00
|
|
|
ReadExcludes(xmlReader);
|
2011-02-27 17:32:53 +01:00
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
// Find libraries list from inside project element
|
2013-12-29 18:06:31 +01:00
|
|
|
if (insideProject && xmlReader.name() == LibrariesElementName)
|
2013-12-30 22:32:50 +01:00
|
|
|
ReadStringList(mLibraries, xmlReader,LibraryElementName);
|
|
|
|
|
|
|
|
// Find suppressions list from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == SuppressionsElementName)
|
|
|
|
ReadStringList(mSuppressions, xmlReader,SuppressionElementName);
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2009-06-22 10:57:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2010-04-02 07:30:58 +02:00
|
|
|
if (xmlReader.name() == ProjectElementName)
|
2009-06-22 10:57:17 +02:00
|
|
|
insideProject = false;
|
|
|
|
break;
|
2009-06-23 08:15:00 +02:00
|
|
|
|
2014-11-20 10:13:03 +01:00
|
|
|
// Not handled
|
2009-06-23 08:15:00 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
2010-07-08 18:49:04 +02:00
|
|
|
if (projectTagFound)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
|
2009-07-04 00:38:47 +02:00
|
|
|
QStringList ProjectFile::GetIncludeDirs() const
|
|
|
|
{
|
2011-02-28 16:18:14 +01:00
|
|
|
QStringList dirs;
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString path, mIncludeDirs) {
|
2011-02-28 16:18:14 +01:00
|
|
|
dirs << QDir::fromNativeSeparators(path);
|
|
|
|
}
|
|
|
|
return dirs;
|
2009-07-04 00:38:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 07:22:19 +02:00
|
|
|
QStringList ProjectFile::GetDefines() const
|
|
|
|
{
|
|
|
|
return mDefines;
|
|
|
|
}
|
|
|
|
|
2010-08-14 17:42:37 +02:00
|
|
|
QStringList ProjectFile::GetCheckPaths() const
|
|
|
|
{
|
2011-02-28 16:18:14 +01:00
|
|
|
QStringList paths;
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString path, mPaths) {
|
2011-02-28 16:18:14 +01:00
|
|
|
paths << QDir::fromNativeSeparators(path);
|
|
|
|
}
|
|
|
|
return paths;
|
2010-08-14 17:42:37 +02:00
|
|
|
}
|
|
|
|
|
2011-08-23 18:54:53 +02:00
|
|
|
QStringList ProjectFile::GetExcludedPaths() const
|
2011-02-27 17:32:53 +01:00
|
|
|
{
|
2011-02-28 16:18:14 +01:00
|
|
|
QStringList paths;
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString path, mExcludedPaths) {
|
2011-02-28 16:18:14 +01:00
|
|
|
paths << QDir::fromNativeSeparators(path);
|
|
|
|
}
|
|
|
|
return paths;
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2013-12-29 18:06:31 +01:00
|
|
|
QStringList ProjectFile::GetLibraries() const
|
|
|
|
{
|
|
|
|
QStringList libraries;
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString library, mLibraries) {
|
2013-12-29 18:06:31 +01:00
|
|
|
libraries << library;
|
|
|
|
}
|
|
|
|
return libraries;
|
|
|
|
}
|
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
QStringList ProjectFile::GetSuppressions() const
|
|
|
|
{
|
|
|
|
QStringList suppressions;
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString suppression, mSuppressions) {
|
2013-12-30 22:32:50 +01:00
|
|
|
suppressions << suppression;
|
|
|
|
}
|
|
|
|
return suppressions;
|
|
|
|
}
|
|
|
|
|
2010-08-20 22:58:00 +02:00
|
|
|
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
|
|
|
QString name = attribs.value("", RootPathNameAttrib).toString();
|
|
|
|
if (!name.isEmpty())
|
|
|
|
mRootPath = name;
|
|
|
|
}
|
|
|
|
|
2009-07-04 00:38:47 +02:00
|
|
|
void ProjectFile::ReadIncludeDirs(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2009-07-04 00:38:47 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2009-07-04 00:38:47 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
|
|
|
// Read dir-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == DirElementName) {
|
2009-07-04 00:38:47 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
|
|
|
QString name = attribs.value("", DirNameAttrib).toString();
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!name.isEmpty())
|
2009-07-04 00:38:47 +02:00
|
|
|
mIncludeDirs << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2013-02-10 07:43:09 +01:00
|
|
|
if (reader.name().toString() == IncludeDirElementName)
|
2009-07-04 00:38:47 +02:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2014-11-20 10:13:03 +01:00
|
|
|
// Not handled
|
2009-07-04 00:38:47 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2009-07-04 00:38:47 +02:00
|
|
|
}
|
2010-05-20 07:22:19 +02:00
|
|
|
|
|
|
|
void ProjectFile::ReadDefines(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2010-05-20 07:22:19 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2010-05-20 07:22:19 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read define-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == DefineName) {
|
2010-05-20 07:22:19 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
|
|
|
QString name = attribs.value("", DefineNameAttrib).toString();
|
|
|
|
if (!name.isEmpty())
|
|
|
|
mDefines << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() == DefinesElementName)
|
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2014-11-20 10:13:03 +01:00
|
|
|
// Not handled
|
2010-05-20 07:22:19 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2010-05-20 07:22:19 +02:00
|
|
|
}
|
2010-07-07 23:59:02 +02:00
|
|
|
|
2010-08-14 17:42:37 +02:00
|
|
|
void ProjectFile::ReadCheckPaths(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2010-08-14 17:42:37 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2010-08-14 17:42:37 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
|
|
|
// Read dir-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == PathName) {
|
2010-08-14 17:42:37 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
|
|
|
QString name = attribs.value("", PathNameAttrib).toString();
|
|
|
|
if (!name.isEmpty())
|
|
|
|
mPaths << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() == PathsElementName)
|
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2014-11-20 10:13:03 +01:00
|
|
|
// Not handled
|
2010-08-14 17:42:37 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2010-08-14 17:42:37 +02:00
|
|
|
}
|
|
|
|
|
2011-08-23 18:54:53 +02:00
|
|
|
void ProjectFile::ReadExcludes(QXmlStreamReader &reader)
|
2011-02-27 17:32:53 +01:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2011-02-27 17:32:53 +01:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2011-02-27 17:32:53 +01:00
|
|
|
case QXmlStreamReader::StartElement:
|
2011-08-23 18:54:53 +02:00
|
|
|
// Read exclude-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == ExcludePathName) {
|
2011-08-23 18:54:53 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
|
|
|
QString name = attribs.value("", ExcludePathNameAttrib).toString();
|
|
|
|
if (!name.isEmpty())
|
|
|
|
mExcludedPaths << name;
|
|
|
|
}
|
|
|
|
// Read ignore-elements - deprecated but support reading them
|
2011-10-13 20:53:06 +02:00
|
|
|
else if (reader.name().toString() == IgnorePathName) {
|
2011-02-27 17:32:53 +01:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
|
|
|
QString name = attribs.value("", IgnorePathNameAttrib).toString();
|
|
|
|
if (!name.isEmpty())
|
2011-08-23 18:54:53 +02:00
|
|
|
mExcludedPaths << name;
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() == IgnoreElementName)
|
|
|
|
allRead = true;
|
2011-08-23 18:54:53 +02:00
|
|
|
if (reader.name().toString() == ExcludeElementName)
|
|
|
|
allRead = true;
|
2011-02-27 17:32:53 +01:00
|
|
|
break;
|
|
|
|
|
2014-11-20 10:13:03 +01:00
|
|
|
// Not handled
|
2011-02-27 17:32:53 +01:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
void ProjectFile::ReadStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[])
|
2013-12-29 18:06:31 +01:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
|
|
|
do {
|
|
|
|
type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read library-elements
|
2013-12-30 22:32:50 +01:00
|
|
|
if (reader.name().toString() == elementname) {
|
2013-12-29 18:06:31 +01:00
|
|
|
type = reader.readNext();
|
|
|
|
if (type == QXmlStreamReader::Characters) {
|
2013-12-30 22:32:50 +01:00
|
|
|
QString text = reader.text().toString();
|
|
|
|
stringlist << text;
|
2013-12-29 18:06:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2013-12-30 22:32:50 +01:00
|
|
|
if (reader.name().toString() != elementname)
|
2013-12-29 18:06:31 +01:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2014-11-20 10:13:03 +01:00
|
|
|
// Not handled
|
2013-12-29 18:06:31 +01:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!allRead);
|
|
|
|
}
|
|
|
|
|
2011-02-27 17:36:09 +01:00
|
|
|
void ProjectFile::SetIncludes(const QStringList &includes)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
|
|
|
mIncludeDirs = includes;
|
|
|
|
}
|
|
|
|
|
2011-02-27 17:36:09 +01:00
|
|
|
void ProjectFile::SetDefines(const QStringList &defines)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
|
|
|
mDefines = defines;
|
|
|
|
}
|
|
|
|
|
2011-02-27 17:36:09 +01:00
|
|
|
void ProjectFile::SetCheckPaths(const QStringList &paths)
|
2010-08-14 17:42:37 +02:00
|
|
|
{
|
|
|
|
mPaths = paths;
|
|
|
|
}
|
|
|
|
|
2011-08-23 18:54:53 +02:00
|
|
|
void ProjectFile::SetExcludedPaths(const QStringList &paths)
|
2011-02-27 17:32:53 +01:00
|
|
|
{
|
2011-08-23 18:54:53 +02:00
|
|
|
mExcludedPaths = paths;
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2013-12-29 18:06:31 +01:00
|
|
|
void ProjectFile::SetLibraries(const QStringList &libraries)
|
|
|
|
{
|
|
|
|
mLibraries = libraries;
|
|
|
|
}
|
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
void ProjectFile::SetSuppressions(const QStringList &suppressions)
|
|
|
|
{
|
|
|
|
mSuppressions = suppressions;
|
|
|
|
}
|
|
|
|
|
2010-07-07 23:59:02 +02:00
|
|
|
bool ProjectFile::Write(const QString &filename)
|
|
|
|
{
|
2010-07-08 15:16:25 +02:00
|
|
|
if (!filename.isEmpty())
|
|
|
|
mFilename = filename;
|
|
|
|
|
2010-07-07 23:59:02 +02:00
|
|
|
QFile file(mFilename);
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QXmlStreamWriter xmlWriter(&file);
|
|
|
|
xmlWriter.setAutoFormatting(true);
|
|
|
|
xmlWriter.writeStartDocument("1.0");
|
|
|
|
xmlWriter.writeStartElement(ProjectElementName);
|
|
|
|
xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mRootPath.isEmpty()) {
|
2010-08-20 22:58:00 +02:00
|
|
|
xmlWriter.writeStartElement(RootPathName);
|
|
|
|
xmlWriter.writeAttribute(RootPathNameAttrib, mRootPath);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mIncludeDirs.isEmpty()) {
|
2013-02-10 07:43:09 +01:00
|
|
|
xmlWriter.writeStartElement(IncludeDirElementName);
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString incdir, mIncludeDirs) {
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeStartElement(DirElementName);
|
|
|
|
xmlWriter.writeAttribute(DirNameAttrib, incdir);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mDefines.isEmpty()) {
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeStartElement(DefinesElementName);
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString define, mDefines) {
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeStartElement(DefineName);
|
|
|
|
xmlWriter.writeAttribute(DefineNameAttrib, define);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2010-08-14 17:42:37 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mPaths.isEmpty()) {
|
2010-08-14 17:42:37 +02:00
|
|
|
xmlWriter.writeStartElement(PathsElementName);
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString path, mPaths) {
|
2010-08-14 17:42:37 +02:00
|
|
|
xmlWriter.writeStartElement(PathName);
|
|
|
|
xmlWriter.writeAttribute(PathNameAttrib, path);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mExcludedPaths.isEmpty()) {
|
2011-08-23 18:54:53 +02:00
|
|
|
xmlWriter.writeStartElement(ExcludeElementName);
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString path, mExcludedPaths) {
|
2011-08-23 18:54:53 +02:00
|
|
|
xmlWriter.writeStartElement(ExcludePathName);
|
|
|
|
xmlWriter.writeAttribute(ExcludePathNameAttrib, path);
|
2011-02-28 15:08:14 +01:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
WriteStringList(xmlWriter,
|
|
|
|
mLibraries,
|
|
|
|
LibrariesElementName,
|
|
|
|
LibraryElementName);
|
|
|
|
|
|
|
|
WriteStringList(xmlWriter,
|
|
|
|
mSuppressions,
|
|
|
|
SuppressionsElementName,
|
|
|
|
SuppressionElementName);
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeEndDocument();
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-30 22:32:50 +01:00
|
|
|
|
|
|
|
void ProjectFile::WriteStringList(QXmlStreamWriter &xmlWriter, const QStringList &stringlist, const char startelementname[], const char stringelementname[])
|
|
|
|
{
|
|
|
|
if (stringlist.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
xmlWriter.writeStartElement(startelementname);
|
2014-11-20 10:13:03 +01:00
|
|
|
foreach (QString str, stringlist) {
|
2013-12-30 22:32:50 +01:00
|
|
|
xmlWriter.writeStartElement(stringelementname);
|
|
|
|
xmlWriter.writeCharacters(str);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|