X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/57a75ab7b9a0f4999cae7c0fa5acb46f230f38f2..HEAD:/sail/main.c diff --git a/sail/main.c b/sail/main.c index 5db425de..fdb9d830 100644 --- a/sail/main.c +++ b/sail/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.11 2000/11/30 22:02:20 jwise Exp $ */ +/* $NetBSD: main.c,v 1.26 2010/08/06 09:14:40 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,32 +31,39 @@ #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.11 2000/11/30 22:02:20 jwise Exp $"); +__RCSID("$NetBSD: main.c,v 1.26 2010/08/06 09:14:40 dholland Exp $"); #endif #endif /* not lint */ -#include "extern.h" +#include +#include #include -#include +#include +#include +#include #include #include +#include +#include +#include "extern.h" +#include "pathnames.h" +#include "restart.h" -int main (int, char **); - -int -main(int argc, char **argv) +static void +initialize(void) { - char *p; - int a,i; int fd; + const char *name; + struct passwd *pw; + char *s; gid = getgid(); egid = getegid(); @@ -71,7 +74,48 @@ main(int argc, char **argv) exit(1); close(fd); - srand(getpid()); + if (chdir(_PATH_SAILDIR) < 0) { + err(1, "%s", _PATH_SAILDIR); + } + + srandom((u_long)time(NULL)); + + name = getenv("SAILNAME"); + if (name != NULL && *name != '\0') { + strlcpy(myname, name, sizeof(myname)); + } else { + pw = getpwuid(getuid()); + if (pw != NULL) { + strlcpy(myname, pw->pw_gecos, sizeof(myname)); + /* trim to just the realname */ + s = strchr(myname, ','); + if (s != NULL) { + *s = '\0'; + } + /* use just the first name */ + s = strchr(myname, ' '); + if (s != NULL) { + *s = '\0'; + } + /* should really do &-expansion properly */ + if (!strcmp(myname, "&")) { + strlcpy(myname, pw->pw_name, sizeof(myname)); + myname[0] = toupper((unsigned char)myname[0]); + } + } + } + if (*myname == '\0') { + strlcpy(myname, "Anonymous", sizeof(myname)); + } +} + +int +main(int argc, char **argv) +{ + char *p; + int a, i; + + initialize(); if ((p = strrchr(*argv, '/')) != NULL) p++; @@ -85,7 +129,7 @@ main(int argc, char **argv) else mode = MODE_PLAYER; - while (a = getopt(argc, argv, "dsDxlb")) + while ((a = getopt(argc, argv, "dsxlb")) != -1) switch (a) { case 'd': mode = MODE_DRIVER; @@ -93,23 +137,22 @@ main(int argc, char **argv) case 's': mode = MODE_LOGGER; break; - case 'D': - debug++; - break; case 'x': - randomize++; + randomize = true; break; case 'l': - longfmt++; + longfmt = true; break; case 'b': - nobells++; + nobells = true; 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 @@ -120,13 +163,16 @@ main(int argc, char **argv) switch (mode) { case MODE_PLAYER: - return pl_main(); + initscreen(); + startup(); + cleanupscreen(); + return 0; case MODE_DRIVER: return dr_main(); case MODE_LOGGER: return lo_main(); default: - fprintf(stderr, "SAIL: Unknown mode %d.\n", mode); + warnx("Unknown mode %d", mode); abort(); } /*NOTREACHED*/