2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 #ifndef IFFPARSE_INTERN_H
7 #define IFFPARSE_INTERN_H
11 #include <clib/alib_protos.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/utility.h>
15 #include <proto/iffparse.h>
16 #include <libraries/iffparse.h>
17 #include <exec/memory.h>
18 #include <exec/libraries.h>
19 #include <aros/libcall.h>
21 #include <utility/hooks.h>
24 #include <aros/debug.h>
29 /* Some external stuff (iffparse_init.c) */
32 struct IFFParseBase_intern
; /* prerefrence */
34 /* Internal prototypes */
35 LONG
ReadStream (struct IFFHandle
*, APTR
, LONG
, struct IFFParseBase_intern
*);
36 LONG
ReadStreamLong (struct IFFHandle
*, APTR
, struct IFFParseBase_intern
*);
37 LONG
WriteStream (struct IFFHandle
*, APTR
, LONG
, struct IFFParseBase_intern
*);
38 LONG
WriteStreamLong (struct IFFHandle
*, APTR
, struct IFFParseBase_intern
*);
39 VOID
PurgeLCI (struct LocalContextItem
*, struct IFFParseBase_intern
*);
41 LONG
PushContextNode (struct IFFHandle
*, LONG
,LONG
, LONG
, LONG
, struct IFFParseBase_intern
*);
42 VOID
PopContextNode (struct IFFHandle
*, struct IFFParseBase_intern
*);
43 LONG
GetChunkHeader (struct IFFHandle
*, struct IFFParseBase_intern
*);
44 LONG
InvokeHandlers (struct IFFHandle
*, LONG
, LONG
, struct IFFParseBase_intern
*);
45 LONG
SeekStream (struct IFFHandle
*, LONG
, struct IFFParseBase_intern
*);
47 /* Some system entry & exit handlers (hook funcs) */
48 LONG
ExitContextFunc(struct Hook
*, APTR
, APTR
);
49 LONG
StopFunc (struct Hook
*, APTR
, APTR
);
50 LONG
PropFunc (struct Hook
*, struct IFFHandle
*, APTR
);
51 LONG
CollectionFunc (struct Hook
*, struct IFFHandle
*, APTR
);
53 /* A system purge hook for purging the LCIs installed by PropChunk and CollectionChunk */
54 ULONG
CollectionPurgeFunc (struct Hook
*, struct LocalContextItem
*, ULONG
);
55 IPTR
PropPurgeFunc (struct Hook
*, struct LocalContextItem
*, ULONG
);
57 /* Buffer functions */
58 struct BufferList
* AllocBuffer (ULONG
, struct IFFParseBase_intern
*);
59 VOID
FreeBuffer (struct BufferList
*, struct IFFParseBase_intern
*);
61 struct BufferNode
* AllocBufferNode (struct BufferList
*, struct IFFParseBase_intern
*);
63 LONG
WriteToBuffer (struct BufferList
*, UBYTE
*, LONG
, struct IFFParseBase_intern
*);
64 BOOL
SeekBuffer (struct BufferList
*, LONG
);
66 BOOL
BufferToStream (struct BufferList
*, struct IFFHandle
*, struct IFFParseBase_intern
*);
68 /* StreamHandler hooks */
70 ULONG
DOSStreamHandler (struct Hook
*, struct IFFHandle
*, struct IFFStreamCmd
*);
71 ULONG
ClipStreamHandler (struct Hook
*, struct IFFHandle
*, struct IFFStreamCmd
*);
72 ULONG
BufStreamHandler (struct Hook
*, struct IFFHandle
*, struct IFFStreamCmd
*);
74 /* Message port help functions */
76 BOOL
InitPort (struct MsgPort
*, struct Task
*, struct IFFParseBase_intern
*);
77 VOID
ClosePort (struct MsgPort
*, struct IFFParseBase_intern
*);
80 /* Buffered stream install/deinstall */
81 LONG
InitBufferedStream (struct IFFHandle
*, struct IFFParseBase_intern
*);
82 LONG
ExitBufferedStream (struct IFFHandle
*, struct IFFParseBase_intern
*);
84 /* Endian conversion */
85 LONG
SwitchIfLittleEndian(LONG
);
89 #define IFFF_NEWFILE (1L << 16)
90 #define IFFF_OPEN (1L << 19)
93 The different states the parser can be in.
94 Chose values so that the compiler easily can create a jump table
96 #define IFFSTATE_COMPOSITE 0
97 #define IFFSTATE_PUSHCHUNK 1
98 #define IFFSTATE_ATOMIC 2
99 #define IFFSTATE_SCANEXIT 3
100 #define IFFSTATE_EXIT 4
101 #define IFFSTATE_POPCHUNK 5
103 /* Size of one tile of a buffer to use in buffering of chunks */
104 #define BUFFERNODESIZE 10000
106 /* Size of buffer fake a forward seek with Read()s */
107 #define SEEKBUFSIZE 10000
110 /************************/
111 /* Internal structures */
112 /************************/
114 /* Structure for maintaing a list of buffers for buffering */
117 struct MinList bl_ListHeader
;
119 /* The size of each buffer */
120 ULONG bl_BufferNodeSize
;
122 /* The current position of the Write/Seek pointer */
125 struct BufferNode
* bl_CurrentNode
;
126 /* An offset pointer into that particular node. */
127 ULONG bl_CurrentOffset
;
129 The number of the current buffernode (the number in the list).
130 First buffenode is number 1 (not 0)
132 ULONG bl_CurrentNodeNum
;
134 /* Number of bytes written to the bufferlist */
137 /* Number of nodes in the list */
142 One node in the bufferlist.
143 Contains a pointer to the buffer - tile itself
148 struct MinNode bn_Node
;
149 UBYTE
* bn_BufferPtr
;
155 Internal version of a ContextNode. Contains a list of
158 struct IntContextNode
160 struct ContextNode CN
;
161 struct MinList cn_LCIList
;
163 /* True if this chunk is a FORM, LIST or CAT */
167 #define GetIntCN(cn) ((struct IntContextNode *)(cn))
168 #define GetCN(cn) (&GetIntCN(cn)->CN))
172 Internal version of the IffHandle data structure. Contains quite a bit
173 of useful information, eg the current context etc.
181 /* The default context node is built-in into the iffhandle */
182 struct IntContextNode iff_DefaultCN
;
184 /* A linkedlist simulated stack with context nodes */
185 struct MinList iff_CNStack
;
187 /* containd the state in which the parser currently is */
188 ULONG iff_CurrentState
;
191 The context depth at which we have started buffering.
192 0 if no buffering is needed.
194 ULONG iff_BufferStartDepth
;
196 /* Here InitIff store it's parameters */
197 struct Hook
* iff_StreamHandler
;
200 Entrys to preserve the StreamHandler, stream and the stream flags
201 whenever the buffering streamhandle is inserted
204 struct Hook
* iff_PreservedHandler
;
205 LONG iff_PreservedFlags
;
206 IPTR iff_PreservedStream
;
208 #define GetIntIH(ih) ((struct IntIFFHandle *)(ih))
209 #define GetIH(ih) (&GetIntIH(ih)->IH)
212 Internal version of the LocalContextItem structure. Contains
213 the dataSize and a Hook for purging...
216 struct IntLocalContextItem
218 struct LocalContextItem LCI
;
220 struct Hook
* lci_PurgeHook
;
221 UBYTE
* lci_UserData
;
222 ULONG lci_UserDataSize
;
225 #define GetIntLCI(lci) ((struct IntLocalContextItem *)(lci))
226 #define GetLCI(lci) (&GetIntLCI(lci)->LCI)
228 /* LocalItem data in IFFLCI_ENTRY/EXITHANDLER LCIs */
232 struct Hook
* hi_Hook
;
237 /* LocalItem data inside IFFLCI_PROP LCIs */
240 struct CollectionItem
* FirstCI
;
246 #define TopChunk( iff ) (struct ContextNode*)GetIntIH(iff)->iff_CNStack.mlh_Head
247 #define RootChunk(iff) (struct ContextNode*)GetIntIH(iff)->iff_CNStack.mlh_TailPred
249 struct IFFParseBase_intern
253 struct Hook stophook
;
254 struct Hook prophook
;
255 struct Hook collectionhook
;
257 struct Hook cliphook
;
259 struct Hook collectionpurgehook
;
260 struct Hook proppurgehook
;
261 struct Hook exitcontexthook
;
264 #define IPB(ipb) ((struct IFFParseBase_intern *)ipb)
267 #define dprintf kprintf
269 void dprintf(const char *, ...);
272 #define DEBUG_ALLOCIFF(x) ;
273 #define DEBUG_ALLOCLOCALITEM(x) ;
274 #define DEBUG_ALLOCBUFFER(x) ;
275 #define DEBUG_WRITETOBUFFER(x) ;
276 #define DEBUG_SEEKBUFFER(x) ;
277 #define DEBUG_BUFFERTOSTREAM(x) ;
278 #define DEBUG_INITBUFFEREDSTREAM(x) ;
279 #define DEBUG_EXITBUFFEREDSTREAM(x) ;
280 #define DEBUG_BUFSTREAMHANDLER(x) ;
281 #define DEBUG_DOSSTREAMHANDLER(x) ;
282 #define DEBUG_READCHUNKRECORDS(x) ;
283 #define DEBUG_WRITECHUNKRECORDS(x) ;
284 #define DEBUG_INITIFFAS(x) ;
285 #define DEBUG_INITIFF(x) ;
286 #define DEBUG_SETLOCALEITEMPURGE(x) ;
287 #define DEBUG_PROPHOOKS(x) ;
289 #define DEBUG_COLLECTIONCHUNK(x) ;
290 #define DEBUG_COLLECTIONCHUNKS(x) ;
291 #define DEBUG_FINDCOLLECTION(x) ;
292 #define DEBUG_FINDLOCALITEM(x) ;
293 #define DEBUG_FINDPROP(x) ;
294 #define DEBUG_POPCHUNK(x) ;
295 #define DEBUG_PROPCHUNK(x) ;
296 #define DEBUG_PROPCHUNKS(x) ;
297 #define DEBUG_PUSHCHUNK(x) ;
298 #define DEBUG_READCHUNKBYTES(x) ;
299 #define DEBUG_STOPCHUNK(x) ;
300 #define DEBUG_STOPCHUNKS(x) ;
301 #define DEBUG_STOPONEXIT(x) ;
302 #define DEBUG_STOREITEMINCONTEXT(x) ;
303 #define DEBUG_STORELOCALITEM(x) ;
304 #define DEBUG_WRITECHUNKBYTES(x) ;
306 #define dmkid(id) ((id) >> 24) & 0xff, ((id) >> 16) & 0xff, ((id) >> 8) & 0xff, (id) & 0xff
308 #endif /* IFFPARSE_INTERN_H */