aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-19 12:55:09 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-19 12:55:09 +0000
commitbeecc86c2b9c1f6ac2d399b24cf87a8418f0f043 (patch)
treeaa6f5f86f3dfe451ddf8ac12c19a0f18048b8120
parent05aaa5605fd3e6ea3e9976d27ebb854201b66cce (diff)
add variable alphabet
-rw-r--r--weasel.c19
1 files 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 <mutatationrate>] [-p <population>] [-d <display>] [target string]\n",
+ fprintf(stderr, "usage: %s [a <alphabet>] [-m <mutatationrate>] [-p <population>] [-d <display>] [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));