/*                     Play function by A.A.Efros.
	PLAY is C function to be used with MELODY MASTER Data files.

  PLAY uses Sound, Delay and Nosound functions. There are no such functions
  in some C-Compilers. In this case one should use file TONE.C (#include
  <tone.c>) which is also included in this package.

  To call function PLAY one should:
	 play( [FileName], [MelodyName]);
  For example:
	 play('music.dat','Glory');
*/

#include <stdio.h>
#include <dos.h>

play(filename, melodyname)

char filename[11], melodyname[15];
{
  int q = 1, fr, t, ver = 1;
  char ch, st[1000];
  FILE *data;

  if ((data = fopen(filename,"r")) != NULL)
  {
    while (q)
    {
      fscanf(data, "%s", st);
      if ((ver = strcmp(melodyname, st)) == 0)
      {
        do
        {
   	  q = fscanf(data,"%d%d%c", &fr, &t, &ch);
	  sound(fr);
          delay(t);           /*  tone(fr,t); for others compilers */
          nosound();
        } while (ch != '\n' && q != EOF);
        break;
      }
      q = (fgets(st,1000,data) != NULL);
    }
    fclose(data);
    if (ver != 0)
      printf("\007 %s song is not found!\n", melodyname);
  }
  else
    printf("\007 %s file is not found!\n", filename);
}