2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)dumpgame.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/trek/dumpgame.c,v 1.6 1999/11/30 03:49:46 billf Exp $
31 * $DragonFly: src/games/trek/dumpgame.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
38 /*** THIS CONSTANT MUST CHANGE AS THE DATA SPACES CHANGE ***/
46 static bool readdump(int);
48 struct dump Dump_template
[] = {
49 { (char *)&Ship
, sizeof (Ship
) },
50 { (char *)&Now
, sizeof (Now
) },
51 { (char *)&Param
, sizeof (Param
) },
52 { (char *)&Etc
, sizeof (Etc
) },
53 { (char *)&Game
, sizeof (Game
) },
54 { (char *)Sect
, sizeof (Sect
) },
55 { (char *)Quad
, sizeof (Quad
) },
56 { (char *)&Move
, sizeof (Move
) },
57 { (char *)Event
, sizeof (Event
) },
64 ** This routine dumps the game onto the file "trek.dump". The
65 ** first two bytes of the file are a version number, which
66 ** reflects whether this image may be used. Obviously, it must
67 ** change as the size, content, or order of the data structures
72 dumpgame(int v __unused
)
79 if ((fd
= creat("trek.dump", 0644)) < 0) {
80 printf("cannot dump\n");
84 write(fd
, &version
, sizeof version
);
86 /* output the main data areas */
87 for (d
= Dump_template
; d
->area
; d
++) {
88 write(fd
, &d
->area
, sizeof d
->area
);
90 write(fd
, d
->area
, i
);
100 ** The game is restored from the file "trek.dump". In order for
101 ** this to succeed, the file must exist and be readable, must
102 ** have the correct version number, and must have all the appro-
103 ** priate data areas.
105 ** Return value is zero for success, one for failure.
114 if ((fd
= open("trek.dump", O_RDONLY
)) < 0 ||
115 read(fd
, &version
, sizeof version
) != sizeof version
||
116 version
!= VERSION
||
118 printf("cannot restart\n");
131 ** This is the business end of restartgame(). It reads in the
134 ** Returns zero for success, one for failure.
147 for (d
= Dump_template
; d
->area
; d
++) {
148 if (read(fd
, &junk
, sizeof junk
) != (sizeof junk
))
150 if ((char *)junk
!= d
->area
)
153 if (read(fd
, d
->area
, i
) != i
)
157 /* make quite certain we are at EOF */
158 return (read(fd
, &junk
, 1));