2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
5 Helpfuncs needed when iffparse is used for clipboard handling.
7 #include "iffparse_intern.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
)
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
;
34 NewList(&(mp
->mp_MsgList
));
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
);
51 /**********************/
52 /* ClipStreamHandler */
53 /**********************/
55 #define IFFParseBase IPB(hook->h_Data)
57 ULONG ClipStreamHandler
60 struct IFFHandle
* iff
,
61 struct IFFStreamCmd
* cmd
64 #define CLIPSCANBUFSIZE 10000000 //500
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
)
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
));
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
));
105 DEBUG_BUFSTREAMHANDLER(dprintf("ClipStream: IFFCMD_SEEK...\n"));
107 req
->io_Offset
+= cmd
->sc_NBytes
;
109 if (req
->io_Offset
< 0)
116 DEBUG_BUFSTREAMHANDLER(dprintf("ClipStream: IFFCMD_INIT...\n"));
118 /* Start reading and writing at offset 0 */
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
;
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
);
152 DEBUG_STREAM(bug("ClipStream: error %ld\n", error
));