diff options
author | mestre <mestre@cvs.openbsd.org> | 2016-02-26 12:10:50 +0000 |
---|---|---|
committer | mestre <mestre@cvs.openbsd.org> | 2016-02-26 12:10:50 +0000 |
commit | cc2254b06956f83e6b53b33fd1e6269c40045bd0 (patch) | |
tree | 5b3c0933b7d480f1eb3751a9f715a9d6b0d31e85 | |
parent | 2c51c428aaf261bd8a7d2c3b58e9b9d4cb137bf3 (diff) |
- Convert atoi(3) to strtonum(3)
- Remove lint-style comment
- Remove usage() since errors are now more informative (the usage is still
available in the manpage)
With this diff I made it accept 0 as rotation whereas before it didn't, but
alas if you use 0 then it defeats the whole purpose of the game.
Initial diff sent by Peter Williams <peterbw at gmail.com>, tweaked by me and
several hints and OK by tb@. I'm in desperate need of a coffee, thank you tb@
for making me notice that!
-rw-r--r-- | games/caesar/caesar.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/games/caesar/caesar.c b/games/caesar/caesar.c index 0266b1c57a2..f55cb221a52 100644 --- a/games/caesar/caesar.c +++ b/games/caesar/caesar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: caesar.c,v 1.18 2015/12/16 14:21:50 tb Exp $ */ +/* $OpenBSD: caesar.c,v 1.19 2016/02/26 12:10:49 mestre Exp $ */ /* * Copyright (c) 1989, 1993 @@ -62,14 +62,13 @@ double stdf[26] = { }; __dead void printit(int); -__dead void usage(void); - int main(int argc, char *argv[]) { int ch, i, nread; extern char *__progname; + const char *errstr; char *inbuf; int obs[26], try, winner; double dot, winnerdot; @@ -82,10 +81,11 @@ main(int argc, char *argv[]) printit(13); if (argc > 1) { - if ((i = atoi(argv[1]))) - printit(i); + i = strtonum(argv[1], 0, 25, &errstr); + if (errstr) + errx(1, "rotation is %s: %s", errstr, argv[1]); else - usage(); + printit(i); } if (!(inbuf = malloc(LINELENGTH))) @@ -129,25 +129,14 @@ main(int argc, char *argv[]) putchar(ROTATE(ch, winner)); } printit(winner); - /* NOT REACHED */ } void printit(int rot) { int ch; - - if ((rot < 0) || ( rot >= 26)) - errx(1, "bad rotation value"); while ((ch = getchar()) != EOF) putchar(ROTATE(ch, rot)); exit(0); } - -void -usage(void) -{ - fprintf(stderr,"usage: caesar [rotation]\n"); - exit(1); -} |