2 Copyright © 1995-2016, 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 successful, IFFERR_#? elsewise.
41 This function tells the custom stream handler to initialize
42 by sending it a IFFCMD_INIT IFFStreamCmd.
53 *****************************************************************************/
57 struct IFFStreamCmd cmd
;
61 D(bug("openiff error: IFFERR_NOMEM\n"));
62 return (IFFERR_NOMEM
);
65 /* Check that a valid StreamHandler Hook has been supplied */
66 if (!( GetIntIH(iff
)->iff_StreamHandler
) )
68 D(bug("openiff error: IFFERR_NOHOOK\n"));
69 return (IFFERR_NOHOOK
);
72 /* Tell the custom stream to initialize itself */
74 cmd
.sc_Command
= IFFCMD_INIT
;
75 err
= CallHookPkt (GetIntIH(iff
)->iff_StreamHandler
, iff
, &cmd
);
79 #if USE_IFFVALIDITYCHECK
80 /* If we are opend in read mode we should test if we have a valid IFF-File */
81 if (rwMode
== IFFF_READ
&& iff
->iff_Stream
)
83 struct ContextNode
*cn
;
85 D(bug("testing if it's a valid IFF file\n"));
86 /* Get header of iff-stream */
87 err
= GetChunkHeader(iff
, IPB(IFFParseBase
));
89 /* Valid IFF header ? */
92 /* We have now entried the chunk */
93 D(bug("entered the chunk\n"));
94 GetIntIH(iff
)->iff_CurrentState
= IFFSTATE_COMPOSITE
;
98 /* We must see if we have a IFF header ("FORM", "CAT" or "LIST") */
99 if (GetIntCN(cn
)->cn_Composite
)
101 D(bug("an iff header\n"));
102 /* Everything went OK */
103 /* Set the acess mode, and mark the stream as opened */
104 iff
->iff_Flags
&= ~IFFF_RWBITS
;
105 iff
->iff_Flags
|= (rwMode
| IFFF_OPEN
| IFFF_NEWFILE
);
112 D(bug("OpenIFF: not an IFF header, pop the context node\n"));
114 /* Pop the contextnode */
115 PopContextNode(iff
, IPB(IFFParseBase
));
120 if (err
== IFFERR_MANGLED
)
123 D(bug("openiff error: IFFERR_MANGLED\n"));
126 /* Fail. We should send CLEANUP to the stream */
127 cmd
.sc_Command
= IFFCMD_CLEANUP
;
130 GetIntIH(iff
)->iff_StreamHandler
,
137 #endif /* USE_IFFVALIDITYCHECK */
139 iff
->iff_Flags
&= ~IFFF_RWBITS
;
140 iff
->iff_Flags
|= (rwMode
| IFFF_OPEN
| IFFF_NEWFILE
);
146 D(bug("openiff: return %d\n", err
));