diff options
author | denes dezso <matusz@matusz.tietoenator.com> | 2010-05-11 09:16:03 +0300 |
---|---|---|
committer | Mike FABIAN <mike.fabian@basyskom.de> | 2010-05-13 11:56:02 +0200 |
commit | 131ebf6e5d4a4f99fb8aefebdcc734f1313511f1 (patch) | |
tree | e1c3166e9c0965da5bc541ca8fe4a925728dbdd3 /mmoc | |
parent | bc250ae79c70f97a6674bb9e80acb84a586bfba2 (diff) |
Fixes: NB#156286 - duimoc doesn't work for some header files.
RevBy: Tomas Junnonen
Diffstat (limited to 'mmoc')
-rwxr-xr-x | mmoc/mmoc | bin | 4215 -> 853942 bytes | |||
-rw-r--r-- | mmoc/mmoc.cpp | 216 | ||||
-rw-r--r-- | mmoc/mmoc.pro | 46 |
3 files changed, 250 insertions, 12 deletions
Binary files differ diff --git a/mmoc/mmoc.cpp b/mmoc/mmoc.cpp new file mode 100644 index 00000000..38785887 --- /dev/null +++ b/mmoc/mmoc.cpp @@ -0,0 +1,216 @@ +#include <QtGlobal> +#include <QFileInfo> +#include <QDir> +#include <QProcess> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <string.h> +#include <QtDebug> + + +void runModelMoc(const QString& header, const QStringList& arguments) +{ + QFile inf(header); + if(!inf.open(QFile::ReadOnly)) + qFatal("Could not open header file for reading"); + + QTextStream in(&inf); + + QProcess p; + p.start(QString(QT_MOC_PATH), arguments, QIODevice::WriteOnly); + if(!p.waitForStarted()) { + qFatal("mmoc: failed to run command '%s'", QT_MOC_PATH); + } + + QString spaces = "\\s*"; + QString comma = ","; + QString colon = ":"; + QString parenO = "\\("; + QString parenC = "\\)"; + QString emptyParen = "\\(\\)"; + QString angleO = "<"; + QString angleC = ">"; + QString braceO = "\\{"; + QString nameSpace = "(?:\\w+::)"; + QString typeName = "\\w+"; + QString pointer = "\\*"; + QString templateName = "\\w+"; + QString plainParam = "(\\w+)"; + QString boolParam = "(true|false)"; + QString anyParam = "(.+)"; + + QRegExp propertyRegExp( + spaces+ + "M_MODEL_PROPERTY"+ + spaces+parenO+spaces+ + "("+ + "(?:"+ + nameSpace+"{,1}"+ + typeName+ + spaces+ + pointer+"{,1}"+ + ")"+ + "|"+ + "(?:"+ + templateName+ + angleO+ + spaces+ + typeName+ + spaces+ + pointer+"{,1}"+ + spaces+ + angleC+ + ")"+ + ")"+ + spaces+comma+spaces+ + plainParam+ + spaces+comma+spaces+ + plainParam+ + spaces+comma+spaces+ + plainParam+ + spaces+comma+spaces+ + anyParam+ + spaces+parenC+spaces ); + + QRegExp propertyPtrRegExp( + spaces+ + "M_MODEL_PTR_PROPERTY"+ + spaces+parenO+spaces+ + "("+ + "(?:"+ + nameSpace+"{,1}"+ + typeName+ + spaces+ + pointer+"{,1}"+ + spaces+ + ")"+ + "|"+ + "(?:"+ + templateName+ + angleO+ + spaces+ + typeName+ + spaces+ + pointer+"{,1}"+ + spaces+ + angleC+ + ")"+ + ")"+ + spaces+comma+spaces+ + plainParam+ + spaces+comma+spaces+ + plainParam+ + spaces+comma+spaces+ + boolParam+ + spaces+comma+spaces+ + anyParam+ + spaces+parenC+spaces ); + + QString line; + while(true) { + line = in.readLine(); + if(line.isNull()) { + break; + } + + line.replace(propertyRegExp, " Q_PROPERTY(\\1 \\2 READ \\2 WRITE set\\3)"); + line.replace(propertyPtrRegExp, " Q_PROPERTY(\\1 \\2 READ \\2 WRITE set\\3)"); + p.write(QString(line + "\n").toLatin1()); + } + p.closeWriteChannel(); + + if(!p.waitForFinished()) { + qFatal("mmoc: failed to run command '%s'", QT_MOC_PATH); + } +} + +void runStyleMoc(const QString& header, const QStringList& arguments) +{ + QFile inf(header); + if(!inf.open(QFile::ReadOnly)) + qFatal("Could not open header file for reading"); + + QTextStream in(&inf); + + QProcess p; + p.start(QString(QT_MOC_PATH), arguments); + if(!p.waitForStarted()) { + qFatal("mmoc: failed to run command '%s'", QT_MOC_PATH); + } + + + QRegExp attributeRegExp("\\s*M_STYLE_ATTRIBUTE\\s*\\(\\s*(\\w+\\:*\\w*)\\s*,\\s*(\\w+)\\s*,\\s*(\\w+)\\s*\\)\\s*"); + QRegExp attributePtrRegExp("\\s*M_STYLE_PTR_ATTRIBUTE\\s*\\(\\s*(\\w+\\:*\\w*\\s*\\*+)\\s*,\\s*(\\w+)\\s*,\\s*(\\w+)\\s*\\)\\s*"); + + + QString line; + while(true) { + line = in.readLine(); + if(line.isNull()) { + break; + } + + line.replace(attributeRegExp, " Q_PROPERTY(\\1 \\2 READ \\2 WRITE set\\3)"); + line.replace(attributePtrRegExp, " Q_PROPERTY(const \\1 \\2 READ \\2 WRITE set\\3)"); + p.write(QString(line + "\n").toLatin1()); + } + p.closeWriteChannel(); + + if(!p.waitForFinished()) { + qFatal("mmoc: failed to run command '%s'", QT_MOC_PATH); + } +} + +enum HeaderType { + Model, + Style +}; + +int main(int argc, const char *argv[]) +{ + HeaderType type=Model; + QStringList commandLineParameters; + QString filename; + char* mocArgv[argc+1]; + int result; + pid_t pid; + + mocArgv[0] = strdup(QT_MOC_PATH); + mocArgv[argc] = NULL; + + for(int i=1; i<argc; ++i) { + if(QString(argv[i]).endsWith("style.h")) { + type = Style; + filename = argv[i]; + } else if(QString(argv[i]).endsWith("model.h")) { + type = Model; + filename = argv[i]; + } else { + commandLineParameters << QString(argv[i]); + mocArgv[i] = (char*) argv[i]; + } + } + + if(filename.isEmpty()) { + if((pid = fork()) == 0) { + exit(execv(QT_MOC_PATH, mocArgv)); + } + waitpid(pid, &result, 0); + if(result != 0) { + qFatal("mmoc: failed to run command '%s'", QT_MOC_PATH); + } + } else { + commandLineParameters << "-f" + filename; + if(type == Model) { + runModelMoc(filename, commandLineParameters); + } else if(type == Style) { + runStyleMoc(filename, commandLineParameters); + } + } + + free(mocArgv[0]); + return 0; //success +} + diff --git a/mmoc/mmoc.pro b/mmoc/mmoc.pro index 4541841d..6b8d2a44 100644 --- a/mmoc/mmoc.pro +++ b/mmoc/mmoc.pro @@ -1,20 +1,42 @@ include(../mkspecs/common.pri) -TEMPLATE = subdirs -SUBDIRS = +TEMPLATE = app +TARGET = mmoc +target.path = $$M_INSTALL_BIN +INCLUDEPATH += . +DEPENDPATH += $$INCLUDEPATH + +# enable QString optimizations +DEFINES += QT_USE_FAST_CONCATENATION QT_USE_FAST_OPERATOR_PLUS + +# Check for mixing of const and non-const iterators, +# which can cause problems when built with some compilers: +DEFINES += QT_STRICT_ITERATORS + +win32-msvc*:{ + target.commands += copy release\mmoc.exe . +} + +# Dont generate mmoc.app bundle for Mac OS X +macx:CONFIG -= app_bundle +CONFIG += \ + qt \ + +SOURCES += \ + mmoc.cpp \ + +HEADERS += \ + + +INSTALLS += \ + target\ + +DEFINES += QT_MOC_PATH=\'$$quote(\"$$QMAKE_MOC\")\' QMAKE_EXTRA_TARGETS += check -check.depends = +check.depends = $${TARGET} check.commands = $$system(true) QMAKE_EXTRA_TARGETS += check-xml -check-xml.depends = +check-xml.depends = $${TARGET} check-xml.commands = $$system(true) - -mmoc.target = .dummy -mmoc.commands = touch $$mmoc.target -mmoc.path = $$M_INSTALL_BIN -mmoc.files = mmoc - -INSTALLS += \ - mmoc\ |