summaryrefslogtreecommitdiffstats
path: root/robots
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2009-08-05 04:03:47 +0000
committerdholland <dholland@NetBSD.org>2009-08-05 04:03:47 +0000
commita7345209258b0ffde396d087589510b8e7c3bb50 (patch)
tree06125e5437890fa3c90156ad8cd59589fd1aa64f /robots
parent534eafe581e5ce9b0b32d42642949f61f9cc61cf (diff)
downloadbsdgames-darwin-a7345209258b0ffde396d087589510b8e7c3bb50.tar.gz
bsdgames-darwin-a7345209258b0ffde396d087589510b8e7c3bb50.tar.zst
bsdgames-darwin-a7345209258b0ffde396d087589510b8e7c3bb50.zip
Use getopt instead of hand-rolled options code. Document all the arguments
and options. Don't allow the previously undocumented method to change the maximum number of scores kept per user to be used on the system-wide high score file. Sort options list in the man page. Bump its date.
Diffstat (limited to 'robots')
-rw-r--r--robots/main.c120
-rw-r--r--robots/robots.643
2 files changed, 87 insertions, 76 deletions
diff --git a/robots/main.c b/robots/main.c
index 9868403a..75a4555a 100644
--- a/robots/main.c
+++ b/robots/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.29 2009/07/20 06:43:18 dholland Exp $ */
+/* $NetBSD: main.c,v 1.30 2009/08/05 04:03:47 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: main.c,v 1.29 2009/07/20 06:43:18 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.30 2009/08/05 04:03:47 dholland Exp $");
#endif
#endif /* not lint */
@@ -58,13 +58,15 @@ extern const char *Scorefile;
extern int Max_per_uid;
int
-main(int ac, char **av)
+main(int argc, char **argv)
{
- const char *sp;
- bool bad_arg;
+ const char *word;
bool show_only;
int score_wfd; /* high score writable file descriptor */
int score_err = 0; /* hold errno from score file open */
+ int maximum = 0;
+ char ch;
+ int i;
score_wfd = open(Scorefile, O_RDWR);
if (score_wfd < 0)
@@ -77,64 +79,60 @@ main(int ac, char **av)
show_only = false;
Num_games = 1;
- if (ac > 1) {
- bad_arg = false;
- for (++av; ac > 1 && *av[0]; av++, ac--)
- if (av[0][0] != '-')
- if (isdigit((unsigned char)av[0][0]))
- Max_per_uid = atoi(av[0]);
- else {
- Scorefile = av[0];
- if (score_wfd >= 0)
- close(score_wfd);
- score_wfd = open(Scorefile, O_RDWR);
- if (score_wfd < 0)
- score_err = errno;
+
+ while ((ch = getopt(argc, argv, "Aajnrst")) != -1) {
+ switch (ch) {
+ case 'A':
+ Auto_bot = true;
+ break;
+ case 'a':
+ Start_level = 4;
+ break;
+ case 'j':
+ Jump = true;
+ break;
+ case 'n':
+ Num_games++;
+ break;
+ case 'r':
+ Real_time = true;
+ break;
+ case 's':
+ show_only = true;
+ break;
+ case 't':
+ Teleport = true;
+ break;
+ default:
+ errx(1,
+ "Usage: robots [-Aajnrst] [maximum] [scorefile]");
+ break;
+ }
+ }
+
+ for (i = optind; i < argc; i++) {
+ word = argv[i];
+ if (isdigit((unsigned char)word[0])) {
+ maximum = atoi(word);
+ } else {
+ Scorefile = word;
+ Max_per_uid = maximum;
+ if (score_wfd >= 0)
+ close(score_wfd);
+ score_wfd = open(Scorefile, O_RDWR);
+ if (score_wfd < 0)
+ score_err = errno;
#ifdef FANCY
- sp = strrchr(Scorefile, '/');
- if (sp == NULL)
- sp = Scorefile;
- if (strcmp(sp, "pattern_roll") == 0)
- Pattern_roll = true;
- else if (strcmp(sp, "stand_still") == 0)
- Stand_still = true;
- if (Pattern_roll || Stand_still)
- Teleport = true;
+ word = strrchr(Scorefile, '/');
+ if (word == NULL)
+ word = Scorefile;
+ if (strcmp(word, "pattern_roll") == 0)
+ Pattern_roll = true;
+ else if (strcmp(word, "stand_still") == 0)
+ Stand_still = true;
+ if (Pattern_roll || Stand_still)
+ Teleport = true;
#endif
- }
- else
- for (sp = &av[0][1]; *sp; sp++)
- switch (*sp) {
- case 'A':
- Auto_bot = true;
- break;
- case 's':
- show_only = true;
- break;
- case 'r':
- Real_time = true;
- break;
- case 'a':
- Start_level = 4;
- break;
- case 'n':
- Num_games++;
- break;
- case 'j':
- Jump = true;
- break;
- case 't':
- Teleport = true;
- break;
-
- default:
- fprintf(stderr, "robots: unknown option: %c\n", *sp);
- bad_arg = true;
- break;
- }
- if (bad_arg) {
- exit(1);
- /* NOTREACHED */
}
}
diff --git a/robots/robots.6 b/robots/robots.6
index ab3b35ca..e07bc3f9 100644
--- a/robots/robots.6
+++ b/robots/robots.6
@@ -1,4 +1,4 @@
-.\" $NetBSD: robots.6,v 1.14 2009/04/09 03:52:54 joerg Exp $
+.\" $NetBSD: robots.6,v 1.15 2009/08/05 04:03:47 dholland Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)robots.6 8.1 (Berkeley) 5/31/93
.\"
-.Dd May 31, 1993
+.Dd August 4, 2009
.Dt ROBOTS 6
.Os
.Sh NAME
@@ -37,7 +37,8 @@
.Nd fight off villainous robots
.Sh SYNOPSIS
.Nm
-.Op Fl Asjtan
+.Op Fl Aajnrst
+.Op Ar maximum
.Op Ar scorefile
.Sh DESCRIPTION
.Nm
@@ -115,35 +116,47 @@ you take the risk of dying by miscalculation.
Only five scores are allowed per user on the score file.
If you make it into the score file, you will be shown the list at the end
of the game.
-If an alternative score file is specified, that will be used instead of the
-standard file for scores.
+If an alternative score file is named on the command line, that file
+will be used instead of the standard file for scores.
+The score file must be created empty beforehand, e.g. with
+.Xr touch 1 .
+If the argument
+.Ar maximum ,
+which must be a number, is provided when a score file is first used,
+the value given will be used as the maximum number of scores to keep
+per user instead of the default five.
+This value is a property of the score file and cannot be changed later.
.Pp
The options are
.Bl -tag -width indent
-.It Fl s
-Don't play, just show the score file.
+.It Fl A
+Auto-bot mode.
+Lets the game play itself.
+.It Fl a
+Advance into the higher levels directly, skipping the lower, easier levels.
.It Fl j
Jump,
.Em i.e. ,
when you run, don't show any intermediate positions; only show things at
the end.
This is useful on slow terminals.
+.It Fl n
+Increase the number of games played by one; that is, automatically
+choose to play again one time per usage of this option.
+.It Fl r
+Play in real time; that is, if you do nothing for a few seconds the
+game will assume you meant to do nothing and move the robots.
+.It Fl s
+Don't play, just show the score file.
.It Fl t
Teleport automatically when you have no other option.
This is a little disconcerting until you get used to it, and then it is
very nice.
-.It Fl a
-Advance into the higher levels directly, skipping the lower, easier levels.
-.It Fl A
-Auto-bot mode.
-Lets the game play itself.
-.It Fl n
-Increase the number of games played by one.
.El
.Sh FILES
.Bl -tag -width /var/games/robots_roll -compact
.It Pa /var/games/robots_roll
-the score file
+The score file.
.El
.Sh AUTHORS
.An Ken Arnold