home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / xpk_Source.lha / xpk_Source / xpkmaster / hook.c < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  74 lines

  1. #ifndef XPKMASTER_HOOK_C
  2. #define XPKMASTER_HOOK_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        hook.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: hook.c 1.3 (09.01.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Hook handling functions
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   27.12.96 : removed V37 defines
  15.  1.2   20.12.97 : nearly rewritten
  16.  1.3   09.01.98 : added XPK_ALLINONE
  17. */
  18.  
  19. #include <exec/types.h>
  20. #include "xpkmaster.h"
  21.  
  22. #ifdef DEBUG
  23. static STRPTR action_names[8] =
  24. {"<zero>", "XIO_READ", "XIO_WRITE", "XIO_FREE", "XIO_ABORT", "XIO_GETBUF",
  25. "XIO_SEEK", "XIO_TOTSIZE" };
  26. #endif
  27.  
  28. static APTR callhook(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  29. ULONG size, struct XpkMasterMsg *msg, struct Hook *hook)
  30. {
  31.   LONG res;
  32.  
  33.   msg->xmm_Type = action;
  34.   msg->xmm_Ptr = (STRPTR) buf;
  35.   msg->xmm_Size = size;
  36.  
  37.   if(!hook)
  38.     return 0;
  39.  
  40.   if((res = (*(regfunc) hook->h_Entry) (hook, msg, 0 A4SUPP2)))
  41.   {
  42.     xbuf->xb_Result = res;
  43. #ifdef DEBUG
  44.     DebugError("hook%s: %s <%ld> (%ld)", msg == &xbuf->xb_RMsg ? "read" :
  45.     "write", action_names[(action&7)], action, xbuf->xb_Result);
  46. #endif
  47.   }
  48.  
  49.   if(xbuf->xb_Result)
  50.     return 0;
  51.   else if(msg->xmm_Ptr)
  52.     return (APTR) msg->xmm_Ptr;
  53.   else
  54.     return (APTR) -1; /* SEEK may return 0 on success! */
  55. }
  56.  
  57. /*************************** read from input hook ************************/
  58.  
  59. XPK_ALLINONE APTR hookread(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  60. ULONG size)
  61. {
  62.   return callhook(xbuf, action, buf, size, &xbuf->xb_RMsg, xbuf->xb_RHook);
  63. }
  64.  
  65. /*************************** write to output hook ************************/
  66.  
  67. XPK_ALLINONE APTR hookwrite(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  68. ULONG size)
  69. {
  70.   return callhook(xbuf, action, buf, size, &xbuf->xb_WMsg, xbuf->xb_WHook);
  71. }
  72.  
  73. #endif /* XPKMASTER_HOOK_C */
  74.