- Documented /N/M.
[tangerine.git] / tools / dtdesc / c_iff / newchunk.c
blobddd4a12e00bc96922a43d58eefd568f855db0249
1 /*
2 * c_iff - a portable IFF-parser
4 * Copyright (C) 2000, 2001 Joerg Dietrich
6 * This is the AROS-version of c_iff.
7 * It is distributed under the AROS Public License.
8 * But I reserve the right to distribute
9 * my own version under other licenses.
13 * newchunk.c - open a new chunk
16 #include "c_iff.h"
18 /****** c_iff/NewChunk ******************************************************
20 * NAME
21 * NewChunk -- Start a new chunk
23 * SYNOPSIS
24 * Success = NewChunk( TheHandle,ID )
26 * int NewChunk( struct IFFHandle *,uint32_t )
28 * FUNCTION
29 * Starts a new chunk, trough writing the chunk-header.
31 * INPUTS
32 * TheHandle - IFFHandle to write to
33 * ID - ID of the chunk
35 * RESULT
36 * Success - TRUE when chunk-header is succesfully written,
37 * otherwise FALSE
39 * EXAMPLE
41 * NOTES
42 * Chunks startet with NewChunk() must be finished with EndChunk()
43 * to correct the internal chunk-size.
45 * BUGS
47 * SEE ALSO
48 * EndChunk()
50 *****************************************************************************
52 * Private notes:
55 int NewChunk(struct IFFHandle *TheHandle, uint32_t ID)
57 uint32_t Buffer[2];
58 struct ChunkNode *CN, *PN;
60 if(!TheHandle)
62 return(FALSE);
65 CN=(struct ChunkNode *) malloc(sizeof(struct ChunkNode));
66 if(!CN)
68 return(FALSE);
71 Buffer[0]=ID;
72 Buffer[1]=0;
74 Buffer[0]=Swap32IfLE(Buffer[0]);
75 Buffer[1]=Swap32IfLE(Buffer[1]);
77 if(!(fwrite((void *) Buffer, sizeof(uint32_t), 2, TheHandle->TheFile)==2))
79 free((void *) CN);
80 return(FALSE);
83 CN->Size=0;
84 CN->FilePos=ftell(TheHandle->TheFile);
85 CN->FilePos-=sizeof(uint32_t);
86 CN->Previous=TheHandle->LastNode;
88 PN=CN->Previous;
90 while(PN)
92 PN->Size+=2*sizeof(uint32_t);
94 PN=PN->Previous;
97 TheHandle->IFFSize+=2*sizeof(uint32_t);
98 TheHandle->LastNode=CN;
100 return(TRUE);