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

undpu Sanity Checking on Input File
remotes/1720846149120324653/tmp_refs/heads/master
silverwizard 11 years ago
commit a1f598255e
  1. 23
      undpu.c

@ -3,19 +3,29 @@
#include <stdio.h>
#include <string.h>
const char compare_string[] = "DOUBLEPLUS UNZIP, FACTOR=";
int main (int argc, char **argv){
char name[FILENAME_MAX];
FILE *bob, *joe;
int factor, thing;
int factor, thing, i;
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){
fputs("That's no input file, THAT'S A SPACE STATION!\n",stderr);
return EXIT_FAILURE;
}
while(thing != '='){
thing=fgetc(bob);
if(thing==EOF){
fputs("You suck! That's not a DPU file!\n",stderr);
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;
}
}
@ -43,4 +53,5 @@ int main (int argc, char **argv){
thing = fgetc(bob);
}
}
return 0;
}

Loading…
Cancel
Save