source: trunk/src/tools/moc/mwerks_mac.cpp@ 296

Last change on this file since 296 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
56QT_BEGIN_NAMESPACE
57
58//qglobal.cpp
59const unsigned char * p_str(const char * c);
60QCString pstring2qstring(const unsigned char *c);
61
62#if CW_USE_PRAGMA_EXPORT
63#pragma export on
64#endif
65
66CWPLUGIN_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
83CWPLUGIN_ENTRY(CWPlugin_GetDropInName)(const char** dropinName)
84{
85 static const char sDropInName[] = "McMoc";
86 *dropinName = sDropInName;
87 return cwNoErr;
88}
89
90CWPLUGIN_ENTRY(CWPlugin_GetDisplayName)(const char** displayName)
91{
92 static const char sDisplayName[] = "McMoc";
93 *displayName = sDisplayName;
94 return cwNoErr;
95}
96
97CWPLUGIN_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
106CWPLUGIN_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
117typedef short CWFileRef;
118
119static int line_count = 0;
120moc_status do_moc(CWPluginContext, const QCString &, const QCString &, CWFileSpec *, bool);
121
122static 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
189pascal 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
240QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.