home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / 第1特集Plug-in / Photoshop / Plug-in_Kit_2.5.1.sit / Plug-in_Kit_2.5.1 / 68kmain.c < prev    next >
C/C++ Source or Header  |  1994-04-12  |  4KB  |  149 lines

  1. #define SystemSevenOrLater 1 /* Needed to force Gestalt to be a direct trap. */
  2. #define USESROUTINEDESCRIPTORS 1
  3.  
  4. #include <Memory.h>
  5. #include <Errors.h>
  6. #include <Resources.h>
  7. #include <Traps.h>
  8. #include <FragLoad.h>
  9. #include <MixedMode.h>
  10.  
  11. #include <PITypes.h>
  12. #include <PIFilter.h>
  13.  
  14. extern UniversalProcPtr LoadMyDataForkFragment(ProcInfoType procInfo,
  15.                                                ConnectionID *fragID,
  16.                                                OSErr *erroRet);
  17.  
  18. extern Boolean IsSystem7(void);
  19. extern Boolean IsPowerPC(void);
  20.  
  21. #define uppPSPlugInProcInfo                                    ¥
  22.     (kPascalStackBased | RESULT_SIZE(kNoByteCode) |            ¥
  23.      STACK_ROUTINE_PARAMETER(1, kTwoByteCode) |                ¥
  24.      STACK_ROUTINE_PARAMETER(2, kFourByteCode) |            ¥
  25.      STACK_ROUTINE_PARAMETER(3, kFourByteCode) |            ¥
  26.      STACK_ROUTINE_PARAMETER(4, kFourByteCode))
  27.  
  28. typedef pascal void PlugInEntryProc(short, void *, long *, short *);
  29.  
  30. /* Just for type checking. */
  31. PlugInEntryProc main;
  32.  
  33. typedef struct {
  34.     PlugInEntryProc *entryPoint;
  35.     ConnectionID connection;
  36.     long plugInData;
  37. } InterposerPlugInInfo;
  38.  
  39. pascal void main(short selector, void *stuff, long *data, short *result)
  40. {
  41.     UniversalProcPtr routineDesc;
  42.     OSErr error;
  43.     InterposerPlugInInfo **saveInfo = (InterposerPlugInInfo **)data;
  44.  
  45.     if (!IsSystem7() || !IsPowerPC()) {
  46.         /* Feel free to call a 68K routine that implements your filter instead. */
  47.         *result = 1;
  48.         return;
  49.     }
  50.  
  51.     if (*saveInfo == NULL) {
  52.         ConnectionID fragID;
  53.  
  54.         if ((routineDesc = LoadMyDataForkFragment(uppPSPlugInProcInfo, &fragID, &error)) == NULL) {
  55. #ifdef DEBUG
  56.             DebugStr("¥pCouldn't load.¥n");
  57. #endif
  58.             *result = error;
  59.             return;
  60.         }
  61.         else {
  62.             InterposerPlugInInfo *myInfo;
  63.  
  64.             if ((myInfo = (InterposerPlugInInfo *)NewPtr(sizeof(InterposerPlugInInfo))) == NULL) {
  65.                 *result = MemError();
  66.                 return;
  67.             }
  68.  
  69.             myInfo->entryPoint = (PlugInEntryProc *)routineDesc;
  70.             myInfo->connection = fragID;
  71.             myInfo->plugInData = (long)NULL;
  72.  
  73.             *saveInfo = myInfo;
  74.  
  75.         }
  76.  
  77.     }
  78.  
  79.     if (*saveInfo != NULL)
  80.         ((*saveInfo)->entryPoint)(selector, stuff, &((*saveInfo)->plugInData), result);
  81.  
  82.     /* Unload the plug-in if we're done. This is non-optimal in that
  83.      * repeated invocations of a filter require it to be reloaded each
  84.      * time, but we don't pay this cost on continue calls etc. so it isn't
  85.      * that bad.
  86.      */ 
  87.     if (selector == filterSelectorFinish) {
  88.         CloseConnection(&(*saveInfo)->connection);
  89.         DisposePtr((Ptr)*saveInfo);
  90.         *saveInfo = NULL;
  91.     }
  92.  
  93. }
  94.  
  95. static UniversalProcPtr LoadMyDataForkFragment(ProcInfoType procInfo, ConnectionID *fragID, OSErr *errorRet)
  96. {
  97.     FCBPBRec thisFileInfo;
  98.     FSSpec fileSpec;
  99.     ConnectionID myFragID;
  100.     Ptr entryAddress;
  101.     Str255 error;
  102.     RoutineDescriptor *theDesc;
  103.     OSErr loadError;
  104.  
  105.     thisFileInfo.ioNamePtr = (StringPtr)&fileSpec.name    ;
  106.     thisFileInfo.ioRefNum = CurResFile();
  107.     thisFileInfo.ioFCBIndx = 0;
  108.     PBGetFCBInfo(&thisFileInfo, false);
  109.     if (thisFileInfo.ioResult != noErr)
  110.         return NULL;
  111.  
  112.     fileSpec.vRefNum = thisFileInfo.ioFCBVRefNum;
  113.     fileSpec.parID = thisFileInfo.ioFCBParID;
  114.     
  115.     if ((loadError = GetDiskFragment(&fileSpec, 0, 0, NULL, kLoadLib, &myFragID, &entryAddress, &error)) != noErr) {
  116. #ifdef DEBUG
  117.         DebugStr(error);
  118. #endif
  119.         if (errorRet != NULL)
  120.             *errorRet = loadError;
  121.         return NULL;
  122.     }
  123.  
  124.     if (fragID != NULL)
  125.         *fragID = myFragID;
  126.  
  127.     theDesc = NewRoutineDescriptor((ProcPtr)entryAddress, procInfo, kPowerPCISA);
  128.  
  129.     return theDesc;
  130. }
  131.  
  132. #include <GestaltEqu.h>
  133.  
  134. static Boolean IsSystem7(void)
  135. {
  136.     SysEnvRec environs;
  137.  
  138.     return (SysEnvirons(1, &environs) == noErr &&
  139.             environs.systemVersion >= 0x0700);
  140. }
  141.  
  142. static Boolean IsPowerPC(void)
  143. {
  144.     long systemArchitecture;
  145.  
  146.     return (Gestalt(gestaltSysArchitecture, &systemArchitecture) == noErr &&
  147.             systemArchitecture == gestaltPowerPC);
  148. }
  149.