add bindings for QGraphicsSceneDragDropEvent
[qtscriptgenerator.git] / generator / main.h
blob88a88f481b3d710ee0f0d6a4f4753afde3eb8340
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 #ifndef MAIN_H
25 #define MAIN_H
27 #include "pp.h"
29 #include <QFile>
30 #include <QDir>
32 struct Preprocess
34 static bool preprocess(const QString &sourceFile, const QString &targetFile, const QString &commandLineIncludes = QString())
36 rpp::pp_environment env;
37 rpp::pp preprocess(env);
39 rpp::pp_null_output_iterator null_out;
41 const char *ppconfig = ":/trolltech/generator/parser/rpp/pp-qt-configuration";
43 QFile file(ppconfig);
44 if (!file.open(QFile::ReadOnly)) {
45 fprintf(stderr, "Preprocessor configuration file not found '%s'\n", ppconfig);
46 return false;
49 QByteArray ba = file.readAll();
50 file.close();
51 preprocess.operator() (ba.constData(), ba.constData() + ba.size(), null_out);
53 QStringList includes;
54 includes << QString(".");
56 #if defined(Q_OS_WIN32)
57 char *path_splitter = ";";
58 #else
59 const char *path_splitter = ":";
60 #endif
62 // Environment INCLUDE
63 QString includePath = getenv("INCLUDE");
64 if (!includePath.isEmpty())
65 includes += includePath.split(path_splitter);
67 // Includes from the command line
68 if (!commandLineIncludes.isEmpty())
69 includes += commandLineIncludes.split(path_splitter);
71 // Include Qt
72 QString qtdir = getenv ("QTDIR");
73 if (qtdir.isEmpty()) {
74 #if defined(Q_OS_MAC)
75 qWarning("QTDIR environment variable not set. Assuming standard binary install using frameworks.");
76 QString frameworkDir = "/Library/Frameworks";
77 includes << (frameworkDir + "/QtXml.framework/Headers");
78 includes << (frameworkDir + "/QtNetwork.framework/Headers");
79 includes << (frameworkDir + "/QtCore.framework/Headers");
80 includes << (frameworkDir + "/QtGui.framework/Headers");
81 includes << (frameworkDir + "/QtOpenGL.framework/Headers");
82 includes << frameworkDir;
83 #else
84 qWarning("QTDIR environment variable not set. This may cause problems with finding the necessary include files.");
85 #endif
86 } else {
87 qtdir += "/include";
88 includes << (qtdir + "/QtXml");
89 includes << (qtdir + "/QtNetwork");
90 includes << (qtdir + "/QtCore");
91 includes << (qtdir + "/QtGui");
92 includes << (qtdir + "/QtOpenGL");
93 includes << qtdir;
96 foreach (QString include, includes)
97 preprocess.push_include_path(QDir::convertSeparators(include).toStdString());
99 QString currentDir = QDir::current().absolutePath();
100 QFileInfo sourceInfo(sourceFile);
101 QDir::setCurrent(sourceInfo.absolutePath());
103 std::string result;
104 result.reserve (20 * 1024); // 20K
106 result += "# 1 \"builtins\"\n";
107 result += "# 1 \"";
108 result += sourceFile.toStdString();
109 result += "\"\n";
111 preprocess.file (sourceInfo.fileName().toStdString(),
112 rpp::pp_output_iterator<std::string> (result));
114 QDir::setCurrent(currentDir);
116 QFile f(targetFile);
117 if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) {
118 fprintf(stderr, "Failed to write preprocessed file: %s\n", qPrintable(targetFile));
120 f.write(result.c_str(), result.length());
122 return true;
126 #endif // MAIN_H