From: Ian Jackson Date: Thu, 21 Feb 2013 15:41:51 +0000 (+0000) Subject: Break out function "execute" X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8a5af80fee67ccad0d5109e3bbb1eb467ca82ff2;p=vbig.git Break out function "execute" Code motion and incidental changes: - Make the 2nd half of main into its own function - Make most of the arg variables have file scope and static duration No functional change. Signed-off-by: Ian Jackson --- diff --git a/vbig.cc b/vbig.cc index 3a35728..40e7875 100644 --- a/vbig.cc +++ b/vbig.cc @@ -103,10 +103,15 @@ static void flushCache(FILE *fp) { #endif } +static void execute(mode_type mode); + +static const char *seed = "hexapodia as the key insight"; +static const char *path; +static bool flush = false; +static long long size; + int main(int argc, char **argv) { - const char *seed = "hexapodia as the key insight"; mode_type mode = NONE; - bool flush = false; int n; while((n = getopt_long(argc, argv, "+s:vcfhV", opts, 0)) >= 0) { switch(n) { @@ -128,8 +133,7 @@ int main(int argc, char **argv) { fatal(0, "excess arguments"); if(argc < (mode == VERIFY ? 1 : 2)) fatal(0, "insufficient arguments"); - const char *path = argv[0]; - long long size; + path = argv[0]; if(argc > 1) { errno = 0; char *end; @@ -152,6 +156,11 @@ int main(int argc, char **argv) { fatal(errno, "stat %s", path); size = sb.st_size; } + execute(mode); + return 0; +} + +static void execute(mode_type mode) { Arcfour rng(seed, strlen(seed)); FILE *fp = fopen(path, mode == VERIFY ? "rb" : "wb"); if(!fp) @@ -196,5 +205,4 @@ int main(int argc, char **argv) { } if(fclose(fp) < 0) fatal(errno, "%s", path); - return 0; }