From 257bd5555bee87b68c79c3bb81c42a445f6d301a Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 24 Nov 2012 20:14:35 +0000 Subject: Add -randomseed git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1779 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- generator/ppmpat.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'generator/ppmpat.c') diff --git a/generator/ppmpat.c b/generator/ppmpat.c index c4ceb797..100b4978 100644 --- a/generator/ppmpat.c +++ b/generator/ppmpat.c @@ -41,6 +41,8 @@ struct cmdlineInfo { pattern basePattern; unsigned int width; unsigned int height; + unsigned int randomseed; + unsigned int randomseedSpec; }; @@ -71,16 +73,28 @@ parseCommandLine(int argc, const char ** argv, MALLOCARRAY_NOFAIL(option_def, 100); option_def_index = 0; /* incremented by OPTENTRY */ - OPTENT3(0, "gingham2", OPT_FLAG, NULL, &gingham2, 0); - OPTENT3(0, "g2", OPT_FLAG, NULL, &gingham2, 0); - OPTENT3(0, "gingham3", OPT_FLAG, NULL, &gingham3, 0); - OPTENT3(0, "g3", OPT_FLAG, NULL, &gingham3, 0); - OPTENT3(0, "madras", OPT_FLAG, NULL, &madras, 0); - OPTENT3(0, "tartan", OPT_FLAG, NULL, &tartan, 0); - OPTENT3(0, "poles", OPT_FLAG, NULL, &poles, 0); - OPTENT3(0, "squig", OPT_FLAG, NULL, &squig, 0); - OPTENT3(0, "camo", OPT_FLAG, NULL, &camo, 0); - OPTENT3(0, "anticamo", OPT_FLAG, NULL, &anticamo, 0); + OPTENT3(0, "gingham2", OPT_FLAG, NULL, + &gingham2, 0); + OPTENT3(0, "g2", OPT_FLAG, NULL, + &gingham2, 0); + OPTENT3(0, "gingham3", OPT_FLAG, NULL, + &gingham3, 0); + OPTENT3(0, "g3", OPT_FLAG, NULL, + &gingham3, 0); + OPTENT3(0, "madras", OPT_FLAG, NULL, + &madras, 0); + OPTENT3(0, "tartan", OPT_FLAG, NULL, + &tartan, 0); + OPTENT3(0, "poles", OPT_FLAG, NULL, + &poles, 0); + OPTENT3(0, "squig", OPT_FLAG, NULL, + &squig, 0); + OPTENT3(0, "camo", OPT_FLAG, NULL, + &camo, 0); + OPTENT3(0, "anticamo", OPT_FLAG, NULL, + &anticamo, 0); + OPTENT3(0, "randomseed", OPT_UINT, &cmdlineP->randomseed, + &cmdlineP->randomseedSpec, 0); opt.opt_table = option_def; opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ @@ -136,6 +150,7 @@ parseCommandLine(int argc, const char ** argv, if (cmdlineP->height < 1) pm_error("Height must be at least 1 pixel"); } + free(option_def); } @@ -1122,7 +1137,8 @@ main(int argc, const char ** argv) { validateComputableDimensions(cmdline.width, cmdline.height); - srand(pm_randseed()); + srand(cmdline.randomseedSpec ? cmdline.randomseed : pm_randseed()); + pixels = ppm_allocarray(cmdline.width, cmdline.height); switch (cmdline.basePattern) { @@ -1170,3 +1186,5 @@ main(int argc, const char ** argv) { return 0; } + + -- cgit 1.4.1