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