| f1f7973 by No'am Rosenthal at 2009-08-10 |
1 |
/**************************************************************************** |
|
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 3d88526 by No'am Rosenthal at 2009-11-26 |
4 |
** All rights reserved. |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
| 3d88526 by No'am Rosenthal at 2009-11-26 |
7 |
** This file is part of SCXML on Qt labs |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
| 3d88526 by No'am Rosenthal at 2009-11-26 |
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
| 3d88526 by No'am Rosenthal at 2009-11-26 |
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
|
|
42 |
#include <QCoreApplication> |
| 82c237b by No'am Rosenthal at 2009-08-07 |
43 |
#include <QXmlQuery> |
|
44 |
#include <QUrl> |
|
45 |
#include <QStringList> |
|
46 |
#include <QFile> |
|
47 |
#include <QFileInfo> |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
48 |
#include <QDir> |
|
49 |
#include <QDebug> |
|
50 |
#include <QXmlSchema> |
|
51 |
#include <QXmlSchemaValidator> |
|
52 |
void usage() |
|
53 |
{ |
|
54 |
printf("scc [--no-comments] -i input-file -o output-file"); |
|
55 |
exit(-1); |
|
56 |
} |
| 82c237b by No'am Rosenthal at 2009-08-07 |
57 |
int main(int argc, char *argv[]) |
|
58 |
{ |
|
59 |
QCoreApplication a(argc, argv); |
|
60 |
QXmlQuery query(QXmlQuery::XSLT20); |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
61 |
if (a.arguments().count() < 3 || a.arguments().contains("--help")) |
|
62 |
{ |
|
63 |
usage(); |
|
64 |
} |
|
65 |
int idxOfInput = a.arguments().indexOf("-i")+1; |
|
66 |
int idxOfOutput = a.arguments().indexOf("-o")+1; |
|
67 |
if (idxOfInput <= 1 && idxOfOutput <= 1) |
|
68 |
{ |
|
69 |
usage(); |
|
70 |
} |
|
71 |
QString input = a.arguments().at(idxOfInput); |
|
72 |
QString output = a.arguments().at(idxOfOutput); |
|
73 |
QUrl target = QUrl::fromLocalFile(QDir::current().absoluteFilePath(".")).resolved(QUrl(input)); |
|
74 |
// QXmlSchema schema; |
|
75 |
// QFile schemaFile(":/scxml.xsd"); |
|
76 |
// schemaFile.open(QIODevice::ReadOnly); |
|
77 |
// schema.load(&schemaFile); |
|
78 |
// QXmlSchemaValidator validator; |
|
79 |
// if (!validator.validate(target)) { |
|
80 |
// return -1; |
|
81 |
// } |
| 82c237b by No'am Rosenthal at 2009-08-07 |
82 |
query.setFocus(target); |
|
83 |
QFile q(":/scc/scc.xslt"); |
|
84 |
q.open(QIODevice::ReadOnly); |
|
85 |
query.bindVariable("target",QXmlItem(QFileInfo(target.toLocalFile()).baseName())); |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
86 |
query.bindVariable("comments",QXmlItem(!a.arguments().contains("--no-comments"))); |
| 82c237b by No'am Rosenthal at 2009-08-07 |
87 |
query.setQuery(QString(q.readAll())); |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
88 |
if (!query.isValid()) |
|
89 |
return -1; |
|
90 |
|
| 82c237b by No'am Rosenthal at 2009-08-07 |
91 |
QString s; |
|
92 |
query.evaluateTo(&s); |
| f1f7973 by No'am Rosenthal at 2009-08-10 |
93 |
s = s.replace("<","<").replace(""","\"").replace(">",">").replace("&","&"); |
|
94 |
QFile f(output); |
| 82c237b by No'am Rosenthal at 2009-08-07 |
95 |
f.open(QIODevice::WriteOnly); |
|
96 |
f.write(s.toUtf8()); |
|
97 |
return 0; |
|
98 |
// return a.exec(); |
|
99 |
} |