home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / MOD15V12.ZIP / SOURCES / 3115.C < prev   
C/C++ Source or Header  |  1996-01-15  |  3KB  |  97 lines

  1. #include <string.h> /* pour les gestions de strings */
  2. #include <stdio.h> /* pour printf et les fichiers */
  3. #include <io.h> /* pour filelenght et eof */
  4. #include <dos.h> /* pour getdfree */
  5. #include <stdlib.h> /* pour exit */
  6.  
  7. char *destname (char *name) {
  8.   char *buf = "            " ;
  9.   strcpy (buf, name) ;
  10.  
  11.   buf[strlen(buf)-3] =  77 ;  /* change the 3 last chars into "MOD" */
  12.   buf[strlen(buf)-2] =  79 ;
  13.   buf[strlen(buf)-1] =  68 ;
  14.  
  15.   if (strcmp (buf, name) == 0 ) /* if ext. was already MOD, change 1st char*/
  16.     memmove (buf, "_", 1) ;
  17.  
  18.   return buf;
  19.   }
  20.  
  21.  
  22. int main (int nbparam, char *param[] ) {
  23.   FILE *src, *dest ;
  24.   char *filename = "            " ;
  25.   unsigned char buf1 [469], buf2 [129] , buf3 [32000] ;
  26.   int i=0,j=0,s ;
  27.  
  28.   printf ("\nMOD 4 CH 31 INSTR to 15 INSTR converter v12\n") ;
  29.   printf ("Coded by Magic Fred of TFL-TDV \n \n") ;
  30.   if (nbparam != 2) {
  31.     printf ("Syntax: 3115 <filename> \n \n") ;
  32.     printf ("This unuseful util converts a ProTracker/NoiseTracker \n") ;
  33.     printf ("module into an old SoundTracker (15samples) module... \n") ;
  34.     exit (0) ;
  35.     }
  36.  
  37.   filename = param [1] ;
  38.   /* Convert filename to upper case */
  39.   for ( i=0; i<strlen(filename); i++)
  40.     filename [i] = toupper (filename [i]) ;
  41.  
  42.   if (strcmp (destname(filename), filename) == 0) {
  43.     printf("I don't want to convert a MOD file ") ;
  44.     printf("with a name beginning by '_'. Sorry ! \n") ;
  45.     printf("Please rename mod file as *.NST before converting. \n") ;
  46.     exit (1) ;
  47.     }
  48.  
  49.   if ((src=fopen(filename,"rb")) == NULL) {
  50.     printf ("File '%s' not found in current directory.\n",filename) ;
  51.     printf ("Type 3115 without any parameter for help\n \n");
  52.     exit (1) ;
  53.     }
  54.   if ((dest=fopen(destname(filename),"wb")) == NULL) {
  55.     printf ("Cannot open destination file. \n \n") ;
  56.     exit (1) ;
  57.     }
  58.  
  59.  
  60.   /* Convertion : */
  61.  
  62.   for ( i=0 ; i<470 ; i++ ) {
  63.     buf1 [i] = getc (src) ;
  64.     if (feof(src) != 0) {
  65.       printf ("Too early eof error -Is this an Amiga module ? \n \n") ;
  66.       exit (1) ;
  67.     } }
  68.   fseek(src,950,SEEK_SET);
  69.   for ( i=0 ; i<130 ; i++ ) {
  70.     buf2 [i] = getc (src) ;
  71.     if (feof(src) != 0) {
  72.       printf ("Too early eof error -Is this an Amiga module ? \n \n") ;
  73.       exit (1) ;
  74.     } }
  75.  
  76.   for ( i=0 ; i<470 ; i++ )
  77.     putc ( buf1 [i] , dest ) ;
  78.   for ( i=0 ; i<130 ; i++ )
  79.     putc ( buf2 [i] , dest ) ;
  80.  
  81.  
  82.   fseek(src,1084,SEEK_SET);
  83.   while (feof(src) == 0) {
  84.     buf3 [j] = getc(src) ;
  85.     j++ ;
  86.     if (j == 32000) {
  87.       for (i=0 ; i<32000 ; i++) putc (buf3 [i] , dest) ;
  88.       j = 0 ;
  89.       }
  90.     }
  91.   for (i=0 ; i<=j ; i++)
  92.     putc (buf3 [i] , dest) ;
  93.  
  94.   printf("Converted module is '%s'.\n\n",destname(filename)) ;
  95.  
  96.   return 0 ;
  97. }