#include <iff/iffparse.h>

typedef struct {
    unsigned Complex : 1;
    unsigned Size    : 15;
} chunk;

struct IFF {
    ULONG   iff_Stream;
    ULONG   iff_Flags;
    ULONG   iff_Depth;
    chunk   *iff_Stack;
    short   iff_Type;
    struct ContextNode current;
};

struct CBHandle {
	struct IOClipReq	*cbh_Req;
	struct MsgPort		*cbh_CBport;
	struct MsgPort		*cbh_SatisfyPort;
};
#define TraceCall  KPutStr(__FUNC__"\n")
#define DoClipIO(req)   DoIO((struct IORequest *)req)
#define IOReq(iff)      ((struct CBHandle *)iff->iff_Stream)->cbh_Req
#define File(iff)       (BPTR)((struct FileHandle *)iff->iff_Stream)
#define IFFStack        iff->iff_Stack
#define IFFScan         iff->iff_Scan
#define IFFptr          iff->iff_Depth

#define FILEHANDLE 0x01
#define IOREQUEST  0x02

void *NULL_NOOP();
long NOOP();
long GoodID();
long GoodType();
UBYTE *IDtoStr(long ID, UBYTE *Buf);
long InitIFFasClip(struct IFF *iff);
long InitIFFasDOS(struct IFF *iff);
long OpenIFF(struct IFF *iff, long rwmode);
void CloseIFF(struct IFF *iff);
struct IFF *AllocIFF(void);
void FreeIFF(struct IFF *iff);
struct CBHandle *OpenClipboard(long unit);
void CloseClipboard(struct CBHandle *ch);
long WriteChunkBytes(struct IFF *iff, APTR data, long size);
long ReadChunkBytes(struct IFF *iff, APTR data, size_t datasize);
long AllocReadChunkBytes(struct IFF *iff, APTR data, size_t datasize);
long EnterNextChunk(struct IFF *iff, struct ContextNode *cn);
long PushChunk(struct IFF *iff, long id, long type, long size);
long EnterChunk(struct IFF *iff, long id,long type);
long PopChunk(struct IFF *iff);
long ExitChunk(struct IFF *iff);
long SkipChunk(struct IFF *iff);
long ParseIFF(struct IFF *iff, long control);
struct ContextNode *CurrentChunk(struct IFF *iff);
#define WriteChunkData(iff, data, size) WriteChunkBytes(iff, (APTR)data, (long)size)

#define SUCCESS 0L
#define FAILED  -1L
