add bindings for QGraphicsSceneDragDropEvent
[qtscriptgenerator.git] / generator / main.cpp
blob21d633a514b317eb0f090c0e143b1de157d26df5
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 **
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 ****************************************************************************/
24 #include "main.h"
25 #include "asttoxml.h"
26 #include "reporthandler.h"
27 #include "typesystem.h"
28 #include "generatorset.h"
29 #include "fileout.h"
31 #include <QDir>
33 void displayHelp(GeneratorSet *generatorSet);
35 #include <QDebug>
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";
43 QString fileName;
44 QString typesystemFileName;
45 QString pp_file = ".preprocessed.tmp";
46 QStringList rebuild_classes;
48 QMap<QString, QString> args;
50 int argNum = 0;
51 for (int i=1; i<argc; ++i) {
52 QString arg(argv[i]);
53 arg = arg.trimmed();
54 if( arg.startsWith("--") ) {
55 int split = arg.indexOf("=");
56 if( split > 0 )
57 args[arg.mid(2).left(split-2)] = arg.mid(split + 1).trimmed();
58 else
59 args[arg.mid(2)] = QString();
60 } else if( arg.startsWith("-")) {
61 args[arg.mid(1)] = QString();
62 } else {
63 argNum++;
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")) {
88 FileOut::diff = true;
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"))
103 displayHelp(gs);
105 if (fileName.isEmpty())
106 fileName = default_file;
108 if (typesystemFileName.isEmpty())
109 typesystemFileName = default_system;
111 if (fileName.isEmpty() || typesystemFileName.isEmpty() )
112 displayHelp(gs);
114 if (!gs->readParameters(args))
115 displayHelp(gs);
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));
124 return 1;
127 if (args.contains("ast-to-xml")) {
128 astToXML(pp_file);
129 return 0;
132 gs->buildModel(pp_file);
133 if (args.contains("dump-object-tree")) {
134 gs->dumpObjectTree();
135 return 0;
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 = ';';
147 #else
148 char path_splitter = ':';
149 #endif
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()));
163 exit(0);