- Documented /N/M.
[tangerine.git] / tools / dtdesc / c_iff / example.c
blobc7150e2141073c76a1b6e43186deac38eb9bd113
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 * example.c - shows how to use c_iff
17 * includes
20 #include <stdio.h>
21 #include <string.h>
24 * include c_iff.h when you want to use c_iff
27 #include "c_iff.h"
30 * prototypes
33 void PrintID(uint32_t ID);
36 * the main-program
39 int main(int argc, char **argv)
42 * struct IFFHandle is the basic struct of c_iff.
44 struct IFFHandle *IH;
46 if(!(argc==2))
48 fprintf(stderr, "usage: %s IFF-file\n", argv[0]);
50 return(0);
54 * OpenIFF() is used to open an existing IFF
56 IH=OpenIFF(argv[1]);
57 if(!IH)
59 return(0);
62 printf("Type: ");
63 PrintID(IH->IFFType);
64 printf("\n");
66 while(TRUE)
69 * Read the header of the next chunk.
71 if(!ReadChunkHeader(IH))
73 break;
76 printf(" Chunk: ");
77 PrintID(IH->ChunkID);
78 printf("\n");
81 * If you are not interessted in the Data, skip it with SkipChunkData() .
82 * If you need the Data use ReadChunkData() .
84 SkipChunkData(IH);
88 * Alway close an IFF with CloseIFF() !
90 CloseIFF(IH);
93 * Use NewIFF() to open a new IFF for writing.
95 IH=NewIFF("test1.iff", MAKE_ID('A','N','I','M'));
96 if(!IH)
98 return(0);
102 * Open a new SubFORM, an IFF inside an IFF.
104 if(NewSubFORM(IH, MAKE_ID('I','L','B','M')))
107 * Open a new Chunk.
109 if(NewChunk(IH, MAKE_ID('F','V','E','R')))
112 * Write some data to the chunk.
113 * The chunk-sizes are automatically fixed.
115 WriteChunkData(IH, "$VER: test1 1.10", 17);
118 * You must always end a chunk with EndChunk() .
120 EndChunk(IH);
123 if(NewChunk(IH, MAKE_ID('A','U','T','H')))
125 WriteChunkData(IH, "Jörg Dietrich", 13);
126 EndChunk(IH);
130 * EndChunk is used too, to end a SubFORM.
132 EndChunk(IH);
136 * And always close your IFF.
138 CloseIFF(IH);
139 return(0);
142 void PrintID(uint32_t ID)
144 char Buffer[5];
146 Buffer[0]=(ID&0xFF000000)>>24;
147 Buffer[1]=(ID&0xFF0000) >>16;
148 Buffer[2]=(ID&0xFF00) >> 8;
149 Buffer[3]=(ID&0xFF);
150 Buffer[4]='\0';
152 printf("%s", Buffer);