From ec835973b720cb249bc6a803ec4e0a44b1ab3dd9 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 2 Sep 2013 07:57:39 -0400 Subject: [PATCH 1/5] suppress compiler warnings --- undpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/undpu.c b/undpu.c index 79be834..3eed3c2 100755 --- a/undpu.c +++ b/undpu.c @@ -4,7 +4,6 @@ #include int main (int argc, char **argv){ - char name[FILENAME_MAX]; FILE *bob, *joe; int factor, thing; char output[FILENAME_MAX]; @@ -43,4 +42,5 @@ int main (int argc, char **argv){ thing = fgetc(bob); } } + return 0; } From ce867fb9960f5a007ae130c84ac151b5027b35b1 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 2 Sep 2013 08:00:10 -0400 Subject: [PATCH 2/5] check more carefully that the input file is valid dpu formst --- undpu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/undpu.c b/undpu.c index 3eed3c2..6cd3ce6 100755 --- a/undpu.c +++ b/undpu.c @@ -3,18 +3,20 @@ #include #include +const char compare_string[] = "DOUBLEPLUS UNZIP, FACTOR="; + int main (int argc, char **argv){ FILE *bob, *joe; - int factor, thing; + int factor, thing, i; char output[FILENAME_MAX]; 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; } } From 7cbae5d7e6d3b3630af4eebf230dbdf83f89cbbb Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 2 Sep 2013 08:05:13 -0400 Subject: [PATCH 3/5] make sure an input file is specified --- undpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/undpu.c b/undpu.c index 6cd3ce6..6aa532a 100755 --- a/undpu.c +++ b/undpu.c @@ -9,6 +9,10 @@ int main (int argc, char **argv){ FILE *bob, *joe; 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((bob = fopen(argv[1],"r"))==NULL){ fputs("That's no input file, THAT'S A SPACE STATION!\n",stderr); return EXIT_FAILURE; From 8351f8e943e16a09b1dac4e55a61e22472f29c61 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 2 Sep 2013 08:09:54 -0400 Subject: [PATCH 4/5] make sure there's a .dpu suffix on the input file --- undpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/undpu.c b/undpu.c index 6aa532a..0a706b2 100755 --- a/undpu.c +++ b/undpu.c @@ -13,6 +13,11 @@ int main (int argc, char **argv){ 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?", 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; From 08b4461acc56b5bb411c4ab2819b221db81f50dc Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 2 Sep 2013 08:35:30 -0400 Subject: [PATCH 5/5] added missing newline to error message --- undpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/undpu.c b/undpu.c index 0a706b2..a112e12 100755 --- a/undpu.c +++ b/undpu.c @@ -15,7 +15,7 @@ int main (int argc, char **argv){ } if(strlen(argv[1]) <= 4 || strcmp(argv[1] + strlen(argv[1]) - 4, ".dpu")) { - fputs("Where's the rest of the filename?", stderr); + fputs("Where's the rest of the filename?\n", stderr); return EXIT_FAILURE; } if((bob = fopen(argv[1],"r"))==NULL){