home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
RENMOD.ZIP
/
RENMOD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-11
|
2KB
|
64 lines
/************************************************************/
/***** RENMOD *****/
/***** Very short'n'simple *****/
/***** Protracker module renamer *****/
/***** "C"oded by ∙B∙I∙K∙E∙R∙ *****/
/***** dumb version - no M.K. *****/
/***** pattern checking - but who cares! *****/
/************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define FNAME_SIZE 8 /*alter this value for systems supporting longer
basename than 'poor' 8 chars offered by MS-DOS*/
void errorExit(char *msg)
{
char errmsg[80] = "■ERROR: ";
puts( strcat(errmsg, msg) );
exit(-1);
}
void main(int argc, char **argv)
{
FILE *f;
char *p, fname[128]; /*128 should be enaugh for modname*/
int counter=0;
if(argc < 2)
errorExit("\rRENMOD by ∙B∙I∙K∙E∙R∙\nusage:\n\tRENMOD filename");
if( !(f = fopen(argv[1], "rb")) ) errorExit("Can't open the file!");
/* you could use
fscanf(f, "%s", fname);
instead of*/
for(p = fname;
(p - fname) < FNAME_SIZE;
p += ( (*p == ' ')|| /* this strange for(;;) */
(*p == '<')|| /* statement removes illegal */
(*p == '>')|| /* chars from fname */
(*p == '#')||
(*p == '.')||
(*p == '\0') )?0:1)
if( (*p = fgetc(f))==EOF )
errorExit("File is too short! (chiptune? :)");
/* but fscanf will (sometimes) truncate filename to the first space*/
fclose(f);
fname[FNAME_SIZE] = '\0';
strcat(fname, ".mod");
/* and now we must handle the same filenames - only 101 same names allowed*/
while( (f = fopen(fname, "r")) ){
fclose(f);
sprintf(&fname[FNAME_SIZE-2], "%02d", counter++);
fname[8]='.';
}
if(rename(argv[1], fname)) errorExit("Can't rename the file!");
}