+#if defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ > 0x5300)
+
+#if !TARGET_API_MAC_CARBON
+// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
+
+#ifndef __MetroNubUtils__
+#include "MetroNubUtils.h"
+#endif
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#ifndef __GESTALT__
+#include <Gestalt.h>
+#endif
+
+#ifndef true
+#define true 1
+#endif
+
+#ifndef false
+#define false 0
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+ #include <CodeFragments.h>
+
+ EXTERN_API_C( long )
+ CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
+
+ ProcPtr gCallUniversalProc_Proc = NULL;
+
+#endif
+
+static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
+
+static long fRunOnce = false;
+
+Boolean IsCompatibleVersion(short inVersion);
+
+/* ---------------------------------------------------------------------------
+ IsCompatibleVersion
+ --------------------------------------------------------------------------- */
+
+Boolean IsCompatibleVersion(short inVersion)
+{
+ Boolean result = false;
+
+ if (fRunOnce)
+ {
+ MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
+
+ result = (inVersion <= block->apiHiVersion);
+ }
+
+ return result;
+}
+
+/* ---------------------------------------------------------------------------
+ IsMetroNubInstalled
+ --------------------------------------------------------------------------- */
+
+Boolean IsMetroNubInstalled()
+{
+ if (!fRunOnce)
+ {
+ long result, value;
+
+ fRunOnce = true;
+ gMetroNubEntry = NULL;
+
+ if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
+ {
+ /* look for MetroNub's Gestalt selector */
+ if (Gestalt(kMetroNubUserSignature, &result) == noErr)
+ {
+
+ #if TARGET_API_MAC_CARBON
+ if (gCallUniversalProc_Proc == NULL)
+ {
+ CFragConnectionID connectionID;
+ Ptr mainAddress;
+ Str255 errorString;
+ ProcPtr symbolAddress;
+ OSErr err;
+ CFragSymbolClass symbolClass;
+
+ symbolAddress = NULL;
+ err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
+ &connectionID, &mainAddress, errorString);
+
+ if (err != noErr)
+ {
+ gCallUniversalProc_Proc = NULL;
+ goto end;
+ }
+
+ err = FindSymbol(connectionID, "\pCallUniversalProc",
+ (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
+
+ if (err != noErr)
+ {
+ gCallUniversalProc_Proc = NULL;
+ goto end;
+ }
+ }
+ #endif
+
+ {
+ MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
+
+ /* make sure the version of the API is compatible */
+ if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
+ kMetroNubUserAPIVersion <= block->apiHiVersion)
+ gMetroNubEntry = block; /* success! */
+ }
+
+ }
+ }
+ }
+
+end:
+
+#if TARGET_API_MAC_CARBON
+ return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
+#else
+ return (gMetroNubEntry != NULL);
+#endif
+}
+
+/* ---------------------------------------------------------------------------
+ IsMWDebuggerRunning [v1 API]
+ --------------------------------------------------------------------------- */
+
+Boolean IsMWDebuggerRunning()
+{
+ if (IsMetroNubInstalled())
+ return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
+ else
+ return false;
+}
+
+/* ---------------------------------------------------------------------------
+ AmIBeingMWDebugged [v1 API]
+ --------------------------------------------------------------------------- */
+
+Boolean AmIBeingMWDebugged()
+{
+ if (IsMetroNubInstalled())
+ return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
+ else
+ return false;
+}
+
+/* ---------------------------------------------------------------------------
+ UserSetWatchPoint [v2 API]
+ --------------------------------------------------------------------------- */
+
+OSErr UserSetWatchPoint (Ptr address, long length, WatchPointIDT* watchPointID)
+{
+ if (IsMetroNubInstalled() && IsCompatibleVersion(kMetroNubUserAPIVersion))
+ return CallUserSetWatchPointProc(gMetroNubEntry->userSetWatchPoint,
+ address, length, watchPointID);
+ else
+ return errProcessIsNotClient;
+}
+
+/* ---------------------------------------------------------------------------
+ ClearWatchPoint [v2 API]
+ --------------------------------------------------------------------------- */
+
+OSErr ClearWatchPoint (WatchPointIDT watchPointID)
+{
+ if (IsMetroNubInstalled() && IsCompatibleVersion(kMetroNubUserAPIVersion))
+ return CallClearWatchPointProc(gMetroNubEntry->clearWatchPoint, watchPointID);
+ else
+ return errProcessIsNotClient;
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif // !TARGET_API_MAC_CARBON
+
+#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ > 0x5300)
+