home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / libs / iffparse / clipboardfuncs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-03  |  2.6 KB  |  128 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: clipboardfuncs.c,v 1.2 1997/02/03 18:38:00 digulla Exp $
  4.  
  5.     Desc: Helpfuncs needed when iffparse is used for clipboard handling.
  6.     Lang: English.
  7. */
  8. #include "iffparse_intern.h"
  9.  
  10.  
  11. /***********************/
  12. /* Port initialization */
  13. /***********************/
  14.  
  15. /* Initializes and Closes PRIVATE ports     */
  16. /* Used in OpenClipboard and CloseClipboard */
  17. /* Look at page 501-502 in RKM Libraries     */
  18.  
  19. BOOL InitPort (struct MsgPort *mp, struct Task *t,
  20.     struct IFFParseBase_intern * IFFParseBase)
  21. {
  22.     LONG sigbit;
  23.  
  24.     if ((sigbit = AllocSignal(-1L) == -1)) return (FALSE);
  25.  
  26.     mp->mp_Node.ln_Type = NT_MSGPORT;
  27.     mp->mp_Flags    =  PA_SIGNAL;
  28.     mp->mp_SigBit     =  sigbit;
  29.     mp->mp_SigTask    =  t;
  30.  
  31.     NewList(&(mp->mp_MsgList));
  32.  
  33.     return (TRUE);
  34. }
  35.  
  36. VOID ClosePort (struct MsgPort *mp,
  37.     struct IFFParseBase_intern * IFFParseBase)
  38. {
  39.     mp->mp_SigTask        =  (struct Task*)-1;
  40.     mp->mp_MsgList.lh_Head  = (struct Node*)-1;
  41.  
  42.     FreeSignal( mp->mp_SigBit );
  43.  
  44.     return;
  45. }
  46.  
  47.  
  48. /**********************/
  49. /* ClipStreamHandler  */
  50. /**********************/
  51.  
  52. #undef SysBase
  53. #define SysBase     (IPB(hook->h_Data)->sysbase)
  54.  
  55. ULONG ClipStreamHandler
  56. (
  57.     struct Hook     * hook,
  58.     struct IFFHandle    * iff,
  59.     struct IFFStreamCmd * cmd
  60. )
  61. {
  62.     #define CLIPSCANBUFSIZE 500
  63.     LONG error = NULL;
  64.  
  65.     /* Buffer neede for reading rest of clip in IFFCMD_CLEANUP. Eats some stack */
  66.     UBYTE  buf[CLIPSCANBUFSIZE];
  67.  
  68.     struct IOClipReq *req;
  69.  
  70.     req = &( ((struct ClipboardHandle*)iff->iff_Stream)->cbh_Req);
  71.  
  72.     switch (cmd->sc_Command)
  73.     {
  74.     case IFFCMD_READ:
  75.         req->io_Command = CMD_READ;
  76.         req->io_Data    = cmd->sc_Buf;
  77.         req->io_Length  =  cmd->sc_NBytes;
  78.  
  79.         error = (DoIO((struct IORequest*)req));
  80.  
  81.         break;
  82.  
  83.     case IFFCMD_WRITE:
  84.         req->io_Command = CMD_WRITE;
  85.         req->io_Data    = cmd->sc_Buf;
  86.         req->io_Length  =  cmd->sc_NBytes;
  87.  
  88.         error = (DoIO((struct IORequest*)req));
  89.  
  90.         break;
  91.  
  92.     case IFFCMD_SEEK:
  93.  
  94.         req->io_Offset += cmd->sc_NBytes;
  95.  
  96.         if (req->io_Offset < 0)
  97.         error = TRUE;
  98.  
  99.         break;
  100.  
  101.     case IFFCMD_INIT:
  102.         /* Start reading and writing at offset 0 */
  103.         req->io_ClipID = 0;
  104.         req->io_Offset = 0;
  105.         break;
  106.  
  107.     case IFFCMD_CLEANUP:
  108.         /* Read past end of clip if we are in read mode */
  109.  
  110.         req->io_Command = CMD_READ;
  111.         req->io_Data    = buf;
  112.         req->io_Length  =  CLIPSCANBUFSIZE;
  113.  
  114.  
  115.         if (iff->iff_Flags & IFFF_READ)
  116.         {
  117.         /* Read until there is not more left */
  118.         while (req->io_Actual)
  119.             DoIO((struct IORequest*)req);
  120.  
  121.         }
  122.         break;
  123.  
  124.     }
  125.  
  126.     return (error);
  127. }
  128.