home *** CD-ROM | disk | FTP | other *** search
/ MACD 9 / MACD9.iso / Datatypes / MacPict2 / Macpaint / desc_macpaint.c next >
Encoding:
C/C++ Source or Header  |  1997-02-21  |  2.5 KB  |  87 lines

  1. ;/*
  2. SC desc_macpaint.c nodebug opt optsize link nostrt nostkext nostkchk
  3. quit 
  4. */
  5. /* This description function replaces the original MacPaint datatype
  6.    recognition found in "pictdt_42_1.lha" archive (on NDU3.1 disks) */
  7.  
  8. /* Execute this file to compile with SAS C 
  9.  * Ex. "1.Ram:>execute desc_macpaint.c"
  10.  *
  11.  * Otherwise it must be compiled with no stack checking. 
  12.  * It must not be linked with any startup code so that DTHook is
  13.  * the entry point for the executable.
  14.  *
  15.  */
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <dos/dos.h>
  19. #include <dos/dosextens.h>
  20. #include <datatypes/datatypes.h>
  21. #include <datatypes/pictureclass.h>
  22.  
  23. #include <clib/exec_protos.h>
  24. #include <clib/dos_protos.h>
  25. #include <clib/utility_protos.h>
  26.  
  27. #include <pragmas/exec_pragmas.h>
  28. #include <pragmas/dos_pragmas.h>
  29. #include <pragmas/utility_pragmas.h>
  30.  
  31. #define SysBase          dthc->dthc_SysBase
  32. #define DOSBase          dthc->dthc_DOSBase
  33. #define UtilityBase      dthc->dthc_UtilityBase
  34.  
  35. BOOL __asm DTHook (register __a0 struct DTHookContext * dthc)
  36. {
  37.   BOOL retval = FALSE;
  38.   ULONG n, *chk;
  39.   UWORD *chkpict;
  40.   UBYTE *buffer;
  41.   BPTR fh;
  42.  
  43.   /* Make sure we have a filehandle */
  44.   if (fh = dthc->dthc_FileHandle) {
  45.     /* Allocate a buffer */
  46.     if(buffer = AllocVec(0x100, MEMF_PUBLIC)) {
  47.  
  48.       /* Read first $100 bytes */
  49.       if(Read(fh, buffer, 0x100) == 0x100) {
  50.         if(buffer[0] == 0) {
  51.  
  52.           /* Check for PNTG mark */
  53.           chk = (ULONG *) &buffer[0x41];
  54.           if((*chk == 0x504E5447) && (buffer[0x4b] == 0)) 
  55.             /* Now we are sure it is a macpaint picture */
  56.             retval = TRUE;
  57.  
  58.           /* This will be harder */
  59.           else {
  60.             chk = (ULONG *) buffer; /* This will normally be 0x00000002 */
  61.             if((n = Seek(fh, 0x135, OFFSET_BEGINNING) >= 0L) && (*chk <= 4UL))
  62.               /* Get next $100 bytes */
  63.               if(Read(fh, buffer, 0x100) == 0x100) {
  64.                 retval = TRUE;
  65.  
  66.                 /* First bytes must all be zero */
  67.                 for(n = 0; (n < 0x80) && (retval==TRUE); n++)
  68.                   if(buffer[n] != 0) retval = FALSE;
  69.  
  70.                   /* We do not want a Mac PICT file, check for version number
  71.                     at filepos 0x20a */
  72.                     chkpict = (UWORD *) &buffer[0xcb];
  73.                     if((chkpict[5]==0x0011) && (chkpict[6]==0x02ff))
  74.                       retval = FALSE;
  75.               }
  76.           }
  77.         }
  78.       }
  79.       /* Do not steal memory */
  80.       FreeVec(buffer);
  81.     }
  82.   }    
  83.   return retval;
  84. }
  85.  
  86.  
  87.