#include #include #include #include #include const char compare_string[] = "DOUBLEPLUS UNZIP, FACTOR="; int main (int argc, char **argv){ FILE *bob, *joe; int modifier, factor, thing, i; int out = 0; char output[FILENAME_MAX]; while((modifier=getopt(argc,argv,"c"))+1){ 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); return EXIT_FAILURE; } if(strlen(argv[0]) <= 4 || strcmp(argv[0] + strlen(argv[0]) - 4, ".dpu")) { fputs("Where's the rest of the filename?\n", stderr); return EXIT_FAILURE; } if((bob = fopen(argv[0],"r"))==NULL){ fputs("That's no input file, THAT'S A SPACE STATION!\n",stderr); return EXIT_FAILURE; } for(i = 0; compare_string[i]; i++) { thing = fgetc(bob); if(thing != compare_string[i]) { fputs("You suck! That's not a DPU file!\n", stderr); return EXIT_FAILURE; } } factor=0; for(;;){ thing=fgetc(bob); if(isdigit(thing)){ factor=(factor*10)+(thing-'0'); }else if(thing==';'){ break; }else{ fputs("You should make it work!\n",stderr); return EXIT_FAILURE; } } if(!out){ strlcpy(output,argv[0],strlen(argv[0])-3); fprintf(stderr,"%s",output); if((joe = fopen(output,"w"))==NULL){ fputs("Ummm, the output file doesn't work.\n",stderr); return EXIT_FAILURE; } } while((thing=fgetc(bob))!=EOF){ fputc(thing,joe); int i; for(i=0;i