From 5d75087b8fdf1c7fbec78cc3b93a71d67561141f Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Thu, 20 Apr 2006 03:24:13 +0000 Subject: Clean up getopt stuff and use strtonum instead of atoi. OK jaredy@ --- games/tetris/tetris.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'games/tetris') diff --git a/games/tetris/tetris.c b/games/tetris/tetris.c index 65db7ddf0f6..4402d42958b 100644 --- a/games/tetris/tetris.c +++ b/games/tetris/tetris.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tetris.c,v 1.20 2004/07/10 07:26:24 deraadt Exp $ */ +/* $OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray Exp $ */ /* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */ /*- @@ -160,6 +160,7 @@ main(int argc, char *argv[]) char *keys; int level = 2; char key_write[6][10]; + const char *errstr; int ch, i, j; keys = "jkl pq"; @@ -169,7 +170,7 @@ main(int argc, char *argv[]) setegid(gid); classic = showpreview = 0; - while ((ch = getopt(argc, argv, "chk:l:ps")) != -1) + while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) switch(ch) { case 'c': /* @@ -184,8 +185,9 @@ main(int argc, char *argv[]) usage(); break; case 'l': - level = atoi(optarg); - if (level < MINLEVEL || level > MAXLEVEL) + level = (int)strtonum(optarg, MINLEVEL, MAXLEVEL, + &errstr); + if (errstr) errx(1, "level must be from %d to %d", MINLEVEL, MAXLEVEL); break; @@ -195,8 +197,6 @@ main(int argc, char *argv[]) case 's': showscores(0); exit(0); - case '?': - case 'h': default: usage(); } -- cgit v1.2.3