Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / iffparse / clipboardfuncs.c
blob3fb16e85931eab3d867600788962e00213a7823c
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Helpfuncs needed when iffparse is used for clipboard handling.
6 */
7 #include "iffparse_intern.h"
8 #include <exec/io.h>
10 #include <aros/debug.h>
12 #define DEBUG_STREAM(x) ;
14 /***********************/
15 /* Port initialization */
16 /***********************/
18 /* Initializes and Closes PRIVATE ports */
19 /* Used in OpenClipboard and CloseClipboard */
20 /* Look at page 501-502 in RKM Libraries */
22 BOOL InitPort (struct MsgPort *mp, struct Task *t,
23 struct IFFParseBase_intern * IFFParseBase)
25 LONG sigbit;
27 if ((sigbit = AllocSignal(-1L)) == -1) return (FALSE);
29 mp->mp_Node.ln_Type = NT_MSGPORT;
30 mp->mp_Flags = PA_SIGNAL;
31 mp->mp_SigBit = sigbit;
32 mp->mp_SigTask = t;
34 NewList(&(mp->mp_MsgList));
36 return (TRUE);
39 VOID ClosePort (struct MsgPort *mp,
40 struct IFFParseBase_intern * IFFParseBase)
42 mp->mp_SigTask = (struct Task*)-1;
43 mp->mp_MsgList.lh_Head = (struct Node*)-1;
45 FreeSignal( mp->mp_SigBit );
47 return;
51 /**********************/
52 /* ClipStreamHandler */
53 /**********************/
55 #define IFFParseBase IPB(hook->h_Data)
57 ULONG ClipStreamHandler
59 struct Hook * hook,
60 struct IFFHandle * iff,
61 struct IFFStreamCmd * cmd
64 #define CLIPSCANBUFSIZE 10000000 //500
65 ULONG error = 0;
67 /* Buffer neede for reading rest of clip in IFFCMD_CLEANUP. Eats some stack */
68 // UBYTE buf[CLIPSCANBUFSIZE];
70 struct IOClipReq *req;
72 req = &( ((struct ClipboardHandle*)iff->iff_Stream)->cbh_Req);
74 DEBUG_STREAM(bug("ClipStream: iff %p cmd %d buf %p bytes %d\n",
75 iff, cmd->sc_Command, cmd->sc_Buf, cmd->sc_NBytes));
77 switch (cmd->sc_Command)
79 case IFFCMD_READ:
81 DEBUG_BUFSTREAMHANDLER(dprintf("ClipStream: IFFCMD_READ...\n"));
83 req->io_Command = CMD_READ;
84 req->io_Data = cmd->sc_Buf;
85 req->io_Length = cmd->sc_NBytes;
87 error = (DoIO((struct IORequest*)req));
89 break;
91 case IFFCMD_WRITE:
93 DEBUG_BUFSTREAMHANDLER(dprintf("ClipStream: IFFCMD_WRITE...\n"));
95 req->io_Command = CMD_WRITE;
96 req->io_Data = cmd->sc_Buf;
97 req->io_Length = cmd->sc_NBytes;
99 error = (DoIO((struct IORequest*)req));
101 break;
103 case IFFCMD_SEEK:
105 DEBUG_BUFSTREAMHANDLER(dprintf("ClipStream: IFFCMD_SEEK...\n"));
107 req->io_Offset += cmd->sc_NBytes;
109 if (req->io_Offset < 0)
110 error = TRUE;
112 break;
114 case IFFCMD_INIT:
116 DEBUG_BUFSTREAMHANDLER(dprintf("ClipStream: IFFCMD_INIT...\n"));
118 /* Start reading and writing at offset 0 */
119 req->io_ClipID = 0;
120 req->io_Offset = 0;
121 break;
123 case IFFCMD_CLEANUP:
125 DEBUG_BUFSTREAMHANDLER(dprintf("ClipStream: IFFCMD_CLEANUP...\n"));
127 if ((iff->iff_Flags & IFFF_RWBITS) == IFFF_READ)
129 /* Read past end of clip if we are in read mode */
130 req->io_Command = CMD_READ;
131 req->io_Data = NULL;
132 req->io_Length = CLIPSCANBUFSIZE;
134 /* Read until there is not more left */
137 DoIO((struct IORequest*)req);
139 while (req->io_Actual==req->io_Length);
143 if ((iff->iff_Flags & IFFF_RWBITS) == IFFF_WRITE)
145 req->io_Command = CMD_UPDATE;
146 DoIO((struct IORequest*)req);
148 break;
152 DEBUG_STREAM(bug("ClipStream: error %ld\n", error));
154 return (error);