|
|
|
@ -2,59 +2,42 @@ |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
#include <getopt.h> |
|
|
|
|
|
|
|
|
|
int main (int argc, char **argv){ |
|
|
|
|
char name[FILENAME_MAX]; |
|
|
|
|
FILE *bob,*joe,*moe; |
|
|
|
|
int out, thing, factor, arg, modifier; |
|
|
|
|
out = 0; |
|
|
|
|
factor=0; |
|
|
|
|
while((modifier=getopt(argc,argv,"0123456789c"))+1){ |
|
|
|
|
switch(modifier){ |
|
|
|
|
case 'c': |
|
|
|
|
joe = stdout; |
|
|
|
|
out = 1; |
|
|
|
|
break; |
|
|
|
|
case '0': case '1': case '2': case '3': case '4': |
|
|
|
|
case '5': case '6': case '7': case '8': case '9': |
|
|
|
|
factor=factor*10+modifier-'0'; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
fputs("You're going to have to be clearer about what you want.\n",stderr); |
|
|
|
|
int thing, factor, arg; |
|
|
|
|
if(argc >= 3){ |
|
|
|
|
char *end_char; |
|
|
|
|
factor = strtol(argv[1], &end_char, 0); |
|
|
|
|
if(!*(argv[1]) || *end_char) |
|
|
|
|
{ |
|
|
|
|
fputs("I can haz number?\n", stderr); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
} |
|
|
|
|
arg = 2; |
|
|
|
|
}else{ |
|
|
|
|
factor = 9; |
|
|
|
|
arg = 1; |
|
|
|
|
} |
|
|
|
|
if(factor==0){ |
|
|
|
|
factor=9; |
|
|
|
|
} |
|
|
|
|
argc-=optind; |
|
|
|
|
argv+=optind; |
|
|
|
|
arg=0; |
|
|
|
|
if(argc<1){ |
|
|
|
|
if(argc<2){ |
|
|
|
|
fputs("I pity the fool who don't have an input file!\n",stderr); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
} |
|
|
|
|
if(argc>1){ |
|
|
|
|
fputs("Be patient, one thing at a time!\n",stderr); |
|
|
|
|
} |
|
|
|
|
if(strlen(argv[arg]) >= FILENAME_MAX - 4) |
|
|
|
|
{ |
|
|
|
|
fputs("It's a filename, not a novel.\n", stderr); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
} |
|
|
|
|
strlcpy(name,argv[arg],sizeof(name)); |
|
|
|
|
strlcat(name,".dpu",sizeof(name)); |
|
|
|
|
strlcat(name,".dpu",sizeof(name));
|
|
|
|
|
if((bob = fopen(argv[arg],"r"))==NULL){ |
|
|
|
|
fputs("NO YOU FOOL, A REAL ONE!\n",stderr); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
} |
|
|
|
|
if(!out){ |
|
|
|
|
if((joe = fopen(name,"w"))==NULL){ |
|
|
|
|
fputs("Ummm, you seem to have an unwritable file or directory or something silly called the output file, this is dumb. Please stop.\n",stderr); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
if((joe = fopen(name,"w"))==NULL){ |
|
|
|
|
fputs("Ummm, you seem to have an unwritable file or directory or something silly called the output file, this is dumb. Please stop.\n",stderr); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
}
|
|
|
|
|
if((moe = fopen("/dev/urandom","r"))==NULL){ |
|
|
|
|
fputs("So, you aren't random enough. Annoying.\n",stderr); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|