home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / utils / sfxmake.cpp < prev    next >
C/C++ Source or Header  |  1995-05-12  |  2KB  |  94 lines

  1. #include <fstream.h>
  2. #include <dir.h>
  3. #include <string.h>
  4. #include <io.h>
  5. #include <values.h>
  6. #include "utils.h"
  7.  
  8. const long BUFSIZE = MAXINT;
  9.  
  10. int create_gfxlib(int argc, char *argv[]);
  11.  
  12. int main(int argc,char** argv)
  13.   {
  14.   //-----------------------------------------------------
  15.   // check for two arguments
  16.  
  17.   if (argc<2)
  18.     {
  19.     cout << "\nUSAGE : SFXMAKE <sfxlib> <file1, ...> @<listfile>\n"
  20.             "  SFXMAKE constructs SFX sound effects libraries\n"
  21.             "  from the files listed on the command line or in\n"
  22.             "  <listfile>. SFXMAKE constructs the SFX library\n"
  23.             "  with the entries in the order in which they appear\n"
  24.             "  on the command file and/or in <listfile>.\n";
  25.     return -1;
  26.     }
  27.   if (create_gfxlib(argc, argv))
  28.     cout << "ok\n";
  29.   return 0;
  30.   }  // main
  31.  
  32. static int count;
  33. static char* sndbuffer;
  34. static ofstream sfxlib;
  35. void bld_sfxlib(char *file);
  36.  
  37. int create_gfxlib(int argc, char *argv[])
  38. {
  39.     //-----------------------------------------------------
  40.     // allocate buffer for sound files
  41.  
  42.     sndbuffer=new char[(size_t)BUFSIZE];
  43.  
  44.     //------------------------------------------------------
  45.     // open the new file
  46.     // write out the count
  47.      // write out size/data pairs
  48.     // close file
  49.  
  50.     sfxlib.open(argv[1],ios::binary);
  51.  
  52.     count = 0;
  53.     sfxlib.write((char*)&count,sizeof(count));
  54.  
  55.     int rtn = parse_cmdline(argc-2, argv+2, bld_sfxlib);
  56.     if (rtn)    {
  57.         sfxlib.seekp(0);
  58.         sfxlib.write((char*)&count,sizeof(count));
  59.         cout << "stored " << count << " entries\n";
  60.     }
  61.     sfxlib.close();
  62.     delete sndbuffer;
  63.     return rtn;
  64. }
  65.  
  66. void bld_sfxlib(char *file)
  67. {
  68.     ifstream clip;
  69.     struct ffblk ffblk;
  70.     long size;
  71.  
  72.     findfirst(file,&ffblk,0);
  73.     size=ffblk.ff_fsize;
  74.  
  75.     clip.open(file,ios::binary);
  76.  
  77.     sfxlib.write((char*)&size,sizeof(size));
  78.  
  79.     char *bf = sndbuffer;
  80.     int chread;
  81.  
  82.     do
  83.       {
  84.         clip.read(bf, MAXINT);
  85.         chread = clip.gcount();
  86.         if (chread)
  87.            sfxlib.write(sndbuffer,chread);
  88.       } while (chread == MAXINT);
  89.  
  90.     clip.close();
  91.     cout << (++count) << ": " << size << " bytes\n";
  92. }
  93.  
  94.