diff options
author | mestre <mestre@openbsd.org> | 2016-02-26 12:10:49 +0000 |
---|---|---|
committer | mestre <mestre@openbsd.org> | 2016-02-26 12:10:49 +0000 |
commit | dd8b6bb44aa38a45b466ba3bb473ca96471b6742 (patch) | |
tree | 44cb335b35cea2135db6723f50c0923a19c1a913 /games/caesar | |
parent | Rename and move x86 calllframe definitions in <machine/frame.h> to use (diff) | |
download | wireguard-openbsd-dd8b6bb44aa38a45b466ba3bb473ca96471b6742.tar.xz wireguard-openbsd-dd8b6bb44aa38a45b466ba3bb473ca96471b6742.zip |
- 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!
Diffstat (limited to 'games/caesar')
-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); -} |