home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / SysBeep INIT / INIT.c next >
Encoding:
C/C++ Source or Header  |  1993-08-12  |  1.6 KB  |  118 lines  |  [TEXT/KAHL]

  1. #include <Traps.h>
  2. #include <SetUpA4.h>
  3.  
  4. #define goodICON    128
  5. #define badICON        129
  6. #define procID        256
  7. #define patchName    "\pSysBeep Patch"
  8. #define EQSTR        0
  9.  
  10.  
  11.  
  12. void ShowInit(int ID)
  13. {
  14. Handle        procH;
  15.         
  16.     if ((procH = GetResource('PROC', procID)) != 0L)
  17.     {
  18.         HLock(procH);
  19.         CallPascal(ID, -1, *procH);
  20.         HUnlock(procH);
  21.         ReleaseResource(procH);
  22.     }
  23. }
  24.  
  25.  
  26.  
  27. static int    ShiftKey()
  28. {
  29. char    theKeyMap[16];
  30.     
  31.     GetKeys(theKeyMap);
  32.     return(theKeyMap[7] & 0x01);
  33. }
  34.  
  35.  
  36.  
  37. int strcmp(char *string1, char *string2)
  38. {
  39. register char    *s1,*s2;
  40.  
  41.     s1 = string1;
  42.     s2 = string2;
  43.     
  44.     while(*s1 == *s2 && *s2 && *s1)
  45.     {
  46.         s1++; 
  47.         s2++;
  48.     }
  49.     
  50.     if (*s1 == *s2) 
  51.         return(EQSTR);
  52.     else
  53.         return(!EQSTR);
  54. }
  55.  
  56.  
  57. main()
  58. {
  59. char         *moof,installed;
  60. Handle         myCodeRes;
  61. long        theSize;
  62. long        oldTrap;
  63.  
  64.     RememberA0();
  65.     SetUpA4();
  66.     
  67.     installed = FALSE;
  68.     
  69.     if (!ShiftKey())
  70.     {
  71.         myCodeRes = GetNamedResource('RoyW',patchName);
  72.                 
  73.         if(myCodeRes == nil)
  74.         {
  75.             SysBeep(1);
  76.         }
  77.         
  78.         else
  79.         {
  80.             theSize = GetHandleSize(myCodeRes);
  81.             
  82.             for(moof=*myCodeRes;theSize>0 && strcmp(moof,"moof")!=EQSTR;moof++,theSize--);
  83.             
  84.             if (theSize <= 0L || strcmp(moof,"moof") != EQSTR)
  85.             {
  86.                 SysBeep(1);
  87.                 SysBeep(1);
  88.             }
  89.             
  90.             else
  91.             {
  92.                 oldTrap = NGetTrapAddress((int) (_SysBeep - 0xA000),ToolTrap);
  93.                 
  94.                 moof += 4L;
  95.                 *((long *) moof) = oldTrap;
  96.                 
  97.                 DetachResource(myCodeRes);
  98.                 HUnlock(myCodeRes);
  99.                 MoveHHi(myCodeRes);
  100.                 HLock(myCodeRes);
  101.                 
  102.                 NSetTrapAddress((long) StripAddress(*myCodeRes),(_SysBeep - 0xA000),ToolTrap);
  103.                     
  104.                 installed = TRUE;
  105.             }
  106.         }
  107.     }    
  108.     
  109.     if (!installed)
  110.     {
  111.         ShowInit(badICON);
  112.     }
  113.     
  114.     else
  115.         ShowInit(goodICON);
  116.     
  117.     RestoreA4();
  118. }