#include <stdio.h>

int main() //bsp2pak test
{
   char file1[101], file2[50];
   char finalname[56];
   FILE *fin, *fout;
   long filesize, t;
   int def;
   for (t = 0; t < 101; t++)
     file1[t] = 0;
   printf("bsp2pak for EdQuake [.map beta test file]\n");
   printf("by Scott Mitting (smitting@netusa1.net)\n");
   printf("free for public use. enjoy Quake\n");
   printf("input file: ");
   gets(file1);
   printf("output file: ");
   gets(file2);
   printf("%s->%s\n",file1,file2);
   fin = fopen(file1, "rb");
   fout = fopen(file2, "wb");
   if (!fin) return 0;
   if (!fout) return 0;
   //get filesize
   fseek(fin,0,2);
   filesize = ftell(fin);
   fseek(fin,0,0);
   //copy data
   fwrite("PACK",4,1,fout);
   filesize+=12;
   fwrite(&filesize,4,1,fout);
   filesize-=12;
   t = 64;
   fwrite(&t,4,1,fout);
   for (t = 0; t <filesize; t++)
	fputc(fgetc(fin),fout);
   //create entry
   def = 50;
   while (def > 0)
   {
      if (file1[def] == '\\') def=-def;
	 else def--;
   }
   def=-def;
   def++;
   finalname[0] = 'm';
   finalname[1] = 'a';
   finalname[2] = 'p';
   finalname[3] = 's';
   finalname[4] = '/';
   for (t = 0; t < 51; t++)
     finalname[t+5] = file1[t + def -1];
   fwrite(finalname,56,1,fout);
   t = 12;
   fwrite(&t,4,1,fout);
   fwrite(&filesize,4,1,fout);
   printf("ok\n");
   fclose(fin);
   fclose(fout);
   return 0;
}
