From beecc86c2b9c1f6ac2d399b24cf87a8418f0f043 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 19 Oct 2009 12:55:09 +0000 Subject: add variable alphabet --- weasel.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/weasel.c b/weasel.c index d0cb58d..fb86a2a 100644 --- a/weasel.c +++ b/weasel.c @@ -33,12 +33,15 @@ int display = 1000; #if 0 const char defaim[] = "METHINKS IT IS LIKE A WEASEL"; -const char alphabet[] = " ABCDEEFGHIJKLMNOPQRSTUVWXYZ"; +const char defalpha[] = " ABCDEEFGHIJKLMNOPQRSTUVWXYZ"; #else const char defaim[] = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK 1234567890 TIMES."; -const char alphabet[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~"; +const char defalpha[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~"; #endif +const char *alphabet; +int alphalen; + const char *aim; struct creature { @@ -51,7 +54,7 @@ struct creature { char rndchar() { - return alphabet[random() % (sizeof(alphabet) - 1)]; + return alphabet[random() % alphalen]; } float @@ -198,7 +201,7 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-m ] [-p ] [-d ] [target string]\n", + fprintf(stderr, "usage: %s [a ] [-m ] [-p ] [-d ] [target string]\n", __progname); exit(1); @@ -212,8 +215,13 @@ main(int argc, char **argv) pthread_t dummy; int i, c, n; - while ((c = getopt(argc, argv, "m:p:d:")) != -1) + alphabet = defalpha; + + while ((c = getopt(argc, argv, "a:m:p:d:")) != -1) switch (c) { + case 'a': + alphabet = strdup(optarg); + break; case 'm': i = atoi(optarg); if (i <= 0) @@ -241,6 +249,7 @@ main(int argc, char **argv) argv += optind; aim = argc ? strdup(*argv) : defaim; + alphalen = strlen(alphabet); initscr(); srandom(time(NULL)); -- cgit v1.2.3