Merge pull request #3 from jlamothe/undpu-infile-check

undpu Sanity Checking on Input File
master
silverwizard 11 years ago
commit a1f598255e
  1. 23
      undpu.c

@ -3,19 +3,29 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
const char compare_string[] = "DOUBLEPLUS UNZIP, FACTOR=";
int main (int argc, char **argv){ int main (int argc, char **argv){
char name[FILENAME_MAX];
FILE *bob, *joe; FILE *bob, *joe;
int factor, thing; int factor, thing, i;
char output[FILENAME_MAX]; char output[FILENAME_MAX];
if(argc < 2){
fputs("I pity the fool who don't have an input file!\n",stderr);
return EXIT_FAILURE;
}
if(strlen(argv[1]) <= 4 || strcmp(argv[1] + strlen(argv[1]) - 4, ".dpu"))
{
fputs("Where's the rest of the filename?\n", stderr);
return EXIT_FAILURE;
}
if((bob = fopen(argv[1],"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;
} }
while(thing != '='){ for(i = 0; compare_string[i]; i++) {
thing=fgetc(bob); thing = fgetc(bob);
if(thing==EOF){ if(thing != compare_string[i]) {
fputs("You suck! That's not a DPU file!\n",stderr); fputs("You suck! That's not a DPU file!\n", stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
@ -43,4 +53,5 @@ int main (int argc, char **argv){
thing = fgetc(bob); thing = fgetc(bob);
} }
} }
return 0;
} }

Loading…
Cancel
Save