/*********************************************************/
/*                                                       */
/*  DMCSpect V1.0 -- Inom Software (c) 1988              */
/*                                                       */
/*  Author        : Erick Scott Dyke                     */
/*  Computer      : Commodore Amiga 1000                 */
/*  Processor     : Motorola 68000                       */
/*  Language      : Lattice AmigaDos C Compiler V4.00    */
/*                                                       */
/*  Purpose       : This program, based on the idea and  */
/*                  Amiga Basic code of Doug Pelletier,  */
/*                  finds all the instruments needed by  */
/*                  DMCS to play the song properly.      */
/*                                                       */
/*  This program is public domain, and I hope that any   */
/*  copies of the source code you distribute still have  */
/*  this program header. -- Enjoy!                       */
/*                                                       */
/*********************************************************/

#include "stdio.h"
#include "string.h"

void main (argc, argv)

int      argc;
char    *argv[];

{
FILE    *File_Pointer;

char     Input_Character;
char     Command [4];
char     Dummy [4];

Command [3] = '\0';

   printf ("\nInom Software's Deluxe Music Instrument Identifier.\n");

   if (argc < 2) 
      {
      printf ("Usage: DMCSpect <file name>\n");
      exit (0);
      }

   if ((File_Pointer = fopen (argv [1], "rb")) == NULL)
      { 
      printf ("\nSorry, invalid file name.\n");
      exit (0);
      }

   printf ("\nInstruments needed for the song %s:\n\n", argv [1]);

   fseek (File_Pointer, -1000L, 2);

   Input_Character = getc (File_Pointer);
   while (!feof (File_Pointer)) 
      {
      if (Input_Character == 'U')
         {
         fread (Command, 1, 3, File_Pointer);
         if (!strcmp (Command, "IID"))
            {
            fread (Dummy, 1, 4, File_Pointer);
            while (((Input_Character = getc (File_Pointer)) != 'U') && (!feof (File_Pointer)))
               printf ("%c", Input_Character);
            printf ("\n");
            ungetc (Input_Character, File_Pointer); 
            }
         }
      Input_Character = getc(File_Pointer);
      }
   fclose (File_Pointer); 
}
