Compare commits

..

No commits in common. 'master' and 'master' have entirely different histories.

  1. 41
      dpu.c
  2. 29
      undpu.c

41
dpu.c

@ -2,42 +2,27 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <getopt.h>
int main (int argc, char **argv){ int main (int argc, char **argv){
char name[FILENAME_MAX]; char name[FILENAME_MAX];
FILE *bob,*joe,*moe; FILE *bob,*joe,*moe;
int out, thing, factor, arg, modifier; int thing, factor, arg;
out = 0; if(argc >= 3){
factor=0; char *end_char;
while((modifier=getopt(argc,argv,"0123456789c"))+1){ factor = strtol(argv[1], &end_char, 0);
switch(modifier){ if(!*(argv[1]) || *end_char)
case 'c': {
joe = stdout; fputs("I can haz number?\n", stderr);
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);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
arg = 2;
}else{
factor = 9;
arg = 1;
} }
if(factor==0){ if(argc<2){
factor=9;
}
argc-=optind;
argv+=optind;
arg=0;
if(argc<1){
fputs("I pity the fool who don't have an input file!\n",stderr); fputs("I pity the fool who don't have an input file!\n",stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(argc>1){
fputs("Be patient, one thing at a time!\n",stderr);
}
if(strlen(argv[arg]) >= FILENAME_MAX - 4) if(strlen(argv[arg]) >= FILENAME_MAX - 4)
{ {
fputs("It's a filename, not a novel.\n", stderr); fputs("It's a filename, not a novel.\n", stderr);
@ -49,12 +34,10 @@ int main (int argc, char **argv){
fputs("NO YOU FOOL, A REAL ONE!\n",stderr); fputs("NO YOU FOOL, A REAL ONE!\n",stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(!out){
if((joe = fopen(name,"w"))==NULL){ 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); 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; return EXIT_FAILURE;
} }
}
if((moe = fopen("/dev/urandom","r"))==NULL){ if((moe = fopen("/dev/urandom","r"))==NULL){
fputs("So, you aren't random enough. Annoying.\n",stderr); fputs("So, you aren't random enough. Annoying.\n",stderr);
return EXIT_FAILURE; return EXIT_FAILURE;

@ -2,39 +2,23 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <getopt.h>
const char compare_string[] = "DOUBLEPLUS UNZIP, FACTOR="; const char compare_string[] = "DOUBLEPLUS UNZIP, FACTOR=";
int main (int argc, char **argv){ int main (int argc, char **argv){
FILE *bob, *joe; FILE *bob, *joe;
int modifier, factor, thing, i; int factor, thing, i;
int out = 0;
char output[FILENAME_MAX]; char output[FILENAME_MAX];
while((modifier=getopt(argc,argv,"c"))+1){ if(argc < 2){
switch(modifier){
case 'c':
joe=stdout;
out = 1;
break;
default:
fprintf(stderr,"modifier=%d\n",modifier);
fputs("You're going to have to be clearer about what you want.\n",stderr);
return EXIT_FAILURE;
}
}
argc-=optind;
argv+=optind;
if(argc < 1){
fputs("I pity the fool who don't have an input file!\n",stderr); fputs("I pity the fool who don't have an input file!\n",stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(strlen(argv[0]) <= 4 || strcmp(argv[0] + strlen(argv[0]) - 4, ".dpu")) if(strlen(argv[1]) <= 4 || strcmp(argv[1] + strlen(argv[1]) - 4, ".dpu"))
{ {
fputs("Where's the rest of the filename?\n", stderr); fputs("Where's the rest of the filename?\n", stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if((bob = fopen(argv[0],"r"))==NULL){ if((bob = fopen(argv[1],"r"))==NULL){
fputs("That's no input file, THAT'S A SPACE STATION!\n",stderr); fputs("That's no input file, THAT'S A SPACE STATION!\n",stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -57,14 +41,11 @@ int main (int argc, char **argv){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
if(!out){ strncpy(output,argv[1],strlen(argv[1])-4);
strlcpy(output,argv[0],strlen(argv[0])-3);
fprintf(stderr,"%s",output);
if((joe = fopen(output,"w"))==NULL){ if((joe = fopen(output,"w"))==NULL){
fputs("Ummm, the output file doesn't work.\n",stderr); fputs("Ummm, the output file doesn't work.\n",stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}
while((thing=fgetc(bob))!=EOF){ while((thing=fgetc(bob))!=EOF){
fputc(thing,joe); fputc(thing,joe);
int i; int i;

Loading…
Cancel
Save