2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
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 /*****************************************************************************
16 #include <proto/iffparse.h>
18 AROS_LH2(LONG
, OpenIFF
,
21 AROS_LHA(struct IFFHandle
*, iff
, A0
),
22 AROS_LHA(LONG
, rwMode
, D0
),
25 struct Library
*, IFFParseBase
, 6, IFFParse
)
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).
33 iff - pointer to IFFHandle struct.
34 ewMode - IFFF_READ or IFFF_WRITE
38 error - 0 if successfull, IFFERR_#? elsewise.
41 This function tells the custom stream handler to initialize
42 by sending it a IFFCMD_INIT IFFStreamCmd.
53 *****************************************************************************/
56 AROS_LIBBASE_EXT_DECL(struct Library
*,IFFParseBase
)
58 struct IFFStreamCmd cmd
;
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
);
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 ? */
93 /* We have now entried the chunk */
94 D(bug("entered the chunk\n"));
95 GetIntIH(iff
)->iff_CurrentState
= IFFSTATE_COMPOSITE
;
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
);
113 D(bug("OpenIFF: not an IFF header, pop the context node\n"));
115 /* Pop the contextnode */
116 PopContextNode(iff
, IPB(IFFParseBase
));
121 if (err
== IFFERR_MANGLED
)
124 D(bug("openiff error: IFFERR_MANGLED\n"));
127 /* Fail. We should send CLEANUP to the stream */
128 cmd
.sc_Command
= IFFCMD_CLEANUP
;
131 GetIntIH(iff
)->iff_StreamHandler
,
138 #endif /* USE_IFFVALIDITYCHECK */
140 iff
->iff_Flags
&= ~IFFF_RWBITS
;
141 iff
->iff_Flags
|= (rwMode
| IFFF_OPEN
| IFFF_NEWFILE
);
147 D(bug("openiff: return %d\n", err
));