diff options
author | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2015-06-08 13:19:36 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2015-06-11 12:01:05 +0300 |
commit | eb59317a2d0ede87595991bb5c10b8466c5ed8ff (patch) | |
tree | dd4cb2954a1f54e4a18eb0ca1fceaf6474ec0a16 /tools | |
parent | 44e30ecea75afc02eda544a250164974c7ba6221 (diff) |
Moved qscxmlc, examples, and tests to correct places.
Change-Id: I943df1ba0c3cecaf54decc59526d6f4334b480db
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qscxmlc/qscxmlc.cpp | 128 | ||||
-rw-r--r-- | tools/qscxmlc/qscxmlc.pro | 9 | ||||
-rw-r--r-- | tools/tools.pro | 2 |
3 files changed, 139 insertions, 0 deletions
diff --git a/tools/qscxmlc/qscxmlc.cpp b/tools/qscxmlc/qscxmlc.cpp new file mode 100644 index 0000000..0a28286 --- /dev/null +++ b/tools/qscxmlc/qscxmlc.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** + ** + ** Copyright (c) 2015 Digia Plc + ** For any questions to Digia, please use contact form at http://qt.digia.com/ + ** + ** All Rights Reserved. + ** + ** NOTICE: All information contained herein is, and remains + ** the property of Digia Plc and its suppliers, + ** if any. The intellectual and technical concepts contained + ** herein are proprietary to Digia Plc + ** and its suppliers and may be covered by Finnish and Foreign Patents, + ** patents in process, and are protected by trade secret or copyright law. + ** Dissemination of this information or reproduction of this material + ** is strictly forbidden unless prior written permission is obtained + ** from Digia Plc. + ****************************************************************************/ + +#include <QScxml/scxmlparser.h> +#include <QScxml/scxmlcppdumper.h> + +#include <QCoreApplication> +#include <QFile> +#include <QFileInfo> + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + QStringList args = a.arguments(); + QString usage = QStringLiteral("\nusage: %1 [-namespace <namespace>] [-o <base/out/name>] [-oh <header/out>] [-ocpp <cpp/out>] [-use-private-api]\n").arg(QFileInfo(args.value(0)).baseName()); + usage += QStringLiteral(" [-classname <stateMachineClassName>] [-name-qobjects] <input.scxml>\n\n"); + usage += QStringLiteral("compiles the given input.scxml file to a header and cpp file\n"); + + QTextStream errs(stderr, QIODevice::WriteOnly); + QTextStream outs(stderr, QIODevice::WriteOnly); + + Scxml::CppDumpOptions options; + QString scxmlFileName; + QString outFileName; + QString outHFileName; + QString outCppFileName; + for (int iarg = 1; iarg < args.size(); ++iarg) { + QString arg = args.at(iarg); + if (arg == QLatin1String("-namespace")) { + options.namespaceName = args.value(++iarg); + } else if (arg == QLatin1String("-o")) { + outFileName = args.value(++iarg); + } else if (arg == QLatin1String("-oh")) { + outHFileName = args.value(++iarg); + } else if (arg == QLatin1String("-ocpp")) { + outCppFileName = args.value(++iarg); + } else if (arg == QLatin1String("-use-private-api")) { + options.usePrivateApi = true; + } else if (arg == QLatin1String("-classname")) { + options.classname = args.value(++iarg); + } else if (arg == QLatin1String("-name-qobjects")) { + options.nameQObjects = true; + } else if (scxmlFileName.isEmpty()) { + scxmlFileName = arg; + } else { + errs << QStringLiteral("Unexpected argument: %1").arg(arg) << endl; + errs << usage; + exit(-1); + } + } + if (scxmlFileName.isEmpty()) { + errs << QStringLiteral("Error: no input files.") << endl; + exit(-2); + } + QFile file(scxmlFileName); + if (!file.open(QFile::ReadOnly)) { + errs << QStringLiteral("Error: cannot open input file %1").arg(scxmlFileName); + exit(-3); + } + if (outFileName.isEmpty()) + outFileName = QFileInfo(scxmlFileName).baseName(); + if (outHFileName.isEmpty()) + outHFileName = outFileName + QLatin1String(".h"); + if (outCppFileName.isEmpty()) + outCppFileName = outFileName + QLatin1String(".cpp"); + + QXmlStreamReader reader(&file); + Scxml::ScxmlParser parser(&reader, + Scxml::ScxmlParser::loaderForDir(QFileInfo(file.fileName()).absolutePath())); + parser.setFileName(file.fileName()); + parser.parse(); + if (!parser.errors().isEmpty()) { + foreach (const Scxml::ErrorMessage &error, parser.errors()) { + errs << error.fileName + << QLatin1Char(':') + << error.line + << QLatin1Char(':') + << error.column + << QStringLiteral(": ") + << error.severityString() + << QStringLiteral(": ") + << error.msg + << endl; + } + return -7; + } + + if (auto doc = parser.scxmlDocument()) { + QFile outH(outHFileName); + if (!outH.open(QFile::WriteOnly)) { + errs << QStringLiteral("Error: cannot open '%1': %2").arg(outH.fileName(), outH.errorString()) << endl; + exit(-4); + } + + QFile outCpp(outCppFileName); + if (!outCpp.open(QFile::WriteOnly)) { + errs << QStringLiteral("Error: cannot open '%1': %2").arg(outCpp.fileName(), outCpp.errorString()) << endl; + exit(-5); + } + + QTextStream h(&outH); + QTextStream c(&outCpp); + Scxml::CppDumper dumper(h, c, QFileInfo(outH).fileName(), options); + dumper.dump(doc); + outH.close(); + outCpp.close(); + a.exit(); + return 0; + } else { + a.exit(); + return -6; + } +} diff --git a/tools/qscxmlc/qscxmlc.pro b/tools/qscxmlc/qscxmlc.pro new file mode 100644 index 0000000..c1c8e57 --- /dev/null +++ b/tools/qscxmlc/qscxmlc.pro @@ -0,0 +1,9 @@ +option(host_build) +QT += core qml qscxml + +TARGET = qscxmlc +CONFIG += console c++11 + +SOURCES += qscxmlc.cpp + +load(qt_tool) diff --git a/tools/tools.pro b/tools/tools.pro new file mode 100644 index 0000000..315133a --- /dev/null +++ b/tools/tools.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += qscxmlc |