0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the tools applications of the Qt Toolkit.
|
|
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
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
**
|
|
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 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#ifdef MOC_MWERKS_PLUGIN
|
|
43 |
|
|
44 |
#include "mwerks_mac.h"
|
|
45 |
#include "qt_mac.h"
|
|
46 |
|
|
47 |
/* compiler headers */
|
|
48 |
#include "DropInCompilerLinker.h"
|
|
49 |
#include "CompilerMapping.h"
|
|
50 |
#include "CWPluginErrors.h"
|
|
51 |
|
|
52 |
/* standard headers */
|
|
53 |
#include <stdio.h>
|
|
54 |
#include <string.h>
|
|
55 |
|
|
56 |
QT_BEGIN_NAMESPACE
|
|
57 |
|
|
58 |
//qglobal.cpp
|
|
59 |
const unsigned char * p_str(const char * c);
|
|
60 |
QCString pstring2qstring(const unsigned char *c);
|
|
61 |
|
|
62 |
#if CW_USE_PRAGMA_EXPORT
|
|
63 |
#pragma export on
|
|
64 |
#endif
|
|
65 |
|
|
66 |
CWPLUGIN_ENTRY(CWPlugin_GetDropInFlags)(const DropInFlags** flags, long* flagsSize)
|
|
67 |
{
|
|
68 |
static const DropInFlags sFlags = {
|
|
69 |
kCurrentDropInFlagsVersion,
|
|
70 |
CWDROPINCOMPILERTYPE,
|
|
71 |
DROPINCOMPILERLINKERAPIVERSION_7,
|
|
72 |
kCompAlwaysReload|kCompRequiresProjectBuildStartedMsg,
|
|
73 |
Lang_C_CPP,
|
|
74 |
DROPINCOMPILERLINKERAPIVERSION
|
|
75 |
};
|
|
76 |
*flags = &sFlags;
|
|
77 |
*flagsSize = sizeof(sFlags);
|
|
78 |
return cwNoErr;
|
|
79 |
}
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
CWPLUGIN_ENTRY(CWPlugin_GetDropInName)(const char** dropinName)
|
|
84 |
{
|
|
85 |
static const char sDropInName[] = "McMoc";
|
|
86 |
*dropinName = sDropInName;
|
|
87 |
return cwNoErr;
|
|
88 |
}
|
|
89 |
|
|
90 |
CWPLUGIN_ENTRY(CWPlugin_GetDisplayName)(const char** displayName)
|
|
91 |
{
|
|
92 |
static const char sDisplayName[] = "McMoc";
|
|
93 |
*displayName = sDisplayName;
|
|
94 |
return cwNoErr;
|
|
95 |
}
|
|
96 |
|
|
97 |
CWPLUGIN_ENTRY(CWPlugin_GetTargetList)(const CWTargetList** targetList)
|
|
98 |
{
|
|
99 |
static CWDataType sCPU = targetCPUAny;
|
|
100 |
static CWDataType sOS = targetOSMacintosh;
|
|
101 |
static CWTargetList sTargetList = {kCurrentCWTargetListVersion, 1, &sCPU, 1, &sOS};
|
|
102 |
*targetList = &sTargetList;
|
|
103 |
return cwNoErr;
|
|
104 |
}
|
|
105 |
|
|
106 |
CWPLUGIN_ENTRY(CWPlugin_GetDefaultMappingList)(const CWExtMapList** defaultMappingList)
|
|
107 |
{
|
|
108 |
static CWExtensionMapping sExtension[] = { {'TEXT', ".mocs", kPrecompile } };
|
|
109 |
static CWExtMapList sExtensionMapList = {kCurrentCWExtMapListVersion, 3, sExtension};
|
|
110 |
*defaultMappingList = &sExtensionMapList;
|
|
111 |
return cwNoErr;
|
|
112 |
}
|
|
113 |
|
|
114 |
#if CW_USE_PRAGMA_EXPORT
|
|
115 |
#pragma export off
|
|
116 |
#endif
|
|
117 |
typedef short CWFileRef;
|
|
118 |
|
|
119 |
static int line_count = 0;
|
|
120 |
moc_status do_moc(CWPluginContext, const QCString &, const QCString &, CWFileSpec *, bool);
|
|
121 |
|
|
122 |
static CWResult mocify(CWPluginContext context, const QCString &source)
|
|
123 |
{
|
|
124 |
CWDisplayLines(context, line_count++);
|
|
125 |
|
|
126 |
source.stripWhiteSpace();
|
|
127 |
|
|
128 |
CWResult err;
|
|
129 |
bool dotmoc=false;
|
|
130 |
QCString stem = source, ext;
|
|
131 |
int dotpos = stem.findRev('.');
|
|
132 |
if(dotpos != -1) {
|
|
133 |
ext = stem.right(stem.length() - (dotpos+1));
|
|
134 |
stem = stem.left(dotpos);
|
|
135 |
if(ext == "cpp")
|
|
136 |
dotmoc = true;
|
|
137 |
} else {
|
|
138 |
//whoa!
|
|
139 |
}
|
|
140 |
QCString dest;
|
|
141 |
if(dotmoc)
|
|
142 |
dest = stem + ".moc";
|
|
143 |
else
|
|
144 |
dest = "moc_" + stem + ".cpp";
|
|
145 |
|
|
146 |
//moc it
|
|
147 |
CWFileSpec destSpec;
|
|
148 |
moc_status mocd = do_moc(context, source, dest, &destSpec, dotmoc);
|
|
149 |
|
|
150 |
#if 0
|
|
151 |
QCString derr = "Weird";
|
|
152 |
switch(mocd) {
|
|
153 |
case moc_success: derr = "Success"; break;
|
|
154 |
case moc_parse_error: derr = "Parser Error"; break;
|
|
155 |
case moc_no_qobject:derr = "No QOBJECT"; break;
|
|
156 |
case moc_not_time: derr = "Not Time"; break;
|
|
157 |
case moc_no_source: derr = "No Source"; break;
|
|
158 |
case moc_general_error: derr = "General Error"; break;
|
|
159 |
}
|
|
160 |
char dmsg[200];
|
|
161 |
sprintf(dmsg, "\"%s\" %s", source.data(), derr.data());
|
|
162 |
CWReportMessage(context, NULL, dmsg, NULL, messagetypeError, 0);
|
|
163 |
#endif
|
|
164 |
|
|
165 |
//handle project
|
|
166 |
if(mocd == moc_no_qobject) {
|
|
167 |
char msg[400];
|
|
168 |
sprintf(msg, "\"%s\" No relevant classes found. No output generated.", source.data());
|
|
169 |
CWReportMessage(context, NULL, msg, NULL, messagetypeWarning, 0);
|
|
170 |
} else if ((mocd == moc_success || mocd == moc_not_time) && !dotmoc)
|
|
171 |
{
|
|
172 |
long whichFile;
|
|
173 |
CWNewProjectEntryInfo ei;
|
|
174 |
memset(&ei, '\0', sizeof(ei));
|
|
175 |
ei.groupPath = "QtGenerated";
|
|
176 |
err = CWAddProjectEntry(context, &destSpec, true, &ei, &whichFile);
|
|
177 |
if (!CWSUCCESS(err))
|
|
178 |
{
|
|
179 |
char msg[200];
|
|
180 |
sprintf(msg, "\"%s\" not added", dest.data());
|
|
181 |
CWReportMessage(context, NULL, msg, NULL, messagetypeWarning, 0);
|
|
182 |
}
|
|
183 |
if(mocd == moc_success)
|
|
184 |
CWSetModDate(context, &destSpec, NULL, true);
|
|
185 |
}
|
|
186 |
return cwNoErr;
|
|
187 |
}
|
|
188 |
|
|
189 |
pascal short main(CWPluginContext context)
|
|
190 |
{
|
|
191 |
short result;
|
|
192 |
long request;
|
|
193 |
|
|
194 |
if (CWGetPluginRequest(context, &request) != cwNoErr)
|
|
195 |
return cwErrRequestFailed;
|
|
196 |
result = cwErrInvalidParameter;
|
|
197 |
|
|
198 |
/* dispatch on compiler request */
|
|
199 |
switch (request)
|
|
200 |
{
|
|
201 |
case reqInitCompiler:
|
|
202 |
case reqTermCompiler:
|
|
203 |
result = cwNoErr;
|
|
204 |
break;
|
|
205 |
|
|
206 |
case reqCompile:
|
|
207 |
{
|
|
208 |
line_count = 0;
|
|
209 |
const char *files = NULL;
|
|
210 |
long filelen;
|
|
211 |
CWGetMainFileText(context, &files, &filelen);
|
|
212 |
const char *beg = files;
|
|
213 |
for(int x = 0; x < filelen; x++) {
|
|
214 |
if(*(files++) == '\r') {
|
|
215 |
char file[1024];
|
|
216 |
memcpy(file, beg, files - beg);
|
|
217 |
file[(files-beg)-1] = '\0';
|
|
218 |
mocify(context, file);
|
|
219 |
beg = files;
|
|
220 |
}
|
|
221 |
}
|
|
222 |
if(beg != files) {
|
|
223 |
char file[1024];
|
|
224 |
memcpy(file, beg, files - beg);
|
|
225 |
file[(files-beg)] = '\0';
|
|
226 |
mocify(context, file);
|
|
227 |
}
|
|
228 |
|
|
229 |
result = cwNoErr;
|
|
230 |
break;
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
/* return result code */
|
|
235 |
return result;
|
|
236 |
}
|
|
237 |
|
|
238 |
#endif
|
|
239 |
|
|
240 |
QT_END_NAMESPACE
|