X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/6a2a60db41cc5b3db833740e9381e58f5270a775..4fa17c6f9afc7c76d0350d5d9e5996391aa18137:/sail/main.c diff --git a/sail/main.c b/sail/main.c index 1808be6c..0c9897f1 100644 --- a/sail/main.c +++ b/sail/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.7 2000/02/09 22:27:56 jsm Exp $ */ +/* $NetBSD: main.c,v 1.25 2009/03/14 23:51:35 dholland Exp $ */ /* * Copyright (c) 1983, 1993 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,34 +31,35 @@ #include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +__COPYRIGHT("@(#) Copyright (c) 1983, 1993\ + The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: main.c,v 1.7 2000/02/09 22:27:56 jsm Exp $"); +__RCSID("$NetBSD: main.c,v 1.25 2009/03/14 23:51:35 dholland Exp $"); #endif #endif /* not lint */ -#include "extern.h" +#include #include -#include +#include +#include #include #include +#include +#include +#include "extern.h" +#include "pathnames.h" +#include "restart.h" -int main __P((int, char **)); - -/*ARGSUSED*/ int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { char *p; - int i; + int a,i; int fd; gid = getgid(); @@ -74,28 +71,32 @@ main(argc, argv) exit(1); close(fd); - (void) srand(getpid()); + if (chdir(_PATH_SAILDIR) < 0) { + err(1, "%s", _PATH_SAILDIR); + } + + srandom((u_long)time(NULL)); + if ((p = strrchr(*argv, '/')) != NULL) p++; else p = *argv; + if (strcmp(p, "driver") == 0 || strcmp(p, "saildriver") == 0) mode = MODE_DRIVER; else if (strcmp(p, "sail.log") == 0) mode = MODE_LOGGER; else mode = MODE_PLAYER; - while ((p = *++argv) && *p == '-') - switch (p[1]) { + + while ((a = getopt(argc, argv, "dsxlb")) != -1) + switch (a) { case 'd': mode = MODE_DRIVER; break; case 's': mode = MODE_LOGGER; break; - case 'D': - debug++; - break; case 'x': randomize++; break; @@ -106,15 +107,20 @@ main(argc, argv) nobells++; break; default: - fprintf(stderr, "SAIL: Unknown flag %s.\n", p); - exit(1); + errx(1, "Usage: %s [-bdlsx] [scenario-number]", p); } + + argc -= optind; + argv += optind; + if (*argv) game = atoi(*argv); else game = -1; + if ((i = setjmp(restart)) != 0) mode = i; + switch (mode) { case MODE_PLAYER: return pl_main(); @@ -123,7 +129,7 @@ main(argc, argv) case MODE_LOGGER: return lo_main(); default: - fprintf(stderr, "SAIL: Unknown mode %d.\n", mode); + warnx("Unknown mode %d", mode); abort(); } /*NOTREACHED*/