1 /****************************************************************************
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
26 #include "reporthandler.h"
27 #include "typesystem.h"
28 #include "generatorset.h"
33 void displayHelp(GeneratorSet
*generatorSet
);
36 int main(int argc
, char *argv
[])
38 GeneratorSet
*gs
= GeneratorSet::getInstance();
40 QString default_file
= ":/trolltech/generator/qtscript_masterinclude.h";
41 QString default_system
= ":/trolltech/generator/build_all.txt";
44 QString typesystemFileName
;
45 QString pp_file
= ".preprocessed.tmp";
46 QStringList rebuild_classes
;
48 QMap
<QString
, QString
> args
;
51 for (int i
=1; i
<argc
; ++i
) {
54 if( arg
.startsWith("--") ) {
55 int split
= arg
.indexOf("=");
57 args
[arg
.mid(2).left(split
-2)] = arg
.mid(split
+ 1).trimmed();
59 args
[arg
.mid(2)] = QString();
60 } else if( arg
.startsWith("-")) {
61 args
[arg
.mid(1)] = QString();
64 args
[QString("arg-%1").arg(argNum
)] = arg
;
68 if (args
.contains("no-suppress-warnings")) {
69 TypeDatabase
*db
= TypeDatabase::instance();
70 db
->setSuppressWarnings(false);
73 if (args
.contains("debug-level")) {
74 QString level
= args
.value("debug-level");
75 if (level
== "sparse")
76 ReportHandler::setDebugLevel(ReportHandler::SparseDebug
);
77 else if (level
== "medium")
78 ReportHandler::setDebugLevel(ReportHandler::MediumDebug
);
79 else if (level
== "full")
80 ReportHandler::setDebugLevel(ReportHandler::FullDebug
);
83 if (args
.contains("dummy")) {
84 FileOut::dummy
= true;
87 if (args
.contains("diff")) {
91 if (args
.contains("license"))
92 FileOut::license
= true;
94 if (args
.contains("rebuild-only")) {
95 QStringList classes
= args
.value("rebuild-only").split(",", QString::SkipEmptyParts
);
96 TypeDatabase::instance()->setRebuildClasses(classes
);
99 fileName
= args
.value("arg-1");
101 typesystemFileName
= args
.value("arg-2");
102 if (args
.contains("arg-3"))
105 if (fileName
.isEmpty())
106 fileName
= default_file
;
108 if (typesystemFileName
.isEmpty())
109 typesystemFileName
= default_system
;
111 if (fileName
.isEmpty() || typesystemFileName
.isEmpty() )
114 if (!gs
->readParameters(args
))
117 printf("Please wait while source files are being generated...\n");
119 if (!TypeDatabase::instance()->parseFile(typesystemFileName
))
120 qFatal("Cannot parse file: '%s'", qPrintable(typesystemFileName
));
122 if (!Preprocess::preprocess(fileName
, pp_file
, args
.value("include-paths"))) {
123 fprintf(stderr
, "Preprocessor failed on file: '%s'\n", qPrintable(fileName
));
127 if (args
.contains("ast-to-xml")) {
132 gs
->buildModel(pp_file
);
133 if (args
.contains("dump-object-tree")) {
134 gs
->dumpObjectTree();
137 printf("%s\n", qPrintable(gs
->generate()));
139 printf("Done, %d warnings (%d known issues)\n", ReportHandler::warningCount(),
140 ReportHandler::suppressedCount());
144 void displayHelp(GeneratorSet
* generatorSet
) {
145 #if defined(Q_OS_WIN32)
146 char path_splitter
= ';';
148 char path_splitter
= ':';
150 printf("Usage:\n generator [options] header-file typesystem-file\n\n");
151 printf("Available options:\n\n");
152 printf("General:\n");
153 printf(" --debug-level=[sparse|medium|full] \n"
154 " --dump-object-tree \n"
155 " --help, -h or -? \n"
156 " --no-suppress-warnings \n"
157 " --output-directory=[dir] \n"
158 " --include-paths=<path>[%c<path>%c...] \n"
159 " --print-stdout \n",
160 path_splitter
, path_splitter
);
162 printf("%s", qPrintable( generatorSet
->usage()));