Improvements to comments etc.
[AROS.git] / tools / dtdesc / c_iff / newsubform.c
blob583edee18f6968cc77c1ccdfa5b9f221dee1c197
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/NewSubFORM ****************************************************
20 * NAME
21 * NewSubFORM -- Start a new sub-FORM
23 * SYNOPSIS
24 * Success = NewSubFORM( TheHandle,Type )
26 * int NewSubFORM( struct IFFHandle *,uint32_t )
28 * FUNCTION
29 * Some IFF's, e.g. ANIM, have cascading FORM's, this means one or
30 * more FORM's inside the main-FORM.
31 * With NewSubFORM() you can start such a child-FORM.
33 * INPUTS
34 * TheHandle - IFFHandle to write to
35 * Type - type of the sub-FORM
37 * RESULT
38 * Success - TRUE when the FORM-header is successfully written,
39 * otherwise FALSE
41 * EXAMPLE
43 * NOTES
44 * Sub-FORM's startet with NewSubFORM() must be finished
45 * with EndChunk() to correct the internal size.
47 * BUGS
49 * SEE ALSO
50 * EndChunk()
52 *****************************************************************************
54 * Private notes:
57 int NewSubFORM(struct IFFHandle *TheHandle, uint32_t Type)
59 uint32_t Buffer[3];
60 struct ChunkNode *CN, *PN;
62 if(!TheHandle)
64 return(FALSE);
67 CN=(struct ChunkNode *) malloc(sizeof(struct ChunkNode));
68 if(!CN)
70 return(FALSE);
73 Buffer[0]=ID_FORM;
74 Buffer[1]=0;
75 Buffer[2]=Type;
77 Buffer[0]=Swap32IfLE(Buffer[0]);
78 Buffer[1]=Swap32IfLE(Buffer[1]);
79 Buffer[2]=Swap32IfLE(Buffer[2]);
81 if(!(fwrite((void *) Buffer, sizeof(uint32_t), 3, TheHandle->TheFile)==3))
83 free((void *) CN);
84 return(FALSE);
87 CN->Size=sizeof(uint32_t);
88 CN->FilePos=ftell(TheHandle->TheFile);
89 CN->FilePos-=8;
90 CN->Previous=TheHandle->LastNode;
92 PN=CN->Previous;
94 while(PN)
96 PN->Size+=3*sizeof(uint32_t);
98 PN=PN->Previous;
101 TheHandle->IFFSize+=3*sizeof(uint32_t);
102 TheHandle->LastNode=CN;
104 return(TRUE);