2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
6 #include "iffparse_intern.h"
8 /*****************************************************************************
11 #include <proto/iffparse.h>
13 AROS_LH1(LONG
, PopChunk
,
16 AROS_LHA(struct IFFHandle
*, iff
, A0
),
19 struct Library
*, IFFParseBase
, 15, IFFParse
)
22 Pops a context node of the context stack. Usually called
23 in write mode to signal the end of a chunk.
27 iff - pointer to IFFHandle struct.
30 error - 0 if successful, IFFERR_#? otherwise.
43 Frees a contextnode an all its related LCIs and removes it from the stack-list
44 If we are in write mode, we will update the cn_Size in the chunk according
45 t cn_Scan, and we will also insert an align byte if necessary
48 If the stream was of PushChunked() as IFFSIZE_UNKNOWN, we have to seek backwards
49 and write the correct size.
50 Since non RSEEK streams are automagically buffered by
51 WriteStream, we don't have to fiddle with it here.
52 However if the stream is buffered, we MUST see if we are
53 about to pop the chunk that started the Buffering (in PushChunk)
55 *****************************************************************************/
59 struct ContextNode
*cn
;
67 DEBUG_POPCHUNK(dprintf("PopChunk: iff 0x%lx\n", iff
));
69 /* Get current chunk */
72 /* Is the IFFHandle opened in Read or Write mode ? */
73 if (iff
->iff_Flags
& IFFF_WRITE
)
75 /* Write mode. We should update cn_Size *INSIDE the stream,
76 if the chunk was pushed with IFFSIZE_UNKNOWN */
78 if (cn
->cn_Size
== IFFSIZE_UNKNOWN
)
84 /* minus is for seeking backwards. Remember: evt. chunk types
85 for composite chunks are allready in cn_Scan */
86 - ( cn
->cn_Scan
+ sizeof(ULONG
) ),
90 if (err
) return (err
);
94 /* Write the chunk size */
102 if (err
< 0) return (err
);
104 /* Seek towards end of chunk again */
112 if (err
) return (err
);
115 else /* IFFSIZE known at PushChunk() time */
119 /* Write a pad byte if chunk is not word-aligned */
130 if (err
< 0) return (err
);
136 GetIntIH(iff
)->iff_BufferStartDepth
141 /* a routine that writes the buffer to stream and reinstallss the old streamhandler */
143 err
= ExitBufferedStream(iff
, IPB(IFFParseBase
));
144 if (err
) return (err
);
149 /* Actually pop the top context-node. (Done for both handles in Read & Write mode) */
151 PopContextNode(iff
, IPB(IFFParseBase
));
153 /* stegerg: is this okay!? */
155 if (iff
->iff_Flags
& IFFF_WRITE
)
159 /* Might work without this check, because there seems to be always at
160 least one contextnode --> see AllocIFF) */
161 if (cn
->cn_Node
.mln_Succ
)
163 cn
->cn_Scan
+= size
+ sizeof(ULONG
) + sizeof(ULONG
);