fprintf(stderr,"usage: inputfile k m coding_technique w (packetsize) (buffersize)\n");
fprintf(stderr,"\nChoose one of the following coding techniques: \nreed_sol_van, \nreed_sol_r6_op, \ncauchy_orig, \ncauchy_good, \nliberation, \nblaum_roth, \nliber8tion");
/* Setting of coding technique and error checking */
if(strcmp(argv[4],"no_coding")==0){
tech=No_Coding;
}
elseif(strcmp(argv[4],"reed_sol_van")==0){
tech=Reed_Sol_Van;
if(w!=8&&w!=16&&w!=32){
fprintf(stderr,"w must be one of {8, 16, 32}\n");
exit(0);
}
}
elseif(strcmp(argv[4],"reed_sol_r6_op")==0){
if(m!=2){
fprintf(stderr,"m must be equal to 2\n");
exit(0);
}
if(w!=8&&w!=16&&w!=32){
fprintf(stderr,"w must be one of {8, 16, 32}\n");
exit(0);
}
tech=Reed_Sol_R6_Op;
}
elseif(strcmp(argv[4],"cauchy_orig")==0){
tech=Cauchy_Orig;
if(packetsize==0){
fprintf(stderr,"Must include packetsize.\n");
exit(0);
}
}
elseif(strcmp(argv[4],"cauchy_good")==0){
tech=Cauchy_Good;
if(packetsize==0){
fprintf(stderr,"Must include packetsize.\n");
exit(0);
}
}
elseif(strcmp(argv[4],"liberation")==0){
if(k>w){
fprintf(stderr,"k must be less than or equal to w\n");
exit(0);
}
if(w<=2||!(w%2)||!is_prime(w)){
fprintf(stderr,"w must be greater than two and w must be prime\n");
exit(0);
}
if(packetsize==0){
fprintf(stderr,"Must include packetsize.\n");
exit(0);
}
if((packetsize%(sizeof(int)))!=0){
fprintf(stderr,"packetsize must be a multiple of sizeof(int)\n");
exit(0);
}
tech=Liberation;
}
elseif(strcmp(argv[4],"blaum_roth")==0){
if(k>w){
fprintf(stderr,"k must be less than or equal to w\n");
exit(0);
}
if(w<=2||!((w+1)%2)||!is_prime(w+1)){
fprintf(stderr,"w must be greater than two and w+1 must be prime\n");
exit(0);
}
if(packetsize==0){
fprintf(stderr,"Must include packetsize.\n");
exit(0);
}
if((packetsize%(sizeof(int)))!=0){
fprintf(stderr,"packetsize must be a multiple of sizeof(int)\n");
exit(0);
}
tech=Blaum_Roth;
}
elseif(strcmp(argv[4],"liber8tion")==0){
if(packetsize==0){
fprintf(stderr,"Must include packetsize\n");
exit(0);
}
if(w!=8){
fprintf(stderr,"w must equal 8\n");
exit(0);
}
if(m!=2){
fprintf(stderr,"m must equal 2\n");
exit(0);
}
if(k>w){
fprintf(stderr,"k must be less than or equal to w\n");
exit(0);
}
tech=Liber8tion;
}
else{
fprintf(stderr,"Not a valid coding technique. Choose one of the following: reed_sol_van, reed_sol_r6_op, cauchy_orig, cauchy_good, liberation, blaum_roth, liber8tion, no_coding\n");
exit(0);
}
/* Set global variable method for signal handler */
method=tech;
/* Get current working directory for construction of file names */
curdir=(char*)malloc(sizeof(char)*1000);
getcwd(curdir,1000);
if(argv[1][0]!='-'){
/* Open file and error check */
fp=fopen(argv[1],"rb");
if(fp==NULL){
fprintf(stderr,"Unable to open file.\n");
exit(0);
}
/* Create Coding directory */
i=mkdir("Coding",S_IRWXU);
if(i==-1&&errno!=EEXIST){
fprintf(stderr,"Unable to create Coding directory.\n");
exit(0);
}
/* Determine original size of file */
stat(argv[1],&status);
size=status.st_size;
}else{
if(sscanf(argv[1]+1,"%d",&size)!=1||size<=0){
fprintf(stderr,"Files starting with '-' should be sizes for randomly created input\n");
exit(1);
}
fp=NULL;
srand48(time(0));
}
newsize=size;
/* Find new size by determining next closest multiple */
if(packetsize!=0){
if(size%(k*w*packetsize*sizeof(int))!=0){
while(newsize%(k*w*packetsize*sizeof(int))!=0)
newsize++;
}
}
else{
if(size%(k*w*sizeof(int))!=0){
while(newsize%(k*w*sizeof(int))!=0)
newsize++;
}
}
if(buffersize!=0){
while(newsize%buffersize!=0){
newsize++;
}
}
/* Determine size of k+m files */
blocksize=newsize/k;
/* Allow for buffersize and determine number of read-ins */
if(size>buffersize&&buffersize!=0){
if(newsize%buffersize!=0){
readins=newsize/buffersize;
}
else{
readins=newsize/buffersize;
}
block=(char*)malloc(sizeof(char)*buffersize);
blocksize=buffersize/k;
}
else{
readins=1;
buffersize=size;
block=(char*)malloc(sizeof(char)*newsize);
}
/* Break inputfile name into the filename and extension */