QSet<QString> Config::overrideOutputFormats;
QMap<QString, QString> Config::extractedDirs;
int Config::numInstances;
+QStack<QString> Config::workingDirs_;
/*!
\class Config
: prog(programName)
{
loc = Location::null;
- lastLoc = Location::null;
+ lastLocation_ = Location::null;
locMap.clear();
- stringValueMap.clear();
- stringListValueMap.clear();
+ stringPairMap.clear();
+ stringListPairMap.clear();
numInstances++;
}
else {
loc.setEtc(true);
}
- lastLoc = Location::null;
+ lastLocation_ = Location::null;
}
/*!
*/
void Config::unload(const QString& fileName)
{
- QStringMultiMap::ConstIterator v = stringValueMap.constBegin();
- while (v != stringValueMap.constEnd()) {
- qDebug() << v.key() << " = " << v.value();
+ QStringPairMap::ConstIterator v = stringPairMap.constBegin();
+ while (v != stringPairMap.constEnd()) {
+ qDebug() << v.key() << " = " << v.value().second;
++v;
}
qDebug() << "fileName:" << fileName;
*/
void Config::setStringList(const QString& var, const QStringList& values)
{
- stringValueMap[var] = values.join(QLatin1Char(' '));
- stringListValueMap[var] = values;
+ stringPairMap[var].first = QDir::currentPath();
+ stringPairMap[var].second = values.join(QLatin1Char(' '));
+ stringListPairMap[var].first = QDir::currentPath();
+ stringListPairMap[var].second = values;
}
/*!
/*!
First, this function looks up the configuration variable \a var
in the location map and, if found, sets the internal variable
- \c{lastLoc} to the Location that \a var maps to.
+ \c{lastLocation_} to the Location that \a var maps to.
Then it looks up the configuration variable \a var in the string
- map, and returns the string that \a var maps to.
+ map and returns the string that \a var maps to.
*/
QString Config::getString(const QString& var) const
{
if (!locMap[var].isEmpty())
- (Location&) lastLoc = locMap[var];
- return stringValueMap[var];
+ (Location&) lastLocation_ = locMap[var];
+ return stringPairMap[var].second;
+}
+
+/*!
+ This function looks up the variable \a var in the location map
+ and, if found, sets the internal variable \c{lastLocation_} to the
+ location that \a var maps to.
+
+ Then it looks up \a var in the configuration variable map and,
+ if found, constructs a path from the pair value, which consists
+ of the directory path of the configuration file where the value
+ came from, and the value itself. The constructed path is returned.
+ */
+QString Config::getPath(const QString& var) const
+{
+ if (!locMap[var].isEmpty())
+ (Location&) lastLocation_ = locMap[var];
+ QString path;
+ if (stringPairMap.contains(var)) {
+ path = QDir(stringPairMap[var].first + "/" + stringPairMap[var].second).absolutePath();
+ }
+ return path;
}
/*!
/*!
First, this function looks up the configuration variable \a var
in the location map and, if found, sets the internal variable
- \c{lastLoc} to the Location that \a var maps to.
+ \c{lastLocation_} to the Location that \a var maps to.
Then it looks up the configuration variable \a var in the string
list map, and returns the string list that \a var maps to.
QStringList Config::getStringList(const QString& var) const
{
if (!locMap[var].isEmpty())
- (Location&) lastLoc = locMap[var];
- return stringListValueMap[var];
+ (Location&) lastLocation_ = locMap[var];
+ return stringListPairMap[var].second;
}
QStringList Config::getCanonicalRelativePathList(const QString& var) const
{
if (!locMap[var].isEmpty())
- (Location&) lastLoc = locMap[var];
+ (Location&) lastLocation_ = locMap[var];
QStringList t;
- QMap<QString,QStringList>::const_iterator it = stringListValueMap.constFind(var);
- if (it != stringListValueMap.constEnd()) {
- const QStringList& sl = it.value();
+ QStringListPairMap::const_iterator it = stringListPairMap.constFind(var);
+ if (it != stringListPairMap.constEnd()) {
+ const QStringList& sl = it.value().second;
if (!sl.isEmpty()) {
t.reserve(sl.size());
for (int i=0; i<sl.size(); ++i) {
First, this function looks up the configuration variable \a var
in the location map and, if found, sets the internal variable
- \c{lastLoc} the Location that \a var maps to.
+ \c{lastLocation_} the Location that \a var maps to.
Then it looks up the configuration variable \a var in the string
list map, which maps to a string list that contains file paths.
QStringList Config::getCleanPathList(const QString& var) const
{
if (!locMap[var].isEmpty())
- (Location&) lastLoc = locMap[var];
+ (Location&) lastLocation_ = locMap[var];
QStringList t;
- QMap<QString,QStringList>::const_iterator it = stringListValueMap.constFind(var);
- if (it != stringListValueMap.constEnd()) {
- const QStringList& sl = it.value();
+ QStringListPairMap::const_iterator it = stringListPairMap.constFind(var);
+ if (it != stringListPairMap.constEnd()) {
+ const QStringList& sl = it.value().second;
if (!sl.isEmpty()) {
t.reserve(sl.size());
for (int i=0; i<sl.size(); ++i) {
}
/*!
+ This function should only be called when the configuration
+ variable \a var maps to a string list that contains file paths.
+ It cleans the paths with QDir::cleanPath() before returning
+ them.
+
+ First, this function looks up the configuration variable \a var
+ in the location map and, if found, sets the internal variable
+ \c{lastLocation_} the Location that \a var maps to.
+
+ Then it looks up the configuration variable \a var in the string
+ list map, which maps to a string list that contains file paths.
+ These paths might not be clean, so QDir::cleanPath() is called
+ for each one. The string list returned contains cleaned paths.
+ */
+QStringList Config::getPathList(const QString& var) const
+{
+ if (!locMap[var].isEmpty())
+ (Location&) lastLocation_ = locMap[var];
+ QStringList t;
+ QStringListPairMap::const_iterator it = stringListPairMap.constFind(var);
+ if (it != stringListPairMap.constEnd()) {
+ const QStringList& sl = it.value().second;
+ const QString d = it.value().first;
+ if (!sl.isEmpty()) {
+ t.reserve(sl.size());
+ for (int i=0; i<sl.size(); ++i) {
+ QFileInfo fileInfo;
+ QString path = d + "/" + QDir::cleanPath(sl[i]);
+ fileInfo.setFile(path);
+ if (!fileInfo.exists())
+ lastLocation_.warning(tr("File '%1' does not exist").arg(path));
+ else
+ t.append(path);
+ }
+ }
+ }
+ return t;
+}
+
+
+/*!
Calls getRegExpList() with the control variable \a var and
iterates through the resulting list of regular expressions,
concatening them with some extras characters to form a single
{
QSet<QString> result;
QString varDot = var + QLatin1Char('.');
- QStringMultiMap::ConstIterator v = stringValueMap.constBegin();
- while (v != stringValueMap.constEnd()) {
+ QStringPairMap::ConstIterator v = stringPairMap.constBegin();
+ while (v != stringPairMap.constEnd()) {
if (v.key().startsWith(varDot)) {
QString subVar = v.key().mid(varDot.length());
int dot = subVar.indexOf(QLatin1Char('.'));
with the matching keys (stripped of the prefix \a var and
mapped to their values. The pairs are inserted into \a t
*/
-void Config::subVarsAndValues(const QString& var, QStringMultiMap& t) const
+void Config::subVarsAndValues(const QString& var, QStringPairMap& t) const
{
QString varDot = var + QLatin1Char('.');
- QStringMultiMap::ConstIterator v = stringValueMap.constBegin();
- while (v != stringValueMap.constEnd()) {
+ QStringPairMap::ConstIterator v = stringPairMap.constBegin();
+ while (v != stringPairMap.constEnd()) {
if (v.key().startsWith(varDot)) {
QString subVar = v.key().mid(varDot.length());
int dot = subVar.indexOf(QLatin1Char('.'));
const QString& fileName,
QString& userFriendlyFilePath)
{
- if (debug)
- qDebug() << "FILES:" << files
- << "DIRS:" << dirs
- << "FILENAME:" << fileName;
+ if (debug) {
+ qDebug() << "FINDFILE DIRS:" << dirs;
+ qDebug() << "FINDFILE FILENAME:" << fileName;
+ }
if (fileName.isEmpty() || fileName.startsWith(QLatin1Char('/'))) {
userFriendlyFilePath = fileName;
return fileName;
/*!
Copies the \a sourceFilePath to the file name constructed by
- concatenating \a targetDirPath and \a userFriendlySourceFilePath.
- \a location is for identifying the file and line number where
- a qdoc error occurred. The constructed output file name is
- returned.
+ concatenating \a targetDirPath and the file name from the
+ \a userFriendlySourceFilePath. \a location is for identifying
+ the file and line number where a qdoc error occurred. The
+ constructed output file name is returned.
*/
QString Config::copyFile(const Location& location,
const QString& sourceFilePath,
{
QFile inFile(sourceFilePath);
if (!inFile.open(QFile::ReadOnly)) {
- location.fatal(tr("Cannot open input file '%1': %2")
- .arg(sourceFilePath).arg(inFile.errorString()));
+ location.warning(tr("Cannot open input file for copy: '%1': %2")
+ .arg(sourceFilePath).arg(inFile.errorString()));
return QString();
}
int slash = outFileName.lastIndexOf(QLatin1Char('/'));
if (slash != -1)
outFileName = outFileName.mid(slash);
-
- QFile outFile(targetDirPath + QLatin1Char('/') + outFileName);
+ if ((outFileName.size()) > 0 && (outFileName[0] != '/'))
+ outFileName = targetDirPath + QLatin1Char('/') + outFileName;
+ else
+ outFileName = targetDirPath + outFileName;
+ QFile outFile(outFileName);
if (!outFile.open(QFile::WriteOnly)) {
- location.fatal(tr("Cannot open output file '%1': %2")
- .arg(outFile.fileName()).arg(outFile.errorString()));
+ location.warning(tr("Cannot open output file for copy: '%1': %2")
+ .arg(outFileName).arg(outFile.errorString()));
return QString();
}
*/
void Config::load(Location location, const QString& fileName)
{
+ pushWorkingDir(QFileInfo(fileName).path());
+ QDir::setCurrent(QFileInfo(fileName).path());
QRegExp keySyntax(QLatin1String("\\w+(?:\\.\\w+)*"));
#define SKIP_CHAR() \
else {
locMap[*key].setEtc(true);
}
- if (stringValueMap[*key].isEmpty()) {
- stringValueMap[*key] = stringValue;
+ if (stringPairMap[*key].second.isEmpty()) {
+ stringPairMap[*key].first = QDir::currentPath();
+ stringPairMap[*key].second = stringValue;
}
else {
- stringValueMap[*key] +=
- QLatin1Char(' ') + stringValue;
+ stringPairMap[*key].second += QLatin1Char(' ') + stringValue;
}
- stringListValueMap[*key] += stringListValue;
+ stringListPairMap[*key].first = QDir::currentPath();
+ stringListPairMap[*key].second += stringListValue;
}
else {
locMap[*key] = keyLoc;
- stringValueMap[*key] = stringValue;
- stringListValueMap[*key] = stringListValue;
+ stringPairMap[*key].first = QDir::currentPath();
+ stringPairMap[*key].second = stringValue;
+ stringListPairMap[*key].first = QDir::currentPath();
+ stringListPairMap[*key].second = stringListValue;
}
++key;
}
}
}
else {
- location.fatal(tr("Unexpected character '%1' at beginning of line")
- .arg(c));
+ location.fatal(tr("Unexpected character '%1' at beginning of line").arg(c));
}
}
+ popWorkingDir();
+ if (!workingDirs_.isEmpty())
+ QDir::setCurrent(QFileInfo(workingDirs_.top()).path());
}
QStringList Config::getFilesHere(const QString& uncleanDir,
return result;
}
+/*!
+ Push \a dir onto the stack of working directories.
+ */
+void Config::pushWorkingDir(const QString& dir)
+{
+ workingDirs_.push(dir);
+}
+
+/*!
+ If the stack of working directories is not empty, pop the
+ top entry and return it. Otherwise return an empty string.
+ */
+QString Config::popWorkingDir()
+{
+ if (!workingDirs_.isEmpty()) {
+ return workingDirs_.pop();
+ }
+ qDebug() << "RETURNED EMPTY WORKING DIR";
+ return QString();
+}
+
QT_END_NAMESPACE
#include <qmap.h>
#include <qset.h>
#include <qstringlist.h>
-
+#include <qstack.h>
+#include <qpair.h>
#include "location.h"
QT_BEGIN_NAMESPACE
-typedef QMultiMap<QString, QString> QStringMultiMap;
+/*
+ In QStringPair, the first string is the path to a directory;
+ the second string is some value.
+ */
+typedef QPair<QString, QString> QStringPair;
+
+/*
+ In QStringListPair, the first string is the path to a directory;
+ the string list is a list of string values.
+ */
+typedef QPair<QString, QStringList> QStringListPair;
+typedef QMultiMap<QString, QStringPair> QStringPairMultiMap;
+typedef QMap<QString, QStringPair> QStringPairMap;
+typedef QMap<QString, QStringListPair> QStringListPairMap;
class Config
{
const QString& programName() const { return prog; }
const Location& location() const { return loc; }
- const Location& lastLocation() const { return lastLoc; }
+ const Location& lastLocation() const { return lastLocation_; }
bool getBool(const QString& var) const;
int getInt(const QString& var) const;
QString getOutputDir() const;
QSet<QString> getOutputFormats() const;
QString getString(const QString& var) const;
+ QString getPath(const QString& var) const;
QSet<QString> getStringSet(const QString& var) const;
QStringList getStringList(const QString& var) const;
QStringList getCanonicalRelativePathList(const QString& var) const;
QStringList getCleanPathList(const QString& var) const;
+ QStringList getPathList(const QString& var) const;
QRegExp getRegExp(const QString& var) const;
QList<QRegExp> getRegExpList(const QString& var) const;
QSet<QString> subVars(const QString& var) const;
- void subVarsAndValues(const QString& var, QStringMultiMap& t) const;
+ void subVarsAndValues(const QString& var, QStringPairMap& t) const;
QStringList getAllFiles(const QString& filesVar,
const QString& dirsVar,
const QSet<QString> &excludedDirs = QSet<QString>(),
const QString& targetDirPath);
static int numParams(const QString& value);
static bool removeDirContents(const QString& dir);
+ static void pushWorkingDir(const QString& dir);
+ static QString popWorkingDir();
QT_STATIC_CONST QString dot;
QString prog;
Location loc;
- Location lastLoc;
+ Location lastLocation_;
QMap<QString, Location> locMap;
- QMap<QString, QStringList> stringListValueMap;
QMap<QString, QString> stringValueMap;
+ QMap<QString, QStringList> stringListValueMap;
+
+ QStringPairMap stringPairMap;
+ QStringListPairMap stringListPairMap;
static QMap<QString, QString> uncompressedFiles;
static QMap<QString, QString> extractedDirs;
static int numInstances;
+ static QStack<QString> workingDirs_;
};
#define CONFIG_ALIAS "alias"
if (!best.isEmpty() && !documentedItems.contains(best))
details = tr("Maybe you meant '%1'?").arg(best);
- node->doc().location().warning(tr("No such enum item '%1' in %2").arg(*a).arg(node->plainFullName()), details);
+ node->doc().location().warning(tr("No such enum item '%1' in %2")
+ .arg(*a).arg(node->plainFullName()), details);
if (*a == "Void")
qDebug() << "VOID:" << node->name() << definedItems;
}
else if (!documentedItems.contains(*a)) {
- node->doc().location().warning(tr("Undocumented enum item '%1' in %2").arg(*a).arg(node->plainFullName()));
+ node->doc().location().warning(tr("Undocumented enum item '%1' in %2")
+ .arg(*a).arg(node->plainFullName()));
}
++a;
}
if (outputFormats.contains((*g)->format())) {
currentGenerator_ = (*g);
(*g)->initializeGenerator(config);
- QStringList extraImages = config.getCleanPathList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format());
+ QStringList extraImages =
+ config.getCleanPathList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format());
QStringList::ConstIterator e = extraImages.constBegin();
while (e != extraImages.constEnd()) {
QString userFriendlyFilePath;
Config::copyFile(config.lastLocation(),
filePath,
userFriendlyFilePath,
- (*g)->outputDir() +
- "/images");
+ (*g)->outputDir() + "/images");
++e;
}
// Documentation template handling
QStringList searchDirs;
- QString templateDir = config.getString((*g)->format() + Config::dot + CONFIG_TEMPLATEDIR);
- qDebug() << "TEMPLATEDIR:" << templateDir << (*g)->format() + Config::dot + CONFIG_TEMPLATEDIR;
+ QString templateDir = config.getPath((*g)->format() + Config::dot + CONFIG_TEMPLATEDIR);
+ qDebug() << "TEMPLATEDIR:" << templateDir
+ << (*g)->format() + Config::dot + CONFIG_TEMPLATEDIR;
if (templateDir.isEmpty())
templateDir = ".";
searchDirs.append(templateDir);
Config::copyFile(config.lastLocation(),
filePath,
userFriendlyFilePath,
- (*g)->outputDir() +
- "/scripts");
+ (*g)->outputDir() + "/scripts");
++e;
}
- QStringList styles = config.getCleanPathList((*g)->format()+Config::dot+CONFIG_STYLESHEETS);
+ //QStringList styles = config.getCleanPathList((*g)->format()+Config::dot+CONFIG_STYLESHEETS);
+ QStringList styles = config.getPathList((*g)->format()+Config::dot+CONFIG_STYLESHEETS);
qDebug() << "STYLES:" << styles;
- qDebug() << "SEARCHDIRS:" << searchDirs;
- qDebug() << "STYLEFILES:" << styleFiles;
- Config::debug = true;
e = styles.constBegin();
while (e != styles.constEnd()) {
- QString userFriendlyFilePath;
- QString filePath = Config::findFile(config.lastLocation(),
- styleFiles,
- searchDirs,
- *e,
- noExts,
- userFriendlyFilePath);
+ QString filePath = *e;
qDebug() << "FILEPATH:" << filePath;
if (!filePath.isEmpty())
Config::copyFile(config.lastLocation(),
filePath,
- userFriendlyFilePath,
- (*g)->outputDir() +
- "/style");
+ filePath,
+ (*g)->outputDir() + "/style");
++e;
}
- Config::debug = false;
}
++g;
}