home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / RENMOD.ZIP / RENMOD.C < prev    next >
C/C++ Source or Header  |  1997-09-11  |  2KB  |  64 lines

  1. /************************************************************/
  2. /*****                     RENMOD                       *****/
  3. /*****               Very short'n'simple                *****/
  4. /*****            Protracker module renamer             *****/
  5. /*****             "C"oded by  ∙B∙I∙K∙E∙R∙              *****/
  6. /*****             dumb version - no  M.K.              *****/
  7. /*****        pattern checking - but who cares!         *****/
  8. /************************************************************/
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #define FNAME_SIZE 8    /*alter this value for systems supporting longer
  14.                          basename than 'poor' 8 chars offered by MS-DOS*/
  15.                         
  16. void errorExit(char *msg)
  17. {
  18.     char errmsg[80] = "■ERROR: ";
  19.     puts( strcat(errmsg, msg) );
  20.     exit(-1);
  21. }
  22.  
  23. void main(int argc, char **argv)
  24. {
  25.     FILE *f;
  26.     char *p, fname[128]; /*128 should be enaugh for modname*/
  27.     int counter=0;
  28.  
  29.     if(argc < 2)
  30.         errorExit("\rRENMOD by ∙B∙I∙K∙E∙R∙\nusage:\n\tRENMOD filename");
  31.     if( !(f = fopen(argv[1], "rb")) ) errorExit("Can't open the file!");
  32.  
  33. /*  you could use 
  34.  
  35.     fscanf(f, "%s", fname);
  36.  
  37.     instead of*/
  38.  
  39.     for(p = fname;
  40.         (p - fname) < FNAME_SIZE;
  41.         p += (  (*p == ' ')||        /* this strange for(;;) */
  42.                 (*p == '<')||        /* statement removes illegal */
  43.                 (*p == '>')||        /* chars from fname */
  44.                 (*p == '#')||
  45.                 (*p == '.')||
  46.                 (*p == '\0') )?0:1)
  47.         if( (*p = fgetc(f))==EOF )
  48.             errorExit("File is too short! (chiptune? :)");
  49.  
  50. /*  but fscanf will (sometimes) truncate filename to the first space*/
  51.  
  52.     fclose(f);
  53.     fname[FNAME_SIZE] = '\0';
  54.     strcat(fname, ".mod");
  55.  
  56. /* and now we must handle the same filenames - only 101 same names allowed*/
  57.     while( (f = fopen(fname, "r")) ){
  58.         fclose(f);
  59.         sprintf(&fname[FNAME_SIZE-2], "%02d", counter++);
  60.         fname[8]='.';
  61.     }
  62.     if(rename(argv[1], fname)) errorExit("Can't rename the file!");
  63. }
  64.