rename from .c to .cpp, and updated 23 year old IFF source code (1985)

This commit is contained in:
erwin.coumans
2008-10-26 23:47:35 +00:00
parent 2a721c7489
commit 14ba3eaff7
3 changed files with 128 additions and 126 deletions

View File

@@ -55,7 +55,8 @@ extern IFFP GetForm(GroupContext*);
extern IFFP GetProp(GroupContext*); extern IFFP GetProp(GroupContext*);
extern IFFP GetCat (GroupContext*); extern IFFP GetCat (GroupContext*);
void IFFCheck(name) char *name; { void IFFCheck(char *name)
{
IFFP iffp; IFFP iffp;
BPTR file = fopen(name,"rb");//Open(name, MODE_OLDFILE); BPTR file = fopen(name,"rb");//Open(name, MODE_OLDFILE);
Frame frame; Frame frame;
@@ -87,16 +88,14 @@ void main(int argc, char **argv)
/* ---------- Put... ---------------------------------------------------*/ /* ---------- Put... ---------------------------------------------------*/
PutLevels(count) void PutLevels(int count)
int count;
{ {
for ( ; count > 0; --count) { for ( ; count > 0; --count) {
printf("."); printf(".");
} }
} }
PutID(id) void PutID(int id)
ID id;
{ {
long int i = 1; long int i = 1;
const char *p = (const char *) &i; const char *p = (const char *) &i;
@@ -114,14 +113,14 @@ ID id;
/* printf("id = %lx", id); */ /* printf("id = %lx", id); */
} }
PutN(n) void PutN(long n)
long n;
{ {
printf(" %ld ", n); printf(" %ld ", n);
} }
/* Put something like "...BMHD 14" or "...LIST 14 PLBM". */ /* Put something like "...BMHD 14" or "...LIST 14 PLBM". */
PutHdr(context) GroupContext *context; { void PutHdr(GroupContext *context)
{
PutLevels( ((Frame *)context->clientFrame)->levels ); PutLevels( ((Frame *)context->clientFrame)->levels );
PutID(context->ckHdr.ckID); PutID(context->ckHdr.ckID);
PutN(context->ckHdr.ckSize); PutN(context->ckHdr.ckSize);
@@ -135,8 +134,9 @@ PutHdr(context) GroupContext *context; {
/* ---------- AtLeaf ---------------------------------------------------*/ /* ---------- AtLeaf ---------------------------------------------------*/
/* At Leaf chunk. That is, a chunk which does NOT contain other chunks. /* At Leaf chunk. That is, a chunk which does NOT contain other chunks.
* Print "ID size".*/ * Print "int size".*/
IFFP AtLeaf(context) GroupContext *context; { IFFP AtLeaf(GroupContext *context)
{
PutHdr(context); PutHdr(context);
/* A typical reader would read the chunk's contents, using the "Frame" /* A typical reader would read the chunk's contents, using the "Frame"
@@ -148,7 +148,8 @@ IFFP AtLeaf(context) GroupContext *context; {
/* ---------- GetList --------------------------------------------------*/ /* ---------- GetList --------------------------------------------------*/
/* Handle a LIST chunk. Print "LIST size subTypeID". /* Handle a LIST chunk. Print "LIST size subTypeID".
* Then dive into it.*/ * Then dive into it.*/
IFFP GetList(parent) GroupContext *parent; { IFFP GetList(GroupContext *parent)
{
Frame newFrame; Frame newFrame;
newFrame = *(Frame *)parent->clientFrame; /* copy parent's frame*/ newFrame = *(Frame *)parent->clientFrame; /* copy parent's frame*/
@@ -162,9 +163,10 @@ IFFP GetList(parent) GroupContext *parent; {
/* ---------- GetForm --------------------------------------------------*/ /* ---------- GetForm --------------------------------------------------*/
/* Handle a FORM chunk. Print "FORM size subTypeID". /* Handle a FORM chunk. Print "FORM size subTypeID".
* Then dive into it.*/ * Then dive into it.*/
IFFP GetForm(parent) GroupContext *parent; { IFFP GetForm(GroupContext *parent)
{
/*CompilerBug register*/ IFFP iffp; /*CompilerBug register*/ IFFP iffp;
GroupContext new; GroupContext newptr;
Frame newFrame; Frame newFrame;
newFrame = *(Frame *)parent->clientFrame; /* copy parent's frame*/ newFrame = *(Frame *)parent->clientFrame; /* copy parent's frame*/
@@ -172,49 +174,51 @@ IFFP GetForm(parent) GroupContext *parent; {
PutHdr(parent); PutHdr(parent);
iffp = OpenRGroup(parent, &new); iffp = OpenRGroup(parent, &newptr);
CheckIFFP(); CheckIFFP();
new.clientFrame = (ClientFrame *)&newFrame; newptr.clientFrame = (ClientFrame *)&newFrame;
/* FORM reader for Checker. */ /* FORM reader for Checker. */
/* LIST, FORM, PROP, CAT already handled by GetF1ChunkHdr. */ /* LIST, FORM, PROP, CAT already handled by GetF1ChunkHdr. */
do {if ( (iffp = GetF1ChunkHdr(&new)) > 0 ) do {if ( (iffp = GetF1ChunkHdr(&newptr)) > 0 )
iffp = AtLeaf(&new); iffp = AtLeaf(&newptr);
} while (iffp >= IFF_OKAY); } while (iffp >= IFF_OKAY);
CloseRGroup(&new); CloseRGroup(&newptr);
return(iffp == END_MARK ? IFF_OKAY : iffp); return(iffp == END_MARK ? IFF_OKAY : iffp);
} }
/* ---------- GetProp --------------------------------------------------*/ /* ---------- GetProp --------------------------------------------------*/
/* Handle a PROP chunk. Print "PROP size subTypeID". /* Handle a PROP chunk. Print "PROP size subTypeID".
* Then dive into it.*/ * Then dive into it.*/
IFFP GetProp(listContext) GroupContext *listContext; { IFFP GetProp(GroupContext *listContext)
{
/*CompilerBug register*/ IFFP iffp; /*CompilerBug register*/ IFFP iffp;
GroupContext new; GroupContext newptr;
PutHdr(listContext); PutHdr(listContext);
iffp = OpenRGroup(listContext, &new); iffp = OpenRGroup(listContext, &newptr);
CheckIFFP(); CheckIFFP();
/* PROP reader for Checker. */ /* PROP reader for Checker. */
((Frame *)listContext->clientFrame)->levels++; ((Frame *)listContext->clientFrame)->levels++;
do {if ( (iffp = GetPChunkHdr(&new)) > 0 ) do {if ( (iffp = GetPChunkHdr(&newptr)) > 0 )
iffp = AtLeaf(&new); iffp = AtLeaf(&newptr);
} while (iffp >= IFF_OKAY); } while (iffp >= IFF_OKAY);
((Frame *)listContext->clientFrame)->levels--; ((Frame *)listContext->clientFrame)->levels--;
CloseRGroup(&new); CloseRGroup(&newptr);
return(iffp == END_MARK ? IFF_OKAY : iffp); return(iffp == END_MARK ? IFF_OKAY : iffp);
} }
/* ---------- GetCat ---------------------------------------------------*/ /* ---------- GetCat ---------------------------------------------------*/
/* Handle a CAT chunk. Print "CAT size subTypeID". /* Handle a CAT chunk. Print "CAT size subTypeID".
* Then dive into it.*/ * Then dive into it.*/
IFFP GetCat(parent) GroupContext *parent; { IFFP GetCat(GroupContext *parent)
{
IFFP iffp; IFFP iffp;
((Frame *)parent->clientFrame)->levels++; ((Frame *)parent->clientFrame)->levels++;

View File

@@ -19,58 +19,60 @@
/* ---------- Read -----------------------------------------------------*/ /* ---------- Read -----------------------------------------------------*/
extern LONG PutID(); /** Added as a diagnostic aid, will remove later ***/ extern int PutID(); /** Added as a diagnostic aid, will remove later ***/
/* ---------- OpenRIFF --------------------------------------------------*/ /* ---------- OpenRIFF --------------------------------------------------*/
IFFP OpenRIFF(file0, new0, clientFrame) IFFP OpenRIFF(BPTR file0, GroupContext *new0,ClientFrame *clientFrame)
BPTR file0; GroupContext *new0; ClientFrame *clientFrame; { {
register BPTR file = file0; register BPTR file = file0;
register GroupContext *new = new0; register GroupContext *newtmp = new0;
IFFP iffp = IFF_OKAY; IFFP iffp = IFF_OKAY;
new->parent = NL; /* "whole file" has no parent.*/ newtmp->parent = NL; /* "whole file" has no parent.*/
new->clientFrame = clientFrame; newtmp->clientFrame = clientFrame;
new->file = file; newtmp->file = file;
new->position = 0; newtmp->position = 0;
new->ckHdr.ckID = new->subtype = NULL_CHUNK; newtmp->ckHdr.ckID = newtmp->subtype = NULL_CHUNK;
new->ckHdr.ckSize = new->bytesSoFar = 0; newtmp->ckHdr.ckSize = newtmp->bytesSoFar = 0;
/* Set new->bound. AmigaDOS specific code.*/ /* Set newtmp->bound. AmigaDOS specific code.*/
if (file <= 0) return(NO_FILE); if (file <= 0) return(NO_FILE);
Seek(file, 0L, OFFSET_END); /* Seek to end of file.*/ Seek(file, 0L, OFFSET_END); /* Seek to end of file.*/
new->bound = ftell(file);//Seek(file, 0L, OFFSET_CURRENT); /* Pos'n == #bytes in file.*/ newtmp->bound = ftell(file);//Seek(file, 0L, OFFSET_CURRENT); /* Pos'n == #bytes in file.*/
if (new->bound < 0) return(DOS_ERROR); /* DOS being absurd.*/ if (newtmp->bound < 0) return(DOS_ERROR); /* DOS being absurd.*/
Seek(file, 0L, OFFSET_BEGINNING); /* Go to file start.*/ Seek(file, 0L, OFFSET_BEGINNING); /* Go to file start.*/
/* Would just do this if Amiga DOS maintained fh_End: */ /* Would just do this if Amiga DOS maintained fh_End: */
/* new->bound = (FileHandle *)BADDR(file)->fh_End; */ /* newtmp->bound = (FileHandle *)BADDR(file)->fh_End; */
if ( new->bound < (long)sizeof(ChunkHeader) ) if ( newtmp->bound < (long)sizeof(ChunkHeader) )
iffp = NOT_IFF; iffp = NOT_IFF;
return(iffp); return(iffp);
} }
/* ---------- OpenRGroup -----------------------------------------------*/ /* ---------- OpenRGroup -----------------------------------------------*/
IFFP OpenRGroup(parent0, new0) GroupContext *parent0, *new0; { IFFP OpenRGroup(GroupContext* parent0,GroupContext* new0)
{
register GroupContext *parent = parent0; register GroupContext *parent = parent0;
register GroupContext *new = new0; register GroupContext *newtmp = new0;
IFFP iffp = IFF_OKAY; IFFP iffp = IFF_OKAY;
new->parent = parent; newtmp->parent = parent;
new->clientFrame = parent->clientFrame; newtmp->clientFrame = parent->clientFrame;
new->file = parent->file; newtmp->file = parent->file;
new->position = parent->position; newtmp->position = parent->position;
new->bound = parent->position + ChunkMoreBytes(parent); newtmp->bound = parent->position + ChunkMoreBytes(parent);
new->ckHdr.ckID = new->subtype = NULL_CHUNK; newtmp->ckHdr.ckID = newtmp->subtype = NULL_CHUNK;
new->ckHdr.ckSize = new->bytesSoFar = 0; newtmp->ckHdr.ckSize = newtmp->bytesSoFar = 0;
if ( new->bound > parent->bound || IS_ODD(new->bound) ) if ( newtmp->bound > parent->bound || IS_ODD(newtmp->bound) )
iffp = BAD_IFF; iffp = BAD_IFF;
return(iffp); return(iffp);
} }
/* ---------- CloseRGroup -----------------------------------------------*/ /* ---------- CloseRGroup -----------------------------------------------*/
IFFP CloseRGroup(context) GroupContext *context; { IFFP CloseRGroup(GroupContext *context)
register LONG position; {
register int position;
if (context->parent == NL) { if (context->parent == NL) {
} /* Context for whole file.*/ } /* Context for whole file.*/
@@ -86,9 +88,7 @@ IFFP CloseRGroup(context) GroupContext *context; {
/* Skip over bytes in a context. Won't go backwards.*/ /* Skip over bytes in a context. Won't go backwards.*/
/* Updates context->position but not context->bytesSoFar.*/ /* Updates context->position but not context->bytesSoFar.*/
/* This implementation is AmigaDOS specific.*/ /* This implementation is AmigaDOS specific.*/
IFFP SkipFwd(context, bytes) IFFP SkipFwd(GroupContext *context,int bytes)
GroupContext *context;
LONG bytes;
{ {
IFFP iffp = IFF_OKAY; IFFP iffp = IFF_OKAY;
@@ -130,18 +130,18 @@ int endianSwap32(int val)
/* ---------- GetChunkHdr ----------------------------------------------*/ /* ---------- GetChunkHdr ----------------------------------------------*/
ID GetChunkHdr(GroupContext *context0) int GetChunkHdr(GroupContext *context0)
{ {
register GroupContext *context = context0; register GroupContext *context = context0;
register IFFP iffp; register IFFP iffp;
LONG remaining; int remaining;
/* Skip remainder of previous chunk & padding. */ /* Skip remainder of previous chunk & padding. */
iffp = SkipFwd(context, iffp = SkipFwd(context,
ChunkMoreBytes(context) + IS_ODD(context->ckHdr.ckSize)); ChunkMoreBytes(context) + IS_ODD(context->ckHdr.ckSize));
CheckIFFP(); CheckIFFP();
/* Set up to read the new header. */ /* Set up to read the newtmp header. */
context->ckHdr.ckID = BAD_IFF; /* Until we know it's okay, mark it BAD.*/ context->ckHdr.ckID = BAD_IFF; /* Until we know it's okay, mark it BAD.*/
context->subtype = NULL_CHUNK; context->subtype = NULL_CHUNK;
context->bytesSoFar = 0; context->bytesSoFar = 0;
@@ -189,7 +189,7 @@ ID GetChunkHdr(GroupContext *context0)
context->position += (long)sizeof(ChunkHeader); context->position += (long)sizeof(ChunkHeader);
remaining -= (long)sizeof(ChunkHeader); remaining -= (long)sizeof(ChunkHeader);
/* Non-positive ID values are illegal and used for error codes.*/ /* Non-positive int values are illegal and used for error codes.*/
/* We could check for other illegal IDs...*/ /* We could check for other illegal IDs...*/
if (context->ckHdr.ckID <= 0 ) if (context->ckHdr.ckID <= 0 )
context->ckHdr.ckID = BAD_IFF; context->ckHdr.ckID = BAD_IFF;
@@ -201,14 +201,14 @@ ID GetChunkHdr(GroupContext *context0)
context->ckHdr.ckID = BAD_IFF; context->ckHdr.ckID = BAD_IFF;
} }
/* Automatically read the LIST, FORM, PROP, or CAT subtype ID */ /* Automatically read the LIST, FORM, PROP, or CAT subtype int */
else { else {
if (context->ckHdr.ckID == LIST || if (context->ckHdr.ckID == LIST ||
context->ckHdr.ckID == FORM || context->ckHdr.ckID == FORM ||
context->ckHdr.ckID == PROP || context->ckHdr.ckID == PROP ||
context->ckHdr.ckID == CAT) { context->ckHdr.ckID == CAT) {
iffp = IFFReadBytes(context, (BYTE *)&context->subtype, iffp = IFFReadBytes(context, (BYTE *)&context->subtype,
(long)sizeof(ID)); (long)sizeof(int));
if (iffp != IFF_OKAY ) if (iffp != IFF_OKAY )
context->ckHdr.ckID = iffp; context->ckHdr.ckID = iffp;
} }
@@ -218,10 +218,7 @@ ID GetChunkHdr(GroupContext *context0)
} }
/* ---------- IFFReadBytes ---------------------------------------------*/ /* ---------- IFFReadBytes ---------------------------------------------*/
IFFP IFFReadBytes(context, buffer, nBytes) IFFP IFFReadBytes(GroupContext *context,BYTE *buffer, int nBytes)
GroupContext *context;
BYTE *buffer;
LONG nBytes;
{ {
register IFFP iffp = IFF_OKAY; register IFFP iffp = IFF_OKAY;
@@ -250,14 +247,12 @@ IFFP SkipGroup( GroupContext* context)
} /* Nothing to do, thanks to GetChunkHdr */ } /* Nothing to do, thanks to GetChunkHdr */
/* ---------- ReadIFF --------------------------------------------------*/ /* ---------- ReadIFF --------------------------------------------------*/
IFFP ReadIFF(file, clientFrame) IFFP ReadIFF(BPTR file,ClientFrame *clientFrame)
BPTR file;
ClientFrame *clientFrame;
{ {
/*CompilerBug register*/ IFFP iffp; /*CompilerBug register*/ IFFP iffp;
GroupContext context; GroupContext context;
iffp = OpenRIFF(file, &context); iffp = OpenRIFF(file, &context,clientFrame);
context.clientFrame = clientFrame; context.clientFrame = clientFrame;
if (iffp == IFF_OKAY) { if (iffp == IFF_OKAY) {
@@ -274,15 +269,13 @@ ClientFrame *clientFrame;
} }
CloseRGroup(&context); CloseRGroup(&context);
if (iffp > 0 ) /* Make sure we don't return an ID.*/ if (iffp > 0 ) /* Make sure we don't return an int.*/
iffp = NOT_IFF; /* GetChunkHdr should've caught this.*/ iffp = NOT_IFF; /* GetChunkHdr should've caught this.*/
return(iffp); return(iffp);
} }
/* ---------- ReadIList ------------------------------------------------*/ /* ---------- ReadIList ------------------------------------------------*/
IFFP ReadIList(parent, clientFrame) IFFP ReadIList(GroupContext *parent,ClientFrame *clientFrame)
GroupContext *parent;
ClientFrame *clientFrame;
{ {
GroupContext listContext; GroupContext listContext;
IFFP iffp; IFFP iffp;
@@ -327,15 +320,15 @@ ClientFrame *clientFrame;
/* ---------- ReadICat -------------------------------------------------*/ /* ---------- ReadICat -------------------------------------------------*/
/* By special arrangement with the ReadIList implement'n, this is trivial.*/ /* By special arrangement with the ReadIList implement'n, this is trivial.*/
IFFP ReadICat(parent) GroupContext *parent; { IFFP ReadICat(GroupContext *parent)
{
return( ReadIList(parent, parent->clientFrame));//NL) ); return( ReadIList(parent, parent->clientFrame));//NL) );
} }
/* ---------- GetFChunkHdr ---------------------------------------------*/ /* ---------- GetFChunkHdr ---------------------------------------------*/
ID GetFChunkHdr(context) int GetFChunkHdr(GroupContext *context)
GroupContext *context;
{ {
register ID id; register int id;
id = GetChunkHdr(context); id = GetChunkHdr(context);
if (id == PROP) if (id == PROP)
@@ -344,8 +337,9 @@ GroupContext *context;
} }
/* ---------- GetF1ChunkHdr ---------------------------------------------*/ /* ---------- GetF1ChunkHdr ---------------------------------------------*/
ID GetF1ChunkHdr(context) GroupContext *context; { int GetF1ChunkHdr(GroupContext *context)
register ID id; {
register int id;
register ClientFrame *clientFrame = context->clientFrame; register ClientFrame *clientFrame = context->clientFrame;
id = GetChunkHdr(context); id = GetChunkHdr(context);
@@ -365,10 +359,9 @@ ID GetF1ChunkHdr(context) GroupContext *context; {
} }
/* ---------- GetPChunkHdr ---------------------------------------------*/ /* ---------- GetPChunkHdr ---------------------------------------------*/
ID GetPChunkHdr(context) int GetPChunkHdr(GroupContext *context)
GroupContext *context;
{ {
register ID id; register int id;
id = GetChunkHdr(context); id = GetChunkHdr(context);
if (id == LIST || id == FORM || id == PROP || id == CAT ) if (id == LIST || id == FORM || id == PROP || id == CAT )

View File

@@ -23,17 +23,18 @@
/* ---------- OpenWIFF -------------------------------------------------*/ /* ---------- OpenWIFF -------------------------------------------------*/
IFFP OpenWIFF(file, new0, limit) BPTR file; GroupContext *new0; LONG limit; { IFFP OpenWIFF(BPTR file, GroupContext *new0, int limit)
register GroupContext *new = new0; {
register GroupContext *newtmp = new0;
register IFFP iffp = IFF_OKAY; register IFFP iffp = IFF_OKAY;
new->parent = NULL; newtmp->parent = NULL;
new->clientFrame = NULL; newtmp->clientFrame = NULL;
new->file = file; newtmp->file = file;
new->position = 0; newtmp->position = 0;
new->bound = limit; newtmp->bound = limit;
new->ckHdr.ckID = NULL_CHUNK; /* indicates no current chunk */ newtmp->ckHdr.ckID = NULL_CHUNK; /* indicates no current chunk */
new->ckHdr.ckSize = new->bytesSoFar = 0; newtmp->ckHdr.ckSize = newtmp->bytesSoFar = 0;
if (0 > Seek(file, 0, OFFSET_BEGINNING)) /* Go to start of the file.*/ if (0 > Seek(file, 0, OFFSET_BEGINNING)) /* Go to start of the file.*/
iffp = DOS_ERROR; iffp = DOS_ERROR;
@@ -43,46 +44,48 @@ IFFP OpenWIFF(file, new0, limit) BPTR file; GroupContext *new0; LONG limit; {
} }
/* ---------- StartWGroup ----------------------------------------------*/ /* ---------- StartWGroup ----------------------------------------------*/
IFFP StartWGroup(parent, groupType, groupSize, subtype, new) IFFP StartWGroup( GroupContext* parent, int groupType,int groupSize,int subtype, GroupContext * newtmp)
GroupContext *parent, *new; ID groupType, subtype; LONG groupSize; { {
register IFFP iffp; register IFFP iffp;
iffp = PutCkHdr(parent, groupType, groupSize); iffp = PutCkHdr(parent, groupType, groupSize);
IfIffp( IFFWriteBytes(parent, (BYTE *)&subtype, sizeof(ID)) ); IfIffp( IFFWriteBytes(parent, (char *)&subtype, sizeof(int)) );
IfIffp( OpenWGroup(parent, new) ); IfIffp( OpenWGroup(parent, newtmp) );
return(iffp); return(iffp);
} }
/* ---------- OpenWGroup -----------------------------------------------*/ /* ---------- OpenWGroup -----------------------------------------------*/
IFFP OpenWGroup(parent0, new0) GroupContext *parent0, *new0; { IFFP OpenWGroup(GroupContext *parent0,GroupContext* new0)
{
register GroupContext *parent = parent0; register GroupContext *parent = parent0;
register GroupContext *new = new0; register GroupContext *newtmp = new0;
register LONG ckEnd; register int ckEnd;
register IFFP iffp = IFF_OKAY; register IFFP iffp = IFF_OKAY;
new->parent = parent; newtmp->parent = parent;
new->clientFrame = parent->clientFrame; newtmp->clientFrame = parent->clientFrame;
new->file = parent->file; newtmp->file = parent->file;
new->position = parent->position; newtmp->position = parent->position;
new->bound = parent->bound; newtmp->bound = parent->bound;
new->ckHdr.ckID = NULL_CHUNK; newtmp->ckHdr.ckID = NULL_CHUNK;
new->ckHdr.ckSize = new->bytesSoFar = 0; newtmp->ckHdr.ckSize = newtmp->bytesSoFar = 0;
if ( Known(parent->ckHdr.ckSize) ) { if ( Known(parent->ckHdr.ckSize) ) {
ckEnd = new->position + ChunkMoreBytes(parent); ckEnd = newtmp->position + ChunkMoreBytes(parent);
if ( new->bound == szNotYetKnown || new->bound > ckEnd ) if ( newtmp->bound == szNotYetKnown || newtmp->bound > ckEnd )
new->bound = ckEnd; newtmp->bound = ckEnd;
}; };
if ( parent->ckHdr.ckID == NULL_CHUNK || /* not currently writing a chunk*/ if ( parent->ckHdr.ckID == NULL_CHUNK || /* not currently writing a chunk*/
IS_ODD(new->position) || IS_ODD(newtmp->position) ||
(Known(new->bound) && IS_ODD(new->bound)) ) (Known(newtmp->bound) && IS_ODD(newtmp->bound)) )
iffp = CLIENT_ERROR; iffp = CLIENT_ERROR;
return(iffp); return(iffp);
} }
/* ---------- CloseWGroup ----------------------------------------------*/ /* ---------- CloseWGroup ----------------------------------------------*/
IFFP CloseWGroup(old0) GroupContext *old0; { IFFP CloseWGroup(GroupContext *old0)
{
register GroupContext *old = old0; register GroupContext *old = old0;
if ( old->ckHdr.ckID != NULL_CHUNK ) /* didn't close the last chunk */ if ( old->ckHdr.ckID != NULL_CHUNK ) /* didn't close the last chunk */
@@ -99,7 +102,8 @@ IFFP CloseWGroup(old0) GroupContext *old0; {
} }
/* ---------- EndWGroup ------------------------------------------------*/ /* ---------- EndWGroup ------------------------------------------------*/
IFFP EndWGroup(old) GroupContext *old; { IFFP EndWGroup(GroupContext *old)
{
register GroupContext *parent = old->parent; register GroupContext *parent = old->parent;
register IFFP iffp; register IFFP iffp;
@@ -110,8 +114,8 @@ IFFP EndWGroup(old) GroupContext *old; {
} }
/* ---------- PutCk ----------------------------------------------------*/ /* ---------- PutCk ----------------------------------------------------*/
IFFP PutCk(context, ckID, ckSize, data) IFFP PutCk(GroupContext *context, int ckID,int ckSize,char *data)
GroupContext *context; ID ckID; LONG ckSize; BYTE *data; { {
register IFFP iffp = IFF_OKAY; register IFFP iffp = IFF_OKAY;
if ( ckSize == szNotYetKnown ) if ( ckSize == szNotYetKnown )
@@ -123,14 +127,14 @@ GroupContext *context; ID ckID; LONG ckSize; BYTE *data; {
} }
/* ---------- PutCkHdr -------------------------------------------------*/ /* ---------- PutCkHdr -------------------------------------------------*/
IFFP PutCkHdr(context0, ckID, ckSize) IFFP PutCkHdr(GroupContext *context0, int ckID, int ckSize)
GroupContext *context0; ID ckID; LONG ckSize; { {
register GroupContext *context = context0; register GroupContext *context = context0;
LONG minPSize = sizeof(ChunkHeader); /* physical chunk >= minPSize bytes*/ int minPSize = sizeof(ChunkHeader); /* physical chunk >= minPSize bytes*/
/* CLIENT_ERROR if we're already inside a chunk or asked to write /* CLIENT_ERROR if we're already inside a chunk or asked to write
* other than one FORM, LIST, or CAT at the top level of a file */ * other than one FORM, LIST, or CAT at the top level of a file */
/* Also, non-positive ID values are illegal and used for error codes.*/ /* Also, non-positive int values are illegal and used for error codes.*/
/* (We could check for other illegal IDs...)*/ /* (We could check for other illegal IDs...)*/
if ( context->ckHdr.ckID != NULL_CHUNK || ckID <= 0 ) if ( context->ckHdr.ckID != NULL_CHUNK || ckID <= 0 )
return(CLIENT_ERROR); return(CLIENT_ERROR);
@@ -157,7 +161,7 @@ GroupContext *context0; ID ckID; LONG ckSize; {
context->bytesSoFar = 0; context->bytesSoFar = 0;
{ {
context->ckHdr.ckSize = endianSwap32(context->ckHdr.ckSize); context->ckHdr.ckSize = endianSwap32(context->ckHdr.ckSize);
if (0 > GWrite(context->file, &context->ckHdr, sizeof(ChunkHeader))) if (0 > fwrite(&context->ckHdr, 1,sizeof(ChunkHeader),context->file))
return(DOS_ERROR); return(DOS_ERROR);
context->ckHdr.ckSize = endianSwap32(context->ckHdr.ckSize); context->ckHdr.ckSize = endianSwap32(context->ckHdr.ckSize);
} }
@@ -166,8 +170,8 @@ GroupContext *context0; ID ckID; LONG ckSize; {
} }
/* ---------- IFFWriteBytes ---------------------------------------------*/ /* ---------- IFFWriteBytes ---------------------------------------------*/
IFFP IFFWriteBytes(context0, data, nBytes) IFFP IFFWriteBytes(GroupContext *context0, char *data, int nBytes)
GroupContext *context0; BYTE *data; LONG nBytes; { {
register GroupContext *context = context0; register GroupContext *context = context0;
if ( context->ckHdr.ckID == NULL_CHUNK || /* not in a chunk */ if ( context->ckHdr.ckID == NULL_CHUNK || /* not in a chunk */
@@ -180,7 +184,7 @@ GroupContext *context0; BYTE *data; LONG nBytes; {
return(CLIENT_ERROR); return(CLIENT_ERROR);
} }
if (0 > GWrite(context->file, data, nBytes)) if (0 > fwrite(data, 1,nBytes,context->file))
return(DOS_ERROR); return(DOS_ERROR);
context->bytesSoFar += nBytes; context->bytesSoFar += nBytes;
@@ -189,7 +193,8 @@ GroupContext *context0; BYTE *data; LONG nBytes; {
} }
/* ---------- PutCkEnd -------------------------------------------------*/ /* ---------- PutCkEnd -------------------------------------------------*/
IFFP PutCkEnd(context0) GroupContext *context0; { IFFP PutCkEnd(GroupContext *context0)
{
register GroupContext *context = context0; register GroupContext *context = context0;
WORD zero = 0; /* padding source */ WORD zero = 0; /* padding source */
@@ -198,7 +203,7 @@ IFFP PutCkEnd(context0) GroupContext *context0; {
if ( context->ckHdr.ckSize == szNotYetKnown ) { if ( context->ckHdr.ckSize == szNotYetKnown ) {
/* go back and set the chunk size to bytesSoFar */ /* go back and set the chunk size to bytesSoFar */
int offset = context->bytesSoFar+sizeof(LONG); int offset = context->bytesSoFar+sizeof(int);
if ( 0 > GSeek(context->file, if ( 0 > GSeek(context->file,
-(offset), -(offset),
OFFSET_CURRENT)) OFFSET_CURRENT))
@@ -207,7 +212,7 @@ IFFP PutCkEnd(context0) GroupContext *context0; {
} else } else
{ {
context->bytesSoFar = endianSwap32(context->bytesSoFar); context->bytesSoFar = endianSwap32(context->bytesSoFar);
if (0 > GWrite(context->file, &context->bytesSoFar, sizeof(LONG))) if (0 > fwrite(&context->bytesSoFar, 1,sizeof(int),context->file))
return (DOS_ERROR); return (DOS_ERROR);
context->bytesSoFar = endianSwap32(context->bytesSoFar); context->bytesSoFar = endianSwap32(context->bytesSoFar);
if (0 > GSeek(context->file, context->bytesSoFar, OFFSET_CURRENT) ) if (0 > GSeek(context->file, context->bytesSoFar, OFFSET_CURRENT) )
@@ -226,7 +231,7 @@ IFFP PutCkEnd(context0) GroupContext *context0; {
* overwritten the context, if we're on an odd position there must * overwritten the context, if we're on an odd position there must
* be room for a pad byte. */ * be room for a pad byte. */
if ( IS_ODD(context->bytesSoFar) ) { if ( IS_ODD(context->bytesSoFar) ) {
if ( 0 > GWrite(context->file, &zero, 1) ) if ( 0 > fwrite(&zero, 1,1,context->file) )
return(DOS_ERROR); return(DOS_ERROR);
context->position += 1; context->position += 1;
}; };