iffparse
Index
struct IFFHandle * AllocIFF();
Allocates an IFFHandle struct.
An unitialized IFFHandle structure.
The default context-node is created in AllocIFF() and persists until
FreeIFF().
struct LocalContextItem * AllocLocalItem(
LONG type,
LONG id,
LONG ident,
ULONG dataSize );
Allocates and initializes a LocalContextItem structure. It also allocates
dataSize user data. User data can be accesseed via LocalItemData function.
This is the only way to allocate such a item, since the item contains private
fields. Of course programmers should assume NOTHING about this private
fields.
type, id - Longword identifications values.
ident - Longword identifier for class of item.
dataSize - Size of a user data area that will be allocated by this funcyion.
item - A initialized LocalContextItem structure.
Changed dataSize parameter to ULONG, negative-sized memory allocations are undefined.
void CloseClipboard(
struct ClipboardHandle * clipHandle );
Closes the clipboard.device and frees the ClipboardHandle
clip - pointer to a ClipboardHandle struct created with OpenClipboard.
void CloseIFF(
struct IFFHandle * iff );
Completes a read or write session by closing the IFF handle.
The IFFHandle struct is ready for reuse in another session,
it's just to open it again with OpenIFF(). This function
also automatically cleans up if a read or write fails halfway through.
iff - Pointer to an IFFhandle struct previously opened with OpenIFF()
This function tells the custom stream handler to clean up
by sending it a IFFCMD_CLEANUP IFFStreamCmd.
Errors during writing of any of the remaining chunks are just
ignored and both the faulty and all following chunks are not written.
LONG CollectionChunk(
struct IFFHandle * iff,
LONG type,
LONG id );
Installs an entry handler with the given type and id, so that
chunks encountered with the same type and id will be stored.
This is quite like PropChunk(), but CollectionChunk() will
store the contents of multiple chunks with the same type and id.
To retrieve the stored collection of chunks one uses FindCollection().
Remember: the collection is only valid inside the current property scope.
iff - Pointer to IFFHandle struct. (does not need to be open).
type - IFF chunk type declarator for chunk to collect.
id - IFF chunk id identifier for chunk to collect.
error - 0 if successful. IFFERR_#? otherwise.
LONG CollectionChunks(
struct IFFHandle * iff,
const LONG * propArray,
LONG numPairs );
Does multiple CollectionChunk() calls on the supplied list.
An easy way to install several collction chunks.
iff - pointer to an IFFHandle struct.
propArray - pointer to an array of longword chunk types and identifiers.
numPairs - number of type/id pairs in the propArray.
error - 0 if successful, IFFERR_#? otherwise.
struct ContextNode * CurrentChunk(
struct IFFHandle * iff );
Returns the top context node for the give IFFHandle struct.
The top contexte is the node most recently pushed onto the
context stack
iff - pointer to IFFHandle struct.
top - Pointer to top contextnode or NULL if none.
LONG EntryHandler(
struct IFFHandle * iff,
LONG type,
LONG id,
LONG position,
struct Hook * handler,
APTR object );
Installs an entry handler for a specific chunk type
that wil be called whenever a chunk of that type is pushed on the contextstack
via ParseIFF().
iff - pointer to an iffhandle struct.
type - type code for the chunk to handle. (ex: "ILBM").
id - ID code for the chunk to handle. (ex: "CMAP")
position - position of localcontextitem. See StoreLocalItem for
more info.
handler - an initialised Hook structure for the handler function.
object - pointer to some kind of object that will be passed to
your handler function.
error - 0 If successful, IFFERR_#? otherwise.
LONG ExitHandler(
struct IFFHandle * iff,
LONG type,
LONG id,
LONG position,
struct Hook * handler,
APTR object );
Installs an exit handler for a specific chunk type
that wil be called whenever a chunk of that type is popped off the contextstack
via ParseIFF().
iff - pointer to an iffhandle struct.
type - type code for the chunk to handle. (ex: "ILBM").
id - ID code for the chunk to handle. (ex: "CMAP")
position - position of localcontextitem. See StoreLocalItem for
more info.
handler - an initialised Hook structure for the handler function.
object - pointer to some kind of object that will be passed to
your handler function.
error - 0 If successful, IFFERR_#? otherwise.
struct CollectionItem * FindCollection(
struct IFFHandle * iff,
LONG type,
LONG id );
Returns a pointer to a list of CollectionItems the installed
CollectionChunk of that type and ID.
iff - pointer to an IFFHandle struct.
type - type code to search for.
id - id code to search for.
ci - pointer to the last collection chunk encountered
with pointers to previous ones.
struct LocalContextItem * FindLocalItem(
struct IFFHandle * iff,
LONG type,
LONG id,
LONG ident );
Goes through the whole context node stack starting at the top
searching the contecnodes for attached LocalContextItems with the
specified type, id and ident codes.
iff - pointer to an IFFHandle struct.
type - type code for item to find.
id - identifier code for item to find.
ident - ident code for the class of context item to find.
lci - pointer to a local context item if found, or NULL if
none is found.
struct StoredProperty * FindProp(
struct IFFHandle * iff,
LONG type,
LONG id );
Searches for a StoredProperty that is valid in the given context.
Property chunks are automatically stored by ParseIFF() when pre-declared
by PropChunk() or PropChunks(). The returned storedproperty contains
a pointer to the data in the chunk.
iff - a pointer to a an IFFHandle struct.
type - type code of property to search for.
id - id code of property to search for.
sp - pointer to a storedproperty if found, NULL if none are found.
struct ContextNode * FindPropContext(
struct IFFHandle * iff );
Finds the proper context in which to store a property.
If we have installed a property entry handler via PropChunk()
and such a property chunk (for example id is "CMAP" and type is "ILBM"
inside a form, then the storedproperty will be stored in the enclosing
FORM chink. If the chunk was inside a PROP chunk inside a LIST, then
the storedproperty would be installed in the LIST context.
iff - pointer to IFFHandle struct.
cn - pointer to contextnode where the property might be installed, or
NULL if no such context exists.
This function is most for internal use.
void FreeIFF(
struct IFFHandle * iff );
Frees an IFFHandle struct previously allocated by AllocIFF.
iff - pointer to an IFFHandle struct.
void FreeLocalItem(
struct LocalContextItem * localItem );
Frees a local context item previously allocated by AllocLocalItem.
This functioned should always be calles by custom LCI purge hooks.
localItem - pointer to LocalContextItem struct.
Determines whether an ID is valid according to the IFF specification.
id - An IFF chunk ID to be tested.
TRUE if valid.
FALSE otherwise.
Assumes input to be in local byte order.
LONG GoodType(
LONG type );
Determines whether a IFF chunk type is valid according to the IFF specification.
type - An IFF chunk type to be tested.
TRUE - type is valid.
FALSE - otherwise.
Assumes the input type to be in local byte order.
STRPTR IDtoStr(
LONG id,
STRPTR buf );
id - pointer to an IFF chunk identfication code.
buf - buffer into which the id will be stored. Should at least be 5 bytes.
buf - pointer to the supplied buffer.
// Print the ID of the current contextnode
UBYTE buf[5];
struct ContextNode *cn;
if (cn = CurrentChunk(iff)
printf
(
"ID of current chunk: %s\n",
IDtoStr(cn->cn_ID)
);
Assumes that the supplied ID is stored in local byte order.
void InitIFF(
struct IFFHandle * iff,
LONG flags,
struct Hook * streamHook );
Initializes an IFFHandle with a custom stream handler and
flags describing seekability of the stream.
iff - pointer to IFFHandle struct.
flags - stream I/O flags for the IFFHandle.
streamHook - pointer to a Hook structure initialized with the streamhandler
to be called.
void InitIFFasClip(
struct IFFHandle * iff );
Initializes the given IFFHandle to be a clipboard stream. It installs a
"custom" stream handler (via InitIFF) to handle clipboard streams.
The iff_Stream field of the iffhandle will still need
to be initializes with a ClipboardHandle struct returned from
OpenClipboard().
iff - pointer to an IFFHandle struct.
void InitIFFasDOS(
struct IFFHandle * iff );
Initializes the given IFFHandle to be a DOS stream. It installs a
"custom" stream handler (via InitIFF) to handle DOS streams.
The iff_Stream field of the iffhandle will still need
to be initializes with a filehandle struct as returned from
dos.library/Open(). The iff_Flags may be changed to
change the seekability of the stream after this function is called,
but before OpenIFF() is called. Seekability for dos files
default to IFFF_RSEEK (random seekable).
iff - pointer to an IFFHandle struct.
APTR LocalItemData(
struct LocalContextItem * localItem );
Returns a pointer to the userdata allocated in AllocLocalItem.
This function returns NULL for an input of NULL.
localItem - pointer to a LocalContextItem struct or NULL.
data - pointer to user data or NULL.
struct ClipboardHandle * OpenClipboard(
LONG unitNumber );
Opens the clipboard.device with the specified unit.
Allocates and initializes a ClipboardHandle struct which should
be put into the iff_Stream field of the IFFHandle when the
handle is initialized with InitIFFasClip().
unitNumber - a clipboard device unit number (usually PRIMARY_CLIP).
ch - pointer to ClipboardHandle struct or NULL if unsuccessful.
LONG OpenIFF(
struct IFFHandle * iff,
LONG rwMode );
Initializes an IFFHandle struct for a new session of reading or
writing. The direction of the I/O is determined by the rwMode flags
supplied (IFFF_READ or IFFF_WRITE).
iff - pointer to IFFHandle struct.
ewMode - IFFF_READ or IFFF_WRITE
error - 0 if successful, IFFERR_#? elsewise.
This function tells the custom stream handler to initialize
by sending it a IFFCMD_INIT IFFStreamCmd.
struct ContextNode * ParentChunk(
struct ContextNode * contextNode );
Returns a pointer to the parent context node to the given
one on the context node stack. The parent context node
represents the chunk enclosing the chunk given.
This can be use together with CurrentChunk() to iterate the
context node stack top-down.
contextNode - pointer to a context node.
parent - pointer to the parent context node or NULL if none.
LONG ParseIFF(
struct IFFHandle * iff,
LONG mode );
This function is the parser itself. It has three control modes.
IFFPARSE_SCAN - the parser will go through the file invoking
entry and exit handlers on its way.
When it returns it might be for 3 different reasons:
- It invoked a Stop entry/exit handler ( Installed by StopChunk[s] or
StopOnExit )
- An error occured.
(return value will be negative.)
- The parser reached EOF and returns IFFERR_EOF.
IFFPARSE_STEP - The parser steps through the file, returning to the
user each time it enters (returns NULL) and each time it exits
(return (IFFERR_EOC) a chunk.
It will also invoke entry/exit - handlers.
IFFPARSE_RAWSTEP - same as IFFPARSE_STEP except that in this mode
the parse won't invoke any handlers.
iff - pointer to IFFHandle struct.
mode - IFFPARSE_SCAN, IFFPARSE_STEP or IFFPARSE_RAWSTEP.
0 if successful or IFFERR_#?
LONG PopChunk(
struct IFFHandle * iff );
Pops a context node of the context stack. Usually called
in write mode to signal the end of a chunk.
iff - pointer to IFFHandle struct.
error - 0 if successful, IFFERR_#? otherwise.
LONG PropChunk(
struct IFFHandle * iff,
LONG type,
LONG id );
Installs an entry handler for chunks with the given type and id.
When such chunk is encoutered, the entry handler will insert
a StoredProperty in the proper context.
A stored property chunk returned by FindProp() will be the valid property
for the current context.
iff - pointer to IFFHandle struct.
type - type code for chunk to declare.
id - identifier for chunk to declare.
error - 0 if successful, IFFERR_#? otherwise.
LONG PropChunks(
struct IFFHandle * iff,
const LONG * propArray,
LONG numPairs );
Does multiple PropChunk() calls on the supplied list.
An easy way to install several prop chunk handlers
iff - pointer to an IFFHandle struct.
propArray - pointer to an array of longword chunk types and identifiers.
numPairs - number of type/id pairs in the propArray.
error - 0 if successful, IFFERR_#? otherwise.
LONG PushChunk(
struct IFFHandle * iff,
LONG type,
LONG id,
LONG size );
Pushes a new context node onto the context stack. Usually used in write mode.
In write mode the contextnode will be pushed with the given parameters.
In Read mode the type, id and size will be read from the installed stream.
Note that IFFSIZE_UNKNOW can be given for size in write mode. In that case,
the size of will not be known until you do a PopChunk(). PopChunk()
will then seek back in the stream and write the correct size.
iff - pointer to IFFHandle struct.
type - chunk type specifier.
id - chunk identifier.
size - size of the new chunk. May be IFFSIZE_UNKNOWN.
error - 0 if successful, IFFERR_#? otherwise.
LONG ReadChunkBytes(
struct IFFHandle * iff,
APTR buf,
LONG numBytes );
Read a number of bytes from the current chunk into a buffer.
Attempts to read past the end of the chunk will be truncated.
iff - pointer to IFFHandle struct.
buf - pointer to a buffer into which the data will be placed.
numBtes - number of bytes to read.
actual - (positive) the actual number of bytes read.
(negative) IFFERR_#? error code if not successful.
LONG ReadChunkRecords(
struct IFFHandle * iff,
APTR buf,
LONG bytesPerRecord,
LONG numRecords );
Read a number of records with the given size from the current chunk
into a buffer. Attempts to read past the end of the chunk will be truncated.
iff - pointer to IFFHandle struct.
buf - pointer to a buffer into which the data will be placed.
bytesPerRecord - number of bytes per record.
numRecords - number of records to read.
actual - (positive) the actual number of whole records read.
(negative) IFFERR_#? error code if not successful.
void SetLocalItemPurge(
struct LocalContextItem * localItem,
struct Hook * purgeHook );
Inserts a custom purge hook for the given local context item.
The purge hook will be freed when the system wants to delete a local
context item.
localItem - pointer to a local context item.
purgeHook - pointer to a hook sructure initialized with the purge function.
The purgehook must call FreeLocalItem() on the local context item after
doing its own resource freeing.
LONG StopChunk(
struct IFFHandle * iff,
LONG type,
LONG id );
Inserts an entry handler for the given type and id, that will cause the parser
to stop when such a chunk is entered.
iff - Pointer to IFFHandle struct. (does not need to be open).
type - IFF chunk type declarator for chunk to stop at.
id - IFF chunk id identifier for chunk to stop at.
error - 0 if successful, IFFERR_#? otherwise.
LONG StopChunks(
struct IFFHandle * iff,
const LONG * propArray,
LONG numPairs );
Declares multiple stop chunks from th typ/id pairs supplied.
iff - pointer to an IFFHandle struct.
propArray - pointer to an array of longword chunk types and identifiers.
numPairs - number of type/id pairs in the propArray.
error - 0 if successful, IFFERR_#? otherwise.
LONG StopOnExit(
struct IFFHandle * iff,
LONG type,
LONG id );
Inserts an exit handler for the given type and id, that will cause the parser
to stop when such a chunk is left.
iff - Pointer to IFFHandle struct. (does not need to be open).
type - IFF chunk type declarator for chunk to stop at.
id - IFF chunk id identifier for chunk to stop at.
error - 0 if successful, IFFERR_#? otherwise.
void StoreItemInContext(
struct IFFHandle * iff,
struct LocalContextItem * localItem,
struct ContextNode * contextNode );
Stores the given local context item into the given context node.
If a LCI with the some id, type and class identifier allready exists
in the context node, the old one will be purged, and the new one
inserted.
iff - pointer to IFFHandle struct.
localItem - pointer to LCI to install.
contextNode - pointer to the context node in which the LCI will be stored.
LONG StoreLocalItem(
struct IFFHandle * iff,
struct LocalContextItem * localItem,
LONG position );
Stores the given local context item in a context node.
Which context node this is depends on the value of the position
argument:
IFFSLI_ROOT - insert into the default contextnode.
IFFSLI_PROP - insert into the node returned by FindPropContext().
IFFSLI_TOP - insert item into the current contextnode.
iff - pointer to IFFHandle struct.
localItem - pointer to local context item.
position - IFFSLI_ROOT, IFFSLI_PROP or IFFSLI_TOP.
error - 0 if successful, IFFERR_#? otherwise.
LONG WriteChunkBytes(
struct IFFHandle * iff,
APTR buf,
LONG numBytes );
Writes given number of bytes in the supplied buffer into the
current chunk. Attempts to write past the endo of the chunk will
be truncated.
iff - pointer to IFFHandle struct.
buf - buffer with data to write.
numBytes - number of bytes to write.
actual - (positive) number of bytes actually written.
(negative) IFFERR_#? indicating unsuccessful write.
LONG WriteChunkRecords(
struct IFFHandle * iff,
APTR buf,
LONG bytesPerRecord,
LONG numRecords );
Write numRecods records of bytesPerRecord bytes to the current chunk.
Attempts to write past the end of the chunk will be truncated.
iff - pointer to IFFHandle struct.
buf - pointer to a buffer containig the data to be written.
bytesPerRecord - number of bytes per record.
numRecords - number of records to write.
actual - (positive) the actual number of whole records written.
(negative) IFFERR_#? error code if not successful.
|
|