5 * c_iff - a portable IFF-parser
7 * Copyright (C) 2000, 2001 Joerg Dietrich
9 * This is the AROS-version of c_iff.
10 * It is distributed under the AROS Public License.
11 * But I reserve the right to distribute
12 * my own version under other licenses.
16 * c_iff.h - the public headerfile
24 * Why are TRUE and FALSE not defined in a standard C header?!
41 * Do you have a big-endain machine?
45 #if defined amiga || defined __PPC__
46 #define C_IFF_BIG_ENDIAN
48 #undef C_IFF_BIG_ENDIAN
53 * Always swap shorts and ints before you write to
54 * or after you read from IFFs.
57 #ifdef C_IFF_BIG_ENDIAN
59 #define Swap16IfLE(x) (x)
61 #define Swap32IfLE(x) (x)
63 #else /* C_IFF_BIG_ENDIAN */
65 #define Swap16IfLE(x) (((((unsigned short) x) & 0xFF00) >> 8) | ((((unsigned short) x) & 0xFF) << 8))
67 #define Swap32IfLE(x) (((((unsigned int) x) & 0xFF000000) >> 24) | \
68 ((((unsigned int) x) & 0xFF0000) >> 8) | \
69 ((((unsigned int) x) & 0xFF00) << 8) | \
70 ((((unsigned int) x) & 0xFF) << 24))
73 #endif /* C_IFF_BIG_ENDIAN */
76 * macro to create an IFF-ID.
79 #define MAKE_ID(a,b,c,d) (((a)<<24) | ((b)<<16) | ((c)<<8) | ((d)))
82 * Some predefined IDs.
85 #define ID_FORM MAKE_ID('F','O','R','M')
88 * This is the invalid ID.
91 #define INVALID_ID (0)
105 * Struct to chain the open chunks together.
110 struct ChunkNode
*Previous
; /* the previous chunk */
111 long Size
; /* size of the chunk */
112 long FilePos
; /* position of the size-uint32_t in the file */
116 * struct IFFHandle, the center of c_iff
121 FILE *TheFile
; /* filehandle of the IFF */
122 uint32_t IFFType
; /* type of the IFF */
123 uint32_t ChunkID
; /* chunk-ID of the current chunk */
124 long BytesLeftInChunk
; /* byte-counter for reading*/
125 int NewIFF
; /* marker for a IFF for writing */
126 long IFFSize
; /* size of the new IFF */
127 struct ChunkNode
*LastNode
; /* the current chunk */
134 extern struct IFFHandle
*OpenIFF(char *Name
);
135 extern void CloseIFF(struct IFFHandle
*TheHandle
);
136 extern int CheckIFF(struct IFFHandle
*TheHandle
);
137 extern int ReadChunkHeader(struct IFFHandle
*TheHandle
);
138 extern int SkipChunkData(struct IFFHandle
*TheHandle
);
139 extern long ReadChunkData(struct IFFHandle
*TheHandle
,
143 extern struct IFFHandle
*NewIFF(char *Name
, uint32_t IFFType
);
144 extern int NewChunk(struct IFFHandle
*TheHandle
, uint32_t ID
);
145 extern int NewSubFORM(struct IFFHandle
*TheHandle
, uint32_t Type
);
146 extern void EndChunk(struct IFFHandle
*TheHandle
);
147 extern long WriteChunkData(struct IFFHandle
*TheHandle
,
151 extern void FixIFFSize(struct IFFHandle
*TheHandle
);
152 extern size_t FileSize(FILE *TheFile
);