home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_source / xpkmaster / hook.c < prev    next >
C/C++ Source or Header  |  1996-10-29  |  3KB  |  118 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.0 (05.10.96)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    Hook handling functions
  12.  
  13.  1.0   05.10.96 : first real version
  14. */
  15.  
  16. #include <exec/types.h>
  17. #include "xpkmaster.h"
  18.  
  19. #ifndef XPK_MINOS_37
  20. typedef ULONG __asm (*regfunc) (register __a0 struct Hook *,
  21.             register __a1 APTR,
  22.             register __a2 APTR
  23. #ifdef SUPPORT_A4
  24.             ,register __a4 ULONG
  25. #endif
  26.             );
  27.  
  28. ULONG __asm MyCallHookPkt(register __a0 struct Hook *hook,
  29. register __a1 APTR paramPacket A4PROTO)
  30. {
  31.   if(!hook)
  32.     return 0;
  33.  
  34.   return (*(regfunc) hook->h_Entry) (hook, paramPacket, NULL A4SUPP);
  35. }
  36. #endif
  37.  
  38. #ifdef DEBUG
  39. static STRPTR action_names[8] =
  40. {"<zero>", "XIO_READ", "XIO_WRITE", "XIO_FREE", "XIO_ABORT", "XIO_GETBUF",
  41. "XIO_SEEK", "XIO_TOTSIZE" };
  42. #endif
  43.  
  44. /*************************** read from input hook ************************/
  45.  
  46. APTR hookread(struct XpkBuffer *xbuf, ULONG action, APTR buf, ULONG size)
  47. {
  48.   LONG res;
  49.  
  50.   xbuf->xb_RMsg.xmm_Type = action;
  51.   xbuf->xb_RMsg.xmm_Ptr = (STRPTR) buf;
  52.   xbuf->xb_RMsg.xmm_Size = size;
  53.  
  54.   if((res = MyCallHookPkt(xbuf->xb_RHook, &xbuf->xb_RMsg A4SUPP2)))
  55.   {
  56.     xbuf->xb_Result = res;
  57.     xbuf->xb_Result2 = xbuf->xb_RMsg.xmm_IOError;
  58.   }
  59.  
  60.   if(xbuf->xb_Result)
  61.   {
  62. #ifdef DEBUG
  63.     DebugError("hookread: %s <%ld> (%ld)", action_names[(action&7)], action,
  64.     xbuf->xb_Result);
  65. #endif
  66.     return NULL;
  67.   }
  68.   else if (xbuf->xb_RMsg.xmm_Ptr)
  69.     return (APTR) xbuf->xb_RMsg.xmm_Ptr;
  70.   else
  71.     return (APTR) 42;    /* SEEK may return 0 an success!  :-( */
  72. }
  73.  
  74.  
  75. /*************************** write to output hook ************************/
  76.  
  77. APTR hookwrite(struct XpkBuffer *xbuf, ULONG action, APTR buf, ULONG size)
  78. {
  79.   LONG res;
  80.  
  81.   xbuf->xb_WMsg.xmm_Type = action;
  82.   xbuf->xb_WMsg.xmm_Ptr = (STRPTR) buf;
  83.   xbuf->xb_WMsg.xmm_Size = size;
  84.  
  85.   if((res = MyCallHookPkt(xbuf->xb_WHook, &xbuf->xb_WMsg A4SUPP2)))
  86.   {
  87.     xbuf->xb_Result = res;
  88.     xbuf->xb_Result2 = xbuf->xb_WMsg.xmm_IOError;
  89.   }
  90.   else if(action == XIO_WRITE)
  91.     xbuf->xb_OutLen += size;
  92.  
  93.   if(xbuf->xb_Result)
  94.   {
  95. #ifdef DEBUG
  96.     DebugError("hookwrite: %s <%ld> (%ld)", action_names[(action&7)], action,
  97.     xbuf->xb_Result);
  98. #endif
  99.     return NULL;
  100.   }
  101.   else if(xbuf->xb_WMsg.xmm_Ptr)
  102.     return (APTR) xbuf->xb_WMsg.xmm_Ptr;
  103.   else
  104.     return (APTR) 42;    /* SEEK may return 0 an success!  :-( */
  105. }
  106.  
  107. /*********************** copy data from in to out hook **********************/
  108.  
  109. LONG copydata (struct XpkBuffer *xbuf, ULONG insize, ULONG outsize)
  110. {
  111.   STRPTR buf;
  112.  
  113.   return !(buf = (STRPTR) hookread(xbuf, XIO_READ, NULL, insize)) ||
  114.   !hookwrite(xbuf, XIO_WRITE, buf, outsize);
  115. }
  116.  
  117. #endif /* XPKMASTER_HOOK_C */
  118.