#include  <io.h>
#include  <dos.h>
#include  <bios.h>
#include  <stdio.h>
#include  <fcntl.h>
#include  <string.h>
#include  <stdlib.h>
#include  <alloc.h>
#include  <time.h>

char wavfile[20];
char *tempbuf;

main(int argc, char **argv)
{
       FILE* wavf;
       FILE* outf;
       FILE* wavlistf;
       char wfile[20];
       int numread, i;

       if(argc > 1) {
               wavlistf = fopen(argv[1], "rt");
               outf = fopen("MORSE.DAT", "wb");

               tempbuf = malloc(50000);

               while(fgets(wavfile, 80, wavlistf)) {
                       wavfile[strlen(wavfile)-1] = 0;
                       strcpy(wfile, wavfile);
                       strcat(wfile, ".WAV");

                       if(! (wavf = fopen(wfile, "rb"))) {
                               printf("Couldn't find %s!\n", wfile);
                               break;
                       }
                       numread = fread(tempbuf, 1, 50000, wavf);

                       fwrite(&numread, 1, 2, outf);
                       fwrite(tempbuf, 1, numread, outf);
                       fclose(wavf);
               }
               fclose(wavlistf);
               fclose(outf);
               printf("Ok.\n");
       } else {
               printf("WAV Masher v1.0\n");
               printf("usage: wavmash <wavlistfile>\n\n");
               printf("The WAV list file should contain the names of all the\n");
               printf("WAV files to mash, one name per line\n");
       }
}