summaryrefslogtreecommitdiff
path: root/command_line/PluginLib
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-01-15 12:14:05 +0000
committerAsh Wolf <ninji@wuffs.org>2023-01-15 12:14:05 +0000
commit35d488e972a9dd75ce3867c000405f128b79c615 (patch)
treee3319a23d9aa0d4725f88a99fdd5131488a334a9 /command_line/PluginLib
parent8078e7f897aaae9b492b22475060052d68b9c547 (diff)
downloadMWCC-35d488e972a9dd75ce3867c000405f128b79c615.tar.gz
MWCC-35d488e972a9dd75ce3867c000405f128b79c615.zip
reorganise things a bit to align further with the actual names/structure
Diffstat (limited to 'command_line/PluginLib')
-rw-r--r--command_line/PluginLib/Src/Internal/COSToolsCLT.c292
-rw-r--r--command_line/PluginLib/Src/Internal/CWSecretPluginCallbacks.cpp39
-rw-r--r--command_line/PluginLib/Src/Library/CWParserPluginsPrivate.cpp207
-rw-r--r--command_line/PluginLib/Src/Library/CWPluginsPrivate.cpp513
-rw-r--r--command_line/PluginLib/Src/Library/DropInCompilerLinkerPrivate.cpp501
5 files changed, 1552 insertions, 0 deletions
diff --git a/command_line/PluginLib/Src/Internal/COSToolsCLT.c b/command_line/PluginLib/Src/Internal/COSToolsCLT.c
new file mode 100644
index 0000000..11f1668
--- /dev/null
+++ b/command_line/PluginLib/Src/Internal/COSToolsCLT.c
@@ -0,0 +1,292 @@
+#include "cw_common.h"
+#include "cos.h"
+
+extern Boolean systemHandles;
+
+static StringPtr COS_pstrcpy(StringPtr dst, ConstStringPtr src) {
+ short cnt;
+ for (cnt = src[0]; cnt >= 0; cnt--) {
+ *(dst++) = *(src++);
+ }
+ return dst;
+}
+
+static StringPtr COS_pstrcat(StringPtr dst, ConstStringPtr src) {
+ // not matching
+ short as;
+ short bs;
+
+ bs = *(src++);
+ as = dst[0];
+ if ((bs + as) > 255)
+ bs = 255 - as;
+
+ dst[0] += bs;
+ dst = &dst[as];
+ dst++;
+
+ while (bs-- > 0) {
+ *(dst++) = *(src++);
+ }
+ return dst;
+}
+
+static void COS_pstrcharcat(StringPtr to, char ch) {
+ if (to[0] < 255) {
+ to[0]++;
+ to[to[0]] = ch;
+ }
+}
+
+static short COS_pstrcmp(ConstStringPtr a, ConstStringPtr b) {
+ short as, bs;
+ if ((bs = *(b++)) != (as = *(a++)))
+ return 1;
+ while (as-- > 0) {
+ if (*(a++) != *(b++))
+ return 1;
+ }
+ return 0;
+}
+
+Handle COS_NewHandle(SInt32 byteCount) {
+ return NewHandle(byteCount);
+}
+
+Handle COS_NewOSHandle(SInt32 logicalSize) {
+ OSErr err;
+ Handle h;
+
+ if (systemHandles) {
+ h = TempNewHandle(logicalSize, &err);
+ if (!err)
+ return h;
+ }
+
+ return NULL;
+}
+
+void COS_FreeHandle(Handle handle) {
+ DisposeHandle(handle);
+}
+
+Boolean COS_ResizeHandle(Handle handle, SInt32 newSize) {
+ SetHandleSize(handle, newSize);
+ return LMGetMemErr() == noErr;
+}
+
+SInt32 COS_GetHandleSize(Handle handle) {
+ return GetHandleSize(handle);
+}
+
+void COS_LockHandle(Handle handle) {
+ HLock(handle);
+}
+
+void COS_LockHandleHi(Handle handle) {
+ HLockHi(handle);
+}
+
+void COS_UnlockHandle(Handle handle) {
+ HUnlock(handle);
+}
+
+int COS_GetHandleState(Handle handle) {
+ return HGetState(handle);
+}
+
+void COS_SetHandleState(Handle handle, int state) {
+ HSetState(handle, state);
+}
+
+Boolean COS_IsLockedState(int state) {
+ return (state & 0x80) >> 7;
+}
+
+char *COS_NewPtr(SInt32 byteCount) {
+ return NewPtr(byteCount);
+}
+
+char *COS_NewPtrClear(SInt32 byteCount) {
+ return NewPtrClear(byteCount);
+}
+
+void COS_FreePtr(char *ptr) {
+ DisposePtr(ptr);
+}
+
+void COS_AppendPtrToHandle(char *ptr1, Handle hand2, SInt32 size) {
+ PtrAndHand(ptr1, hand2, size);
+}
+
+OSErr COS_GetMemErr(void) {
+ return LMGetMemErr();
+}
+
+SInt32 COS_GetTicks(void) {
+ return LMGetTicks();
+}
+
+SInt32 COS_GetTime(void) {
+ return LMGetTime();
+}
+
+void COS_GetString(char *buffer, SInt16 strListID, SInt16 index) {
+ GetIndString((StringPtr) buffer, strListID, index);
+ p2cstr((StringPtr) buffer);
+}
+
+void COS_GetPString(StringPtr buffer, SInt16 strListID, SInt16 index) {
+ GetIndString((StringPtr) buffer, strListID, index);
+}
+
+Boolean COS_IsMultiByte(const void *str1, const void *str2) {
+ return OS_IsMultiByte(str1, str2);
+}
+
+OSErr COS_FileNew(const FSSpec *spec, SInt16 *refNum, OSType creator, OSType fileType) {
+ OSErr err;
+
+ HDelete(spec->vRefNum, spec->parID, spec->name);
+ err = HCreate(spec->vRefNum, spec->parID, spec->name, creator, fileType);
+ if (!err)
+ err = HOpenDF(spec->vRefNum, spec->parID, spec->name, fsRdWrPerm, refNum);
+ return err;
+}
+
+OSErr COS_FileOpen(const FSSpec *spec, SInt16 *refNum) {
+ return HOpenDF(spec->vRefNum, spec->parID, spec->name, fsRdPerm, refNum);
+}
+
+OSErr COS_FileGetType(const FSSpec *spec, OSType *fileType) {
+ OSErr err;
+ FInfo fi;
+
+ err = HGetFInfo(spec->vRefNum, spec->parID, spec->name, &fi);
+ *fileType = fi.fdType;
+ return err;
+}
+
+OSErr COS_FileGetSize(SInt16 refNum, SInt32 *logEOF) {
+ return GetEOF(refNum, logEOF);
+}
+
+OSErr COS_FileRead(SInt16 refNum, void *buffPtr, SInt32 count) {
+ return FSRead(refNum, &count, buffPtr);
+}
+
+OSErr COS_FileWrite(SInt16 refNum, const void *buffPtr, SInt32 count) {
+ return FSWrite(refNum, &count, buffPtr);
+}
+
+OSErr COS_FileGetPos(SInt16 refNum, SInt32 *filePos) {
+ return GetFPos(refNum, filePos);
+}
+
+OSErr COS_FileSetPos(SInt16 refNum, SInt32 filePos) {
+ return SetFPos(refNum, fsFromStart, filePos);
+}
+
+OSErr COS_FileClose(SInt16 refNum) {
+ return FSClose(refNum);
+}
+
+void COS_FileSetFSSpec(FSSpec *spec, ConstStringPtr path) {
+ char buf[256];
+ OSSpec ospec;
+
+ memcpy(buf, path + 1, path[0]);
+ buf[path[0]] = 0;
+
+ if (OS_MakeSpec(buf, &ospec, NULL) || OS_OSSpec_To_FSSpec(&ospec, spec)) {
+ spec->vRefNum = 0;
+ spec->parID = 0;
+ c2pstrcpy(spec->name, buf);
+ }
+}
+
+OSErr COS_FileMakeFSSpec(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, FSSpec *spec) {
+ int oerr;
+ OSPathSpec opspec;
+ char buf[256];
+ OSSpec ospec;
+
+ oerr = OS_VolDir_To_OSPathSpec(vRefNum, dirID, &opspec);
+ if (oerr)
+ return OS_MacError(oerr);
+
+ p2cstrcpy(buf, fileName);
+ oerr = OS_MakeSpecWithPath(&opspec, buf, 0, &ospec);
+ if (oerr) {
+ pstrncpy(spec->name, fileName, 256);
+ return OS_MacError(oerr);
+ } else {
+ return OS_MacError(OS_OSSpec_To_FSSpec(&ospec, spec));
+ }
+}
+
+OSErr COS_FileMakeFSSpecWithPath(const FSSpec *inputSpec, ConstStringPtr fileName, FSSpec *spec) {
+ spec->vRefNum = inputSpec->vRefNum;
+ spec->parID = inputSpec->parID;
+ COS_pstrcpy(spec->name, fileName);
+ return noErr;
+}
+
+OSErr COS_FileGetFileInfo(const FSSpec *spec, OSType *creator, OSType *fileType) {
+ OSErr err;
+ FInfo fi;
+ err = HGetFInfo(spec->vRefNum, spec->parID, spec->name, &fi);
+ if (fileType)
+ *fileType = fi.fdType;
+ if (creator)
+ *creator = fi.fdCreator;
+ return err;
+}
+
+void COS_FileGetFSSpecInfo(const FSSpec *spec, SInt16 *vRefNum, SInt32 *dirID, StringPtr fileName) {
+ if (vRefNum)
+ *vRefNum = spec->vRefNum;
+ if (dirID)
+ *dirID = spec->parID;
+ if (fileName)
+ COS_pstrcpy(fileName, spec->name);
+}
+
+static void COS_MakePath(SInt16 vRefNum, SInt32 dirID, StringPtr path) {
+ FSSpec fss;
+ OSSpec oss;
+ fss.vRefNum = vRefNum;
+ fss.parID = dirID;
+ COS_pstrcpy(fss.name, path);
+ if (!OS_FSSpec_To_OSSpec(&fss, &oss)) {
+ OS_SpecToString(&oss, (char *) path, 256);
+ c2pstr((char *) path);
+ }
+}
+
+void COS_FileGetPathName(char *buffer, const FSSpec *spec, SInt32 *mdDat) {
+ HParamBlockRec rec;
+
+ if (mdDat) {
+ rec.fileParam.ioNamePtr = (StringPtr) spec->name;
+ rec.fileParam.ioVRefNum = spec->vRefNum;
+ rec.fileParam.ioDirID = spec->parID;
+ rec.fileParam.ioFDirIndex = 0;
+ if (!PBHGetFInfoSync(&rec))
+ *mdDat = rec.fileParam.ioFlMdDat;
+ else
+ *mdDat = 0;
+ }
+
+ COS_pstrcpy((StringPtr) buffer, spec->name);
+ COS_MakePath(spec->vRefNum, spec->parID, (StringPtr) buffer);
+ p2cstr((StringPtr) buffer);
+}
+
+int COS_EqualFileSpec(const FSSpec *a, const FSSpec *b) {
+ if (a->vRefNum != b->vRefNum)
+ return 0;
+ if (a->parID != b->parID)
+ return 0;
+ return COS_pstrcmp(a->name, b->name) == 0;
+}
diff --git a/command_line/PluginLib/Src/Internal/CWSecretPluginCallbacks.cpp b/command_line/PluginLib/Src/Internal/CWSecretPluginCallbacks.cpp
new file mode 100644
index 0000000..b33ca81
--- /dev/null
+++ b/command_line/PluginLib/Src/Internal/CWSecretPluginCallbacks.cpp
@@ -0,0 +1,39 @@
+#include "plugin_internal.h"
+
+static Boolean ValidateContext(CWPluginContext context) {
+ return context && (context->shellSignature == CWFOURCHAR('C','W','I','E'));
+}
+
+typedef CWResult (*cbSecretAttachHandleType)(CWPluginContext, Handle, CWMemHandle *);
+typedef CWResult (*cbSecretDetachHandleType)(CWPluginContext, CWMemHandle, Handle *);
+typedef CWResult (*cbSecretPeekHandleType)(CWPluginContext, CWMemHandle, Handle *);
+typedef CWResult (*cbSecretGetNamedPreferencesType)(CWPluginContext, const char *, Handle *);
+
+CW_CALLBACK CWSecretAttachHandle(CWPluginContext context, Handle handle, CWMemHandle *memHandle) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return ((cbSecretAttachHandleType) context->callbacks->cbInternal[0])(context, handle, memHandle);
+}
+
+CW_CALLBACK CWSecretDetachHandle(CWPluginContext context, CWMemHandle memHandle, Handle *handle) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return ((cbSecretDetachHandleType) context->callbacks->cbInternal[1])(context, memHandle, handle);
+}
+
+CW_CALLBACK CWSecretPeekHandle(CWPluginContext context, CWMemHandle memHandle, Handle *handle) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return ((cbSecretPeekHandleType) context->callbacks->cbInternal[2])(context, memHandle, handle);
+}
+
+CW_CALLBACK CWSecretGetNamedPreferences(CWPluginContext context, const char *prefsname, Handle *prefsdata) {
+ if (!prefsdata)
+ return cwErrInvalidParameter;
+
+ CWMemHandle memHandle;
+ CWResult res = CWGetNamedPreferences(context, prefsname, &memHandle);
+ if (!res)
+ res = CWSecretDetachHandle(context, memHandle, prefsdata);
+ return res;
+}
diff --git a/command_line/PluginLib/Src/Library/CWParserPluginsPrivate.cpp b/command_line/PluginLib/Src/Library/CWParserPluginsPrivate.cpp
new file mode 100644
index 0000000..6973b4d
--- /dev/null
+++ b/command_line/PluginLib/Src/Library/CWParserPluginsPrivate.cpp
@@ -0,0 +1,207 @@
+#include "plugin_internal.h"
+
+static CWParserContext *GetContext(CWPluginContext context) {
+ if (context && (context->pluginType == CWDROPINPARSERTYPE))
+ return static_cast<CWParserContext *>(context);
+ else
+ return 0;
+}
+
+CW_CALLBACK CWParserGetBuildDate(CWPluginContext context, const char **bdate, const char **btime) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!bdate)
+ return cwErrInvalidParameter;
+ if (!btime)
+ return cwErrInvalidParameter;
+ *bdate = pc->build_date;
+ *btime = pc->build_time;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserGetCommandLine(CWPluginContext context, CWCommandLineArgs **args) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!args)
+ return cwErrInvalidParameter;
+ *args = pc->args;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserGetTargetInfo(CWPluginContext context, CWDataType *cpu, CWDataType *os) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!cpu)
+ return cwErrInvalidParameter;
+ if (!os)
+ return cwErrInvalidParameter;
+ *cpu = pc->cpu;
+ *os = pc->os;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserGetToolInfo(CWPluginContext context, const ToolVersionInfo **toolVersionInfo) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!toolVersionInfo)
+ return cwErrInvalidParameter;
+ *toolVersionInfo = pc->build_tool;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserGetPlugins(CWPluginContext context, int *numPlugins, const CLPluginInfo **pluginInfo) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!numPlugins)
+ return cwErrInvalidParameter;
+ if (!pluginInfo)
+ return cwErrInvalidParameter;
+ *numPlugins = pc->numPlugins;
+ *pluginInfo = pc->plugins;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserGetPanels(CWPluginContext context, int *numPanels, const char ***panelNames) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!numPanels)
+ return cwErrInvalidParameter;
+ if (!panelNames)
+ return cwErrInvalidParameter;
+ *numPanels = pc->numPanels;
+ *panelNames = pc->panelNames;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserStoreCommandLineForPanel(CWPluginContext context, int index, const CWCommandLineArgs *args) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (index < 0 || index >= pc->numPanels)
+ return cwErrInvalidParameter;
+ if (!args)
+ return cwErrInvalidParameter;
+ pc->panel_args[index] = *args;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserStoreCommandLineForPlugin(CWPluginContext context, int index, const CWCommandLineArgs *args) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (index < 0 || index >= pc->numPlugins)
+ return cwErrInvalidParameter;
+ if (!args)
+ return cwErrInvalidParameter;
+ pc->plugin_args[index] = *args;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWParserSetNamedPreferences(CWPluginContext context, const char *panelName, Handle paneldata) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!panelName)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserSetNamedPreferences(pc, panelName, paneldata);
+}
+
+CW_CALLBACK CWParserAddAccessPath(CWPluginContext context, const CWNewAccessPathInfo *api) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!api)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserAddAccessPath(pc, api);
+}
+
+CW_CALLBACK CWParserSwapAccessPaths(CWPluginContext context) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ return pc->callbacks->cbParserSwapAccessPaths(pc);
+}
+
+CW_CALLBACK CWParserSetOutputFileDirectory(CWPluginContext context, const CWFileSpec *idefss) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!idefss)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserSetOutputFileDirectory(pc, idefss);
+}
+
+CW_CALLBACK CWParserSetFileOutputName(CWPluginContext context, SInt32 position, short which, const char *outfilename) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!outfilename)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserSetFileOutputName(pc, position, which, outfilename);
+}
+
+CW_CALLBACK CWParserAddOverlay1Group(CWPluginContext context, const char *name, const CWAddr64 *addr, SInt32 *newGroupNumber) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!name)
+ return cwErrInvalidParameter;
+ if (!addr)
+ return cwErrInvalidParameter;
+ if (!newGroupNumber)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserAddOverlay1Group(pc, name, addr, newGroupNumber);
+}
+
+CW_CALLBACK CWParserAddOverlay1(CWPluginContext context, const char *name, SInt32 groupNumber, SInt32 *newOverlayNumber) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!name)
+ return cwErrInvalidParameter;
+ if (!newOverlayNumber)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserAddOverlay1(pc, name, groupNumber, newOverlayNumber);
+}
+
+CW_CALLBACK CWParserAddSegment(CWPluginContext context, const char *name, short attrs, SInt32 *newSegmentNumber) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!name)
+ return cwErrInvalidParameter;
+ if (!newSegmentNumber)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserAddSegment(pc, name, attrs, newSegmentNumber);
+}
+
+CW_CALLBACK CWParserSetSegment(CWPluginContext context, SInt32 segmentNumber, const char *name, short attrs) {
+ CWParserContext *pc;
+ if (!(pc = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (!name)
+ return cwErrInvalidParameter;
+ return pc->callbacks->cbParserSetSegment(pc, segmentNumber, name, attrs);
+}
+
+CW_CALLBACK CWParserCreateVirtualFile(CWPluginContext context, const char *name, CWMemHandle text) {
+ CWNewTextDocumentInfo info;
+ info.documentname = name;
+ info.text = text;
+ info.markDirty = 1;
+ return CWCreateNewTextDocument(context, &info);
+}
+
+CW_CALLBACK CWParserDisplayTextHandle(CWPluginContext context, const char *name, CWMemHandle text) {
+ CWNewTextDocumentInfo info;
+ info.documentname = name;
+ info.text = text;
+ info.markDirty = 0;
+ return CWCreateNewTextDocument(context, &info);
+}
diff --git a/command_line/PluginLib/Src/Library/CWPluginsPrivate.cpp b/command_line/PluginLib/Src/Library/CWPluginsPrivate.cpp
new file mode 100644
index 0000000..2e0df81
--- /dev/null
+++ b/command_line/PluginLib/Src/Library/CWPluginsPrivate.cpp
@@ -0,0 +1,513 @@
+#include "plugin_internal.h"
+
+// Forward declarations
+CWResult OSErrtoCWResult(OSErr err);
+
+static Boolean ValidateContext(CWPluginContext context) {
+ return context
+ && (context->shellSignature == CWFOURCHAR('C','W','I','E'))
+ && (context->request != reqInitialize)
+ && (context->request != reqTerminate)
+ && (context->request != reqIdle);
+}
+
+static Boolean ValidateInitTermContext(CWPluginContext context) {
+ return context
+ && (context->shellSignature == CWFOURCHAR('C','W','I','E'))
+ && ((context->request == reqInitialize)
+ || (context->request == reqTerminate)
+ || (context->request == reqIdle));
+}
+
+static Boolean IsVCSContext(CWPluginContext context) {
+ return context && (context->pluginType == CWDROPINVCSTYPE);
+}
+
+CW_CALLBACK CWGetPluginRequest(CWPluginContext context, SInt32 *request) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (request == NULL)
+ return cwErrInvalidParameter;
+
+ *request = context->request;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetAPIVersion(CWPluginContext context, SInt32 *version) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (version == NULL)
+ return cwErrInvalidParameter;
+
+ *version = context->apiVersion;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetIDEInfo(CWPluginContext context, CWIDEInfo *info) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (info == NULL)
+ return cwErrInvalidParameter;
+
+ *info = *context->shellInfo;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetCallbackOSError(CWPluginContext context, CWOSResult *error) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (error == NULL)
+ return cwErrInvalidParameter;
+
+ *error = context->callbackOSError;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWSetPluginOSError(CWPluginContext context, CWOSResult error) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+
+ context->pluginOSError = error;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetProjectFile(CWPluginContext context, CWFileSpec *projectSpec) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (projectSpec == NULL)
+ return cwErrInvalidParameter;
+
+ *projectSpec = context->projectFile;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetTargetDataDirectory(CWPluginContext context, CWFileSpec *targetDataDirectorySpec) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (targetDataDirectorySpec == NULL)
+ return cwErrInvalidParameter;
+ if (context->targetDataDirectorySpec == NULL)
+ return cwErrInvalidCallback;
+
+ *targetDataDirectorySpec = *context->targetDataDirectorySpec;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetTargetName(CWPluginContext context, char *name, short maxLength) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+
+ if (context->apiVersion >= 8)
+ return context->callbacks->cbGetTargetName(context, name, maxLength);
+ else
+ return cwErrRequestFailed;
+}
+
+CW_CALLBACK CWGetProjectFileCount(CWPluginContext context, SInt32 *count) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (count == NULL)
+ return cwErrInvalidParameter;
+
+ *count = context->numFiles;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetOutputFileDirectory(CWPluginContext context, CWFileSpec *outputFileDirectory) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (outputFileDirectory == NULL)
+ return cwErrInvalidParameter;
+
+ *outputFileDirectory = context->outputFileDirectory;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetOverlay1GroupsCount(CWPluginContext context, SInt32 *count) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (count == NULL)
+ return cwErrInvalidParameter;
+
+ *count = context->numOverlayGroups;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetFileInfo(CWPluginContext context, SInt32 whichfile, Boolean checkFileLocation, CWProjectFileInfo *fileinfo) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (fileinfo == NULL)
+ return cwErrInvalidParameter;
+
+ return context->callbacks->cbGetFileInfo(context, whichfile, checkFileLocation, fileinfo);
+}
+
+CW_CALLBACK CWFindAndLoadFile(CWPluginContext context, const char *filename, CWFileInfo *fileinfo) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (filename == NULL)
+ return cwErrInvalidParameter;
+ if (fileinfo == NULL)
+ return cwErrInvalidParameter;
+
+ return context->callbacks->cbFindAndLoadFile(context, filename, fileinfo);
+}
+
+static CWResult EnsureCachedAccessPaths(CWPluginContext context) {
+ if (!context->accessPathList) {
+ CWResult res = context->callbacks->cbCacheAccessPathList(context);
+ if (res)
+ return res;
+ if (!context->accessPathList)
+ return cwErrRequestFailed;
+ }
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetAccessPathListInfo(CWPluginContext context, CWAccessPathListInfo *pathListInfo) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (pathListInfo == NULL)
+ return cwErrInvalidParameter;
+ if (context->apiVersion < 10)
+ return cwErrInvalidCallback;
+ CWResult res = EnsureCachedAccessPaths(context);
+ if (res)
+ return res;
+ pathListInfo->systemPathCount = context->accessPathList->systemPathCount;
+ pathListInfo->userPathCount = context->accessPathList->userPathCount;
+ pathListInfo->alwaysSearchUserPaths = context->accessPathList->alwaysSearchUserPaths;
+ pathListInfo->convertPaths = context->accessPathList->convertPaths;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetAccessPathInfo(CWPluginContext context, CWAccessPathType pathType, SInt32 whichPath, CWAccessPathInfo *pathInfo) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (pathInfo == NULL)
+ return cwErrInvalidParameter;
+ if (context->apiVersion < 10)
+ return cwErrInvalidCallback;
+ CWResult res = EnsureCachedAccessPaths(context);
+ if (res)
+ return res;
+
+ IDEAccessPath *paths;
+ SInt32 count;
+ switch (pathType) {
+ case cwSystemPath:
+ paths = context->accessPathList->systemPaths;
+ count = context->accessPathList->systemPathCount;
+ break;
+ case cwUserPath:
+ paths = context->accessPathList->userPaths;
+ count = context->accessPathList->userPathCount;
+ break;
+ default:
+ return cwErrInvalidParameter;
+ }
+
+ if (whichPath < 0 || whichPath >= count)
+ return cwErrInvalidParameter;
+
+ IDEAccessPath *path = &paths[whichPath];
+ pathInfo->pathSpec = path->pathSpec;
+ pathInfo->recursive = path->recursive;
+ pathInfo->subdirectoryCount = path->subdirectoryCount;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetAccessPathSubdirectory(CWPluginContext context, CWAccessPathType pathType, SInt32 whichPath,
+ SInt32 whichSubdirectory, CWFileSpec *subdirectory) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (subdirectory == NULL)
+ return cwErrInvalidParameter;
+ if (context->apiVersion < 10)
+ return cwErrInvalidCallback;
+ CWResult res = EnsureCachedAccessPaths(context);
+ if (res)
+ return res;
+
+ IDEAccessPath *paths;
+ SInt32 count;
+ switch (pathType) {
+ case cwSystemPath:
+ paths = context->accessPathList->systemPaths;
+ count = context->accessPathList->systemPathCount;
+ break;
+ case cwUserPath:
+ paths = context->accessPathList->userPaths;
+ count = context->accessPathList->userPathCount;
+ break;
+ default:
+ return cwErrInvalidParameter;
+ }
+
+ if (whichPath < 0 || whichPath >= count)
+ return cwErrInvalidParameter;
+
+ IDEAccessPath *path = &paths[whichPath];
+ if (whichSubdirectory < 0 || whichSubdirectory >= path->subdirectoryCount)
+ return cwErrInvalidParameter;
+
+ *subdirectory = path->subdirectories[whichSubdirectory];
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetFileText(CWPluginContext context, const CWFileSpec *filespec, const char **text, SInt32 *textLength,
+ short *filedatatype) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!filespec)
+ return cwErrInvalidParameter;
+ if (!text)
+ return cwErrInvalidParameter;
+ if (!textLength)
+ return cwErrInvalidParameter;
+ if (!filedatatype)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetFileText(context, filespec, text, textLength, filedatatype);
+}
+
+CW_CALLBACK CWReleaseFileText(CWPluginContext context, const char *text) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+
+ if (text)
+ return context->callbacks->cbReleaseFileText(context, text);
+ else
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetSegmentInfo(CWPluginContext context, SInt32 whichsegment, CWProjectSegmentInfo *segmentinfo) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!segmentinfo)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetSegmentInfo(context, whichsegment, segmentinfo);
+}
+
+CW_CALLBACK CWGetOverlay1GroupInfo(CWPluginContext context, SInt32 whichgroup, CWOverlay1GroupInfo *groupinfo) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!groupinfo)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetOverlay1GroupInfo(context, whichgroup, groupinfo);
+}
+
+CW_CALLBACK
+CWGetOverlay1Info(CWPluginContext context, SInt32 whichgroup, SInt32 whichoverlay, CWOverlay1Info *overlayinfo) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!overlayinfo)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetOverlay1Info(context, whichgroup, whichoverlay, overlayinfo);
+}
+
+CW_CALLBACK CWGetOverlay1FileInfo(CWPluginContext context, SInt32 whichgroup, SInt32 whichoverlay, SInt32 whichoverlayfile,
+ CWOverlay1FileInfo *fileinfo) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!fileinfo)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetOverlay1FileInfo(context, whichgroup, whichoverlay, whichoverlayfile, fileinfo);
+}
+
+CW_CALLBACK CWReportMessage(CWPluginContext context, const CWMessageRef *msgRef, const char *line1, const char *line2,
+ short errorlevel, SInt32 errorNumber) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbReportMessage(context, msgRef, line1, line2, errorlevel, errorNumber);
+}
+
+CW_CALLBACK CWAlert(CWPluginContext context, const char *msg1, const char *msg2, const char *msg3, const char *msg4) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbAlert(context, msg1, msg2, msg3, msg4);
+}
+
+CW_CALLBACK CWShowStatus(CWPluginContext context, const char *line1, const char *line2) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbShowStatus(context, line1, line2);
+}
+
+CW_CALLBACK CWUserBreak(CWPluginContext context) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbUserBreak(context);
+}
+
+CW_CALLBACK CWGetNamedPreferences(CWPluginContext context, const char *prefsname, CWMemHandle *prefsdata) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!prefsname)
+ return cwErrInvalidParameter;
+ if (!prefsdata)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetNamedPreferences(context, prefsname, prefsdata);
+}
+
+CW_CALLBACK CWStorePluginData(CWPluginContext context, SInt32 whichfile, CWDataType type, CWMemHandle prefsdata) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbStorePluginData(context, whichfile, type, prefsdata);
+}
+
+CW_CALLBACK CWGetPluginData(CWPluginContext context, SInt32 whichfile, CWDataType type, CWMemHandle *prefsdata) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetPluginData(context, whichfile, type, prefsdata);
+}
+
+CW_CALLBACK CWSetModDate(CWPluginContext context, const CWFileSpec *filespec, CWFileTime *moddate, Boolean isGenerated) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!filespec)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbSetModDate(context, filespec, moddate, isGenerated);
+}
+
+CW_CALLBACK CWAddProjectEntry(CWPluginContext context, const CWFileSpec *fileSpec, Boolean isGenerated,
+ const CWNewProjectEntryInfo *projectEntryInfo, SInt32 *whichfile) {
+ if (IsVCSContext(context) || !ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!fileSpec)
+ return cwErrInvalidParameter;
+ if (context->apiVersion < 8)
+ return cwErrRequestFailed;
+ return context->callbacks->cbAddProjectEntry(context, fileSpec, isGenerated, projectEntryInfo, whichfile);
+}
+
+CW_CALLBACK CWCreateNewTextDocument(CWPluginContext context, const CWNewTextDocumentInfo *docinfo) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (!docinfo)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbCreateNewTextDocument(context, docinfo);
+}
+
+CW_CALLBACK CWAllocateMemory(CWPluginContext context, SInt32 size, Boolean isPermanent, void **ptr) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (!ptr)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbAllocateMemory(context, size, isPermanent, ptr);
+}
+
+CW_CALLBACK CWFreeMemory(CWPluginContext context, void *ptr, Boolean isPermanent) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (!ptr)
+ return cwNoErr;
+ return context->callbacks->cbFreeMemory(context, ptr, isPermanent);
+}
+
+CW_CALLBACK CWAllocMemHandle(CWPluginContext context, SInt32 size, Boolean useTempMemory, CWMemHandle *handle) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (!handle)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbAllocMemHandle(context, size, useTempMemory, handle);
+}
+
+CW_CALLBACK CWFreeMemHandle(CWPluginContext context, CWMemHandle handle) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbFreeMemHandle(context, handle);
+}
+
+CW_CALLBACK CWGetMemHandleSize(CWPluginContext context, CWMemHandle handle, SInt32 *size) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (!size)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbGetMemHandleSize(context, handle, size);
+}
+
+CW_CALLBACK CWResizeMemHandle(CWPluginContext context, CWMemHandle handle, SInt32 newSize) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbResizeMemHandle(context, handle, newSize);
+}
+
+CW_CALLBACK CWLockMemHandle(CWPluginContext context, CWMemHandle handle, Boolean moveHi, void **ptr) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ if (!ptr)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbLockMemHandle(context, handle, moveHi, ptr);
+}
+
+CW_CALLBACK CWUnlockMemHandle(CWPluginContext context, CWMemHandle handle) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbUnlockMemHandle(context, handle);
+}
+
+CW_CALLBACK CWDonePluginRequest(CWPluginContext, CWResult resultCode) {
+ return resultCode;
+}
+
+CW_CALLBACK CWPreDialog(CWPluginContext context) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbPreDialog(context);
+}
+
+CW_CALLBACK CWPostDialog(CWPluginContext context) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbPostDialog(context);
+}
+
+CW_CALLBACK CWPreFileAction(CWPluginContext context, const CWFileSpec *theFile) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbPreFileAction(context, theFile);
+}
+
+CW_CALLBACK CWPostFileAction(CWPluginContext context, const CWFileSpec *theFile) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbPostFileAction(context, theFile);
+}
+
+CW_CALLBACK CWCheckoutLicense(CWPluginContext context, const char *featureName, const char *licenseVersion, SInt32 flags, void *reserved, SInt32 *cookie) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbCheckoutLicense(context, featureName, licenseVersion, flags, reserved, cookie);
+}
+
+CW_CALLBACK CWCheckinLicense(CWPluginContext context, SInt32 cookie) {
+ if (!ValidateContext(context) && !ValidateInitTermContext(context))
+ return cwErrInvalidParameter;
+ return context->callbacks->cbCheckinLicense(context, cookie);
+}
+
+CW_CALLBACK CWResolveRelativePath(CWPluginContext context, const CWRelativePath *relativePath, CWFileSpec *fileSpec, Boolean create) {
+ if (!ValidateContext(context))
+ return cwErrInvalidParameter;
+ if (relativePath == NULL)
+ return cwErrInvalidParameter;
+ if (fileSpec == NULL)
+ return cwErrInvalidParameter;
+ return context->callbacks->cbResolveRelativePath(context, relativePath, fileSpec, create);
+}
+
+CW_CALLBACK CWMacOSErrToCWResult(CWPluginContext context, OSErr err) {
+ return OSErrtoCWResult(err);
+}
+
+CWResult OSErrtoCWResult(OSErr err) {
+ switch (err) {
+ case noErr: return cwNoErr;
+ case userCanceledErr: return cwErrUserCanceled;
+ case paramErr: return cwErrInvalidParameter;
+ case memFullErr: return cwErrOutOfMemory;
+ case fnfErr: return cwErrFileNotFound;
+ default: return cwErrRequestFailed;
+ }
+}
+
diff --git a/command_line/PluginLib/Src/Library/DropInCompilerLinkerPrivate.cpp b/command_line/PluginLib/Src/Library/DropInCompilerLinkerPrivate.cpp
new file mode 100644
index 0000000..2c0a0c7
--- /dev/null
+++ b/command_line/PluginLib/Src/Library/DropInCompilerLinkerPrivate.cpp
@@ -0,0 +1,501 @@
+#include "plugin_internal.h"
+
+static CWCompilerLinkerContext *GetContext(CWPluginContext context) {
+ if (context && (context->pluginType == CWDROPINCOMPILERTYPE || context->pluginType == CWDROPINLINKERTYPE))
+ return static_cast<CWCompilerLinkerContext *>(context);
+ else
+ return 0;
+}
+
+CW_CALLBACK CWIsPrecompiling(CWPluginContext context, Boolean* isPrecompiling) {
+ CWCompilerLinkerContext *cl;
+ if (!isPrecompiling)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *isPrecompiling = cl->precompile;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWIsAutoPrecompiling(CWPluginContext context, Boolean* isAutoPrecompiling) {
+ CWCompilerLinkerContext *cl;
+ if (!isAutoPrecompiling)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *isAutoPrecompiling = cl->autoprecompile;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWIsPreprocessing(CWPluginContext context, Boolean* isPreprocessing) {
+ CWCompilerLinkerContext *cl;
+ if (!isPreprocessing)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *isPreprocessing = cl->preprocess;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWIsGeneratingDebugInfo(CWPluginContext context, Boolean* isGenerating) {
+ CWCompilerLinkerContext *cl;
+ if (!isGenerating)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *isGenerating = cl->debuginfo;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWIsCachingPrecompiledHeaders(CWPluginContext context, Boolean* isCaching) {
+ CWCompilerLinkerContext *cl;
+ if (!isCaching)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *isCaching = cl->cachingPCH;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetBrowseOptions(CWPluginContext context, CWBrowseOptions* browseOptions) {
+ CWCompilerLinkerContext *cl;
+ if (!browseOptions)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *browseOptions = cl->browseoptions;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetBuildSequenceNumber(CWPluginContext context, SInt32* sequenceNumber) {
+ CWCompilerLinkerContext *cl;
+ if (!sequenceNumber)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *sequenceNumber = cl->sequenceID;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetTargetInfo(CWPluginContext context, CWTargetInfo* targetInfo) {
+ CWCompilerLinkerContext *cl;
+ if (!targetInfo)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion >= 10) {
+ *targetInfo = *cl->targetinfo;
+ } else if (cl->apiVersion >= 8) {
+ CWTargetInfo *ti = cl->targetinfo;
+ targetInfo->outputType = ti->outputType;
+ targetInfo->outfile = ti->outfile;
+ targetInfo->symfile = ti->symfile;
+ targetInfo->runfile = ti->runfile;
+ targetInfo->linkType = ti->linkType;
+ targetInfo->canRun = ti->canRun;
+ targetInfo->canDebug = ti->canDebug;
+ targetInfo->targetCPU = ti->targetCPU;
+ targetInfo->targetOS = ti->targetOS;
+#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
+ targetInfo->outfileCreator = ti->outfileCreator;
+ targetInfo->outfileType = ti->outfileType;
+ targetInfo->debuggerCreator = ti->debuggerCreator;
+ targetInfo->runHelperCreator = ti->runHelperCreator;
+#endif
+ } else {
+ memset(targetInfo, 0, sizeof(CWTargetInfo));
+ if (CWFileSpecNotEmpty(&cl->targetinfo_V7.outfile))
+ targetInfo->outputType = linkOutputFile;
+ else
+ targetInfo->outputType = linkOutputNone;
+ targetInfo->outfile = cl->targetinfo_V7.outfile;
+ targetInfo->symfile = cl->targetinfo_V7.symfile;
+ targetInfo->runfile = cl->targetinfo_V7.outfile;
+ targetInfo->linkType = cl->targetinfo_V7.linkType;
+ targetInfo->canRun = cl->targetinfo_V7.canRun;
+ targetInfo->canDebug = cl->targetinfo_V7.canDebug;
+#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
+ targetInfo->debuggerCreator = cl->targetinfo_V7.debuggerCreator;
+ targetInfo->runHelperCreator = cl->targetinfo_V7.runHelperCreator;
+#endif
+ }
+ return cwNoErr;
+}
+
+CW_CALLBACK CWSetTargetInfo(CWPluginContext context, CWTargetInfo* targetInfo) {
+ CWCompilerLinkerContext *cl;
+ if (!targetInfo)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion >= 10) {
+ *cl->targetinfo = *targetInfo;
+ } else if (cl->apiVersion >= 8) {
+ CWTargetInfo *ti = cl->targetinfo;
+ ti->outputType = targetInfo->outputType;
+ ti->outfile = targetInfo->outfile;
+ ti->symfile = targetInfo->symfile;
+ ti->runfile = targetInfo->runfile;
+ ti->linkType = targetInfo->linkType;
+ ti->canRun = targetInfo->canRun;
+ ti->canDebug = targetInfo->canDebug;
+ ti->targetCPU = targetInfo->targetCPU;
+ ti->targetOS = targetInfo->targetOS;
+#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
+ ti->outfileCreator = targetInfo->outfileCreator;
+ ti->outfileType = targetInfo->outfileType;
+ ti->debuggerCreator = targetInfo->debuggerCreator;
+ ti->runHelperCreator = targetInfo->runHelperCreator;
+#endif
+ } else {
+ cl->targetinfo_V7.outfile = targetInfo->outfile;
+ cl->targetinfo_V7.symfile = targetInfo->symfile;
+ cl->targetinfo_V7.linkType = targetInfo->linkType;
+ cl->targetinfo_V7.canRun = targetInfo->canRun;
+ cl->targetinfo_V7.canDebug = targetInfo->canDebug;
+#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
+ cl->targetinfo_V7.useRunHelperApp = targetInfo->runHelperCreator != 0;
+ cl->targetinfo_V7.debuggerCreator = targetInfo->debuggerCreator;
+ cl->targetinfo_V7.runHelperCreator = targetInfo->runHelperCreator;
+#endif
+ }
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetMainFileNumber(CWPluginContext context, SInt32* fileNumber) {
+ CWCompilerLinkerContext *cl;
+ if (!fileNumber)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *fileNumber = cl->whichfile;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetMainFileID(CWPluginContext context, short* fileID) {
+ CWCompilerLinkerContext *cl;
+ if (!fileID)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *fileID = cl->fileID;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetMainFileSpec(CWPluginContext context, CWFileSpec* fileSpec) {
+ CWCompilerLinkerContext *cl;
+ if (!fileSpec)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *fileSpec = cl->sourcefile;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetMainFileText(CWPluginContext context, const char** text, SInt32* textLength) {
+ CWCompilerLinkerContext *cl;
+ if (!text)
+ return cwErrInvalidParameter;
+ if (!textLength)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ *text = cl->sourcetext;
+ *textLength = cl->sourcetextsize;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWLoadObjectData(CWPluginContext context, SInt32 whichfile, CWMemHandle* objectdata) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbLoadObjectData(cl, whichfile, objectdata);
+}
+
+CW_CALLBACK CWStoreObjectData(CWPluginContext context, SInt32 whichfile, CWObjectData* object) {
+ CWCompilerLinkerContext *cl;
+ if (!object)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbStoreObjectData(cl, whichfile, object);
+}
+
+CW_CALLBACK CWFreeObjectData(CWPluginContext context, SInt32 whichfile, CWMemHandle objectdata) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbFreeObjectData(cl, whichfile, objectdata);
+}
+
+CW_CALLBACK CWGetSuggestedObjectFileSpec(CWPluginContext context, SInt32 whichfile, CWFileSpec* fileSpec) {
+ CWCompilerLinkerContext *cl;
+ if (!fileSpec)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (context->apiVersion < 10)
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbGetSuggestedObjectFileSpec(cl, whichfile, fileSpec);
+}
+
+CW_CALLBACK CWGetStoredObjectFileSpec(CWPluginContext context, SInt32 whichfile, CWFileSpec* fileSpec) {
+ CWCompilerLinkerContext *cl;
+ if (!fileSpec)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (context->apiVersion < 10)
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbGetStoredObjectFileSpec(cl, whichfile, fileSpec);
+}
+
+CW_CALLBACK CWDisplayLines(CWPluginContext context, SInt32 nlines) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbDisplayLines(cl, nlines);
+}
+
+CW_CALLBACK CWGetResourceFile(CWPluginContext context, CWFileSpec* filespec) {
+ CWCompilerLinkerContext *cl;
+ if (!filespec)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbGetResourceFile(cl, filespec);
+}
+
+CW_CALLBACK CWPutResourceFile(CWPluginContext context, const char* prompt, const char* name, CWFileSpec* filespec) {
+ CWCompilerLinkerContext *cl;
+ if (!prompt)
+ return cwErrInvalidParameter;
+ if (!name)
+ return cwErrInvalidParameter;
+ if (!filespec)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbPutResourceFile(cl, prompt, name, filespec);
+}
+
+CW_CALLBACK CWCachePrecompiledHeader(CWPluginContext context, const CWFileSpec* filespec, CWMemHandle pchhandle) {
+ CWCompilerLinkerContext *cl;
+ if (!filespec)
+ return cwErrInvalidParameter;
+ if (!pchhandle)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbCachePrecompiledHeader(cl, filespec, pchhandle);
+}
+
+CW_CALLBACK CWGetPrecompiledHeaderSpec(CWPluginContext context, CWFileSpec *pchspec, const char *target) {
+ CWCompilerLinkerContext *cl;
+ if (!pchspec)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbGetPrecompiledHeaderSpec(cl, pchspec, target);
+}
+
+CW_CALLBACK CWBeginSubCompile(CWPluginContext context, SInt32 whichfile, CWPluginContext* subContext) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbBeginSubCompile(cl, whichfile, subContext);
+}
+
+CW_CALLBACK CWEndSubCompile(CWPluginContext subContext) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(subContext)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbEndSubCompile(subContext);
+}
+
+CW_CALLBACK CWLookUpUnit(CWPluginContext context, const char* name, Boolean isdependency, const void** unitdata, SInt32* unitdatalength) {
+ CWCompilerLinkerContext *cl;
+ if (!name)
+ return cwErrInvalidParameter;
+ if (!unitdata)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbLookUpUnit(cl, name, isdependency, unitdata, unitdatalength);
+}
+
+CW_CALLBACK CWSBMfiles(CWPluginContext context, short libref) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbSBMfiles(cl, libref);
+}
+
+CW_CALLBACK CWStoreUnit(CWPluginContext context, const char* unitname, CWMemHandle unitdata, CWDependencyTag dependencytag) {
+ CWCompilerLinkerContext *cl;
+ if (!unitname)
+ return cwErrInvalidParameter;
+ if (!unitdata)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbStoreUnit(cl, unitname, unitdata, dependencytag);
+}
+
+CW_CALLBACK CWReleaseUnit(CWPluginContext context, void* unitdata) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbReleaseUnit(cl, unitdata);
+}
+
+CW_CALLBACK CWUnitNameToFileName(CWPluginContext context, const char* unitname, char* filename) {
+ CWCompilerLinkerContext *cl;
+ if (!unitname)
+ return cwErrInvalidParameter;
+ if (!filename)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbUnitNameToFileName(cl, unitname, filename);
+}
+
+CW_CALLBACK CWGetTargetStorage(CWPluginContext context, void** storage) {
+ CWCompilerLinkerContext *cl;
+ if (!storage)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion >= 8) {
+ *storage = cl->targetStorage;
+ return cwNoErr;
+ } else {
+ return cwErrRequestFailed;
+ }
+}
+
+CW_CALLBACK CWSetTargetStorage(CWPluginContext context, void* storage) {
+ CWCompilerLinkerContext *cl;
+ if (!storage)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion >= 8) {
+ cl->targetStorage = storage;
+ return cwNoErr;
+ } else {
+ return cwErrRequestFailed;
+ }
+}
+
+CW_CALLBACK CWOSErrorMessage(CWPluginContext context, const char *msg, OSErr errorcode) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbOSErrorMessage(cl, msg, errorcode);
+}
+
+CW_CALLBACK CWOSAlert(CWPluginContext context, const char* message, OSErr errorcode) {
+ CWCompilerLinkerContext *cl;
+ if (!message)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbOSAlert(cl, message, errorcode);
+}
+
+CW_CALLBACK CWGetModifiedFiles(CWPluginContext context, SInt32* modifiedFileCount, const SInt32** modifiedFiles) {
+ CWCompilerLinkerContext *cl;
+ if (!modifiedFileCount)
+ return cwErrInvalidParameter;
+ if (!modifiedFiles)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (context->apiVersion < 9)
+ return cwErrInvalidCallback;
+ return cl->callbacks->cbGetModifiedFiles(cl, modifiedFileCount, modifiedFiles);
+}
+
+CW_CALLBACK CWGetCommandLineArgs(CWPluginContext context, const char** commandLineArgs) {
+ CWCompilerLinkerContext *cl;
+ if (!commandLineArgs)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion < 11)
+ return cwErrInvalidCallback;
+ if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl))
+ return cwErrRequestFailed;
+ *commandLineArgs = cl->commandLineArgs;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetWorkingDirectory(CWPluginContext context, CWFileSpec* workingDirectorySpec) {
+ CWCompilerLinkerContext *cl;
+ if (!workingDirectorySpec)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion < 11)
+ return cwErrInvalidCallback;
+ if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl))
+ return cwErrRequestFailed;
+ *workingDirectorySpec = *cl->workingDirectorySpec;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetEnvironmentVariableCount(CWPluginContext context, SInt32* count) {
+ CWCompilerLinkerContext *cl;
+ if (!count)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion < 11)
+ return cwErrInvalidCallback;
+ if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl))
+ return cwErrRequestFailed;
+ *count = cl->numEnvironmentVariables;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetEnvironmentVariable(CWPluginContext context, SInt32 index, const char** name, const char** value) {
+ CWCompilerLinkerContext *cl;
+ if (!name)
+ return cwErrInvalidParameter;
+ if (!value)
+ return cwErrInvalidParameter;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion < 11)
+ return cwErrInvalidCallback;
+ if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl))
+ return cwErrRequestFailed;
+ if (index < 0 || index >= cl->numEnvironmentVariables)
+ return cwErrInvalidParameter;
+ *name = cl->environmentVariables[index].name;
+ *value = cl->environmentVariables[index].value;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetFrameworkCount(CWPluginContext context, SInt32* frameworkCount) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion < 11)
+ return cwErrInvalidCallback;
+ if (!cl->commandLineArgs && cl->callbacks->cbGetFrameworkCount(cl, frameworkCount))
+ return cwErrRequestFailed;
+ return cwNoErr;
+}
+
+CW_CALLBACK CWGetFrameworkInfo(CWPluginContext context, SInt32 whichFramework, CWFrameworkInfo* frameworkInfo) {
+ CWCompilerLinkerContext *cl;
+ if (!(cl = GetContext(context)))
+ return cwErrInvalidCallback;
+ if (cl->apiVersion < 11)
+ return cwErrInvalidCallback;
+ if (!cl->commandLineArgs && cl->callbacks->cbGetFrameworkInfo(cl, whichFramework, frameworkInfo))
+ return cwErrRequestFailed;
+ return cwNoErr;
+}