X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/b2ca333c4ad541145141d538923e93ec3464e29d..dd096191dcfacdcbd63dabb28e4aeb1c79cfafae:/trek/dumpgame.c diff --git a/trek/dumpgame.c b/trek/dumpgame.c index b512d8e9..83c5e6ff 100644 --- a/trek/dumpgame.c +++ b/trek/dumpgame.c @@ -1,4 +1,4 @@ -/* $NetBSD: dumpgame.c,v 1.3 1995/04/22 10:58:46 cgd Exp $ */ +/* $NetBSD: dumpgame.c,v 1.11 2007/12/15 19:44:44 perry Exp $ */ /* * Copyright (c) 1980, 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. * @@ -33,15 +29,20 @@ * SUCH DAMAGE. */ +#include #ifndef lint #if 0 static char sccsid[] = "@(#)dumpgame.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: dumpgame.c,v 1.3 1995/04/22 10:58:46 cgd Exp $"; +__RCSID("$NetBSD: dumpgame.c,v 1.11 2007/12/15 19:44:44 perry Exp $"); #endif #endif /* not lint */ -# include "trek.h" +#include +#include +#include +#include +#include "trek.h" /*** THIS CONSTANT MUST CHANGE AS THE DATA SPACES CHANGE ***/ # define VERSION 2 @@ -52,19 +53,21 @@ struct dump int count; }; +static int readdump(int); + struct dump Dump_template[] = { - (char *)&Ship, sizeof (Ship), - (char *)&Now, sizeof (Now), - (char *)&Param, sizeof (Param), - (char *)&Etc, sizeof (Etc), - (char *)&Game, sizeof (Game), - (char *)Sect, sizeof (Sect), - (char *)Quad, sizeof (Quad), - (char *)&Move, sizeof (Move), - (char *)Event, sizeof (Event), - 0 + { (char *)&Ship, sizeof (Ship) }, + { (char *)&Now, sizeof (Now) }, + { (char *)&Param, sizeof (Param) }, + { (char *)&Etc, sizeof (Etc) }, + { (char *)&Game, sizeof (Game) }, + { (char *)Sect, sizeof (Sect) }, + { (char *)Quad, sizeof (Quad) }, + { (char *)&Move, sizeof (Move) }, + { (char *)Event, sizeof (Event) }, + { NULL, 0 } }; /* @@ -77,15 +80,20 @@ struct dump Dump_template[] = ** output change. */ -dumpgame() +/*ARGSUSED*/ +void +dumpgame(v) + int v __unused; { - int version; - register int fd; - register struct dump *d; - register int i; + int version; + int fd; + struct dump *d; + int i; - if ((fd = creat("trek.dump", 0644)) < 0) - return (printf("cannot dump\n")); + if ((fd = creat("trek.dump", 0644)) < 0) { + warn("cannot open `trek.dump'"); + return; + } version = VERSION; write(fd, &version, sizeof version); @@ -112,18 +120,20 @@ dumpgame() ** Return value is zero for success, one for failure. */ +int restartgame() { - register int fd; + int fd; int version; - if ((fd = open("trek.dump", 0)) < 0 || + if ((fd = open("trek.dump", O_RDONLY)) < 0 || read(fd, &version, sizeof version) != sizeof version || version != VERSION || readdump(fd)) { printf("cannot restart\n"); - close(fd); + if (fd >= 0) + close(fd); return (1); } @@ -141,13 +151,14 @@ restartgame() ** Returns zero for success, one for failure. */ +static int readdump(fd1) int fd1; { - register int fd; - register struct dump *d; - register int i; - int junk; + int fd; + struct dump *d; + int i; + long junk; fd = fd1;