From dd8b6bb44aa38a45b466ba3bb473ca96471b6742 Mon Sep 17 00:00:00 2001 From: mestre Date: Fri, 26 Feb 2016 12:10:49 +0000 Subject: - 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 , 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! --- games/caesar/caesar.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'games/caesar') 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); -} -- cgit v1.2.3-59-g8ed1b