home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / Split_GUI.lha / Split_v1.0 / Sources.lha / Sources / diskhandler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-06  |  1.7 KB  |  73 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/interrupts.h>
  4. #include <devices/input.h>
  5.  
  6. #include <proto/exec.h>
  7.  
  8. extern void checkDisk( void );
  9. extern void patchDOSlibrary( void );
  10. extern BOOL resetDOSlibrary( void );
  11.  
  12. struct Interrupt *diskhandler;
  13. struct IOStdReq *inputIO;
  14. struct MsgPort *inputMPort;
  15. BYTE diskBit;
  16. ULONG diskSig;
  17. struct Task *thisTask;
  18.  
  19. /*
  20.  * This handler signals us the user has inserted or removed a disk,
  21.  * or some file has been deleted or written. This piece of code sets
  22.  * up the handler; the main code for the handler is in handler.s, in
  23.  * which there is also the code for patching OS functions Delete and
  24.  * Close.
  25.  */
  26.  
  27. BOOL setDiskHandler( void )
  28. {
  29. if ( (diskBit = AllocSignal( -1 )) != -1 )
  30.     {
  31.     diskSig = 1L<<diskBit;
  32.     thisTask = FindTask( NULL );
  33.  
  34.     if ( inputMPort = CreateMsgPort() )
  35.         {
  36.         if ( inputIO = CreateIORequest( inputMPort, sizeof(struct IOStdReq) ) )
  37.             {
  38.             if ( !( OpenDevice( "input.device", 0, (struct IORequest *)inputIO, 0 ) ) )
  39.                 {
  40.                 if ( diskhandler = AllocVec( sizeof(struct Interrupt), MEMF_ANY | MEMF_CLEAR ) )
  41.                     {
  42.                     diskhandler->is_Code = checkDisk;
  43.                     diskhandler->is_Data = NULL;
  44.                     diskhandler->is_Node.ln_Pri = 100;
  45.                     diskhandler->is_Node.ln_Name = "Split-DiskHandler";
  46.  
  47.                     inputIO->io_Data = (APTR)diskhandler;
  48.                     inputIO->io_Command = IND_ADDHANDLER;
  49.                     DoIO( (struct IORequest *)inputIO );
  50.  
  51.                     return TRUE;
  52.                     }
  53.                 }
  54.             DeleteIORequest( inputIO );
  55.             }
  56.         DeleteMsgPort( inputMPort );
  57.         }
  58.     FreeSignal( diskBit );
  59.     }
  60. return FALSE;
  61. }
  62.  
  63.  
  64. void removeDiskHandler( void )
  65. {
  66. inputIO->io_Data = (APTR)diskhandler;
  67. inputIO->io_Command = IND_REMHANDLER;
  68. DoIO( (struct IORequest *)inputIO );
  69. DeleteIORequest( inputIO );
  70. DeleteMsgPort( inputMPort );
  71. FreeSignal( diskBit );
  72. }
  73.