New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / libs / iffparse / openiff.c
blobc841b14f195bcbae249549b69507efe53160ce95
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
8 #include "iffparse_intern.h"
10 /* NOTE: Original iffparse.library doesn't have this check here. - Piru */
11 #define USE_IFFVALIDITYCHECK 1
13 /*****************************************************************************
15 NAME */
16 #include <proto/iffparse.h>
18 AROS_LH2(LONG, OpenIFF,
20 /* SYNOPSIS */
21 AROS_LHA(struct IFFHandle *, iff, A0),
22 AROS_LHA(LONG , rwMode, D0),
24 /* LOCATION */
25 struct Library *, IFFParseBase, 6, IFFParse)
27 /* FUNCTION
28 Initializes an IFFHandle struct for a new session of reading or
29 writing. The direction of the I/O is determined by the rwMode flags
30 supplied (IFFF_READ or IFFF_WRITE).
32 INPUTS
33 iff - pointer to IFFHandle struct.
34 ewMode - IFFF_READ or IFFF_WRITE
37 RESULT
38 error - 0 if successfull, IFFERR_#? elsewise.
40 NOTES
41 This function tells the custom stream handler to initialize
42 by sending it a IFFCMD_INIT IFFStreamCmd.
44 EXAMPLE
46 BUGS
48 SEE ALSO
49 CloseIFF(), InitIFF()
51 INTERNALS
53 *****************************************************************************/
55 AROS_LIBFUNC_INIT
56 AROS_LIBBASE_EXT_DECL(struct Library *,IFFParseBase)
57 LONG err;
58 struct IFFStreamCmd cmd;
60 if (iff == NULL)
62 D(bug("openiff error: IFFERR_NOMEM\n"));
63 return (IFFERR_NOMEM);
66 /* Check that a valid StreamHandler Hook has been supplied */
67 if (!( GetIntIH(iff)->iff_StreamHandler) )
69 D(bug("openiff error: IFFERR_NOHOOK\n"));
70 return (IFFERR_NOHOOK);
73 /* Tell the custom stream to initialize itself */
75 cmd.sc_Command = IFFCMD_INIT;
76 err = CallHookPkt (GetIntIH(iff)->iff_StreamHandler, iff, &cmd);
78 if (!err)
80 #if USE_IFFVALIDITYCHECK
81 /* If we are opend in read mode we should test if we have a valid IFF-File */
82 if (rwMode == IFFF_READ && iff->iff_Stream)
84 struct ContextNode *cn;
86 D(bug("testing if it's a valid IFF file\n"));
87 /* Get header of iff-stream */
88 err = GetChunkHeader(iff, IPB(IFFParseBase));
90 /* Valid IFF header ? */
91 if (!err)
93 /* We have now entried the chunk */
94 D(bug("entered the chunk\n"));
95 GetIntIH(iff)->iff_CurrentState = IFFSTATE_COMPOSITE;
97 cn = TopChunk(iff);
99 /* We must see if we have a IFF header ("FORM", "CAT" or "LIST") */
100 if (GetIntCN(cn)->cn_Composite)
102 D(bug("an iff header\n"));
103 /* Everything went OK */
104 /* Set the acess mode, and mark the stream as opened */
105 iff->iff_Flags &= ~IFFF_RWBITS;
106 iff->iff_Flags |= (rwMode | IFFF_OPEN | IFFF_NEWFILE);
108 err = 0L;
110 else
112 err = IFFERR_NOTIFF;
113 D(bug("OpenIFF: not an IFF header, pop the context node\n"));
115 /* Pop the contextnode */
116 PopContextNode(iff, IPB(IFFParseBase));
119 else
121 if (err == IFFERR_MANGLED)
123 err = IFFERR_NOTIFF;
124 D(bug("openiff error: IFFERR_MANGLED\n"));
127 /* Fail. We should send CLEANUP to the stream */
128 cmd.sc_Command = IFFCMD_CLEANUP;
129 err = CallHookPkt
131 GetIntIH(iff)->iff_StreamHandler,
132 iff,
133 &cmd
136 } /* IFFF_READ */
137 else
138 #endif /* USE_IFFVALIDITYCHECK */
140 iff->iff_Flags &= ~IFFF_RWBITS;
141 iff->iff_Flags |= (rwMode | IFFF_OPEN | IFFF_NEWFILE);
142 err = 0L;
145 } /* if (!err) */
147 D(bug("openiff: return %d\n", err));
148 return (err);
149 AROS_LIBFUNC_EXIT
150 } /* OpenIFF */