/* This file has been altered slightly from Tim Butler's original by  * Terence Kelly, (tkelly@pressenter.com).  This file should be linked with  * callback.c, which I have added to substantially, and the Niff library as  * provided by Tim.  I have added code to redirect stdout to a file so that * the dump can be used as a development tool.  That code is platform specific * but you should only have to alter 4 lines to make it work on your platform.  * The appropriate lines are commented.   * To save time and space I altered the doindent function to use tabs and rewrote * the separator (doline) function.  Set tabs to 4 in your viewer, and the output will  * be indistinguishable from the original. */#include <assert.h>#include <stdio.h>#include <osbind.h>#include "stdcriff.h"#include "niffio.h"extern NIFFIOParser *InitParser(void);extern void doindent(unsigned indent);static void usage();static void dumpchunk(RIFFIOFile *rioFilep, int indent);static void doerror(const char *message);static char *Progname;intmain(int argc, char **argv){    char *strNiffFile;    FILE *pFILENiff;    NIFFIOFile *pnf;    RIFFIOFOURCC fccFormType;    NIFFIOParser *pparser;    long bytesRead, handle;    unsigned char extraByte;    unsigned long extraCount;    Progname = argv[0];    /*     * Check command line arguments     */    if (argc != 2)    {        usage();        return 1;    }    strNiffFile = argv[1];    /*     * Open the riff file     */    pFILENiff = fopen(strNiffFile, "rb");    if (!pFILENiff)    {        perror("Can't open NIFF File");        return 1;    }        /*      * Initialize the niffio file     */    pnf = NIFFIOFileNewSTDC(pFILENiff);    if (!pnf)        doerror("Can't create new NIFFIOFile");        /* Redirect output to a file.      I added this code to Tim Butler's original.    	My development was for an Atari St.    	You should substitute whatever code would     	redirect stdout on your platform for the    	next two lines. */        handle = Fcreate("output.txt",0);		Fforce(1,(short)handle);    #if 0    pnf = NIFFIOFileNew();    if (pnf == 0)    {        doerror("Can't allocate NIFFIOFile");    }    if (! NIFFIOFileInit(pnf, pFILENiff,                          STDCRIFFRead, STDCRIFFWrite,                          STDCRIFFSeek, STDCRIFFTell))    {        doerror("Can't initialize NIFFIOFile");    }#endif    /*     * Initialize the parser      */    pparser = InitParser();    NIFFIOParserSetTracing(pparser, 0);    NIFFIOParseFile(pparser, pnf,  0, 0 );    /*     * Check for any extra bytes past the Form     */    extraCount = 0;    while ((bytesRead = NIFFIORead(pnf, &extraByte , 1)) == 1)    {        extraCount +=1;    }    if (extraCount != 0)    {        fprintf(stderr,"%s:WARNING:Found %lu extra bytes after Form\n",                Progname,                extraCount);        return 1;    }    /*     * Clean up     */    NIFFIOParserDelete(pparser);    NIFFIOFileDelete(pnf);    fclose(pFILENiff);        /* Reset stdout and close the file.       Change the next two lines for your        computer platform.  */           Fforce(1,1);		Fclose((short)handle);    return 0;}voiddoindent(unsigned indent){    int i;        /* Don't indent levels 0 and 1 */    if ((--indent) <= 0 )        return;    /*    indent *= 4;  four spaces per indent level */            for (i = 0; i < indent; i++)        printf("\t");}staticvoidusage(){    fprintf(stderr, "Usage: niffdump file.nif\n");}staticvoiddoerror(const char *message){    fprintf(stderr, "%s:ERROR:%s\n", Progname, message);    exit(1);}