summaryrefslogtreecommitdiffstats
path: root/monop/cards.c
diff options
context:
space:
mode:
authorsimonb <simonb@NetBSD.org>1999-08-21 09:23:44 +0000
committersimonb <simonb@NetBSD.org>1999-08-21 09:23:44 +0000
commitca104a29f1236b5c4ee454e8c132ed8518df7a27 (patch)
tree314b1914aaf8b83354a3f37d0e390f6b752d955f /monop/cards.c
parent9f5f92a0f3b2deed923c1d9c5613fe2dc55e605f (diff)
downloadbsdgames-darwin-ca104a29f1236b5c4ee454e8c132ed8518df7a27.tar.gz
bsdgames-darwin-ca104a29f1236b5c4ee454e8c132ed8518df7a27.tar.zst
bsdgames-darwin-ca104a29f1236b5c4ee454e8c132ed8518df7a27.zip
Instead of writing out a structure that contains pointers as the header
of the card decks file, just write out the number of cards for each deck. Also use "off_t" for offsets into the file (that are stored after the number of cards) instead of "long". /usr/share/games/cards.pck is now MI.
Diffstat (limited to 'monop/cards.c')
-rw-r--r--monop/cards.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/monop/cards.c b/monop/cards.c
index 18e5fa0c..5f1adabc 100644
--- a/monop/cards.c
+++ b/monop/cards.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cards.c,v 1.5 1998/08/30 09:19:39 veego Exp $ */
+/* $NetBSD: cards.c,v 1.6 1999/08/21 09:23:44 simonb Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,10 +38,12 @@
#if 0
static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: cards.c,v 1.5 1998/08/30 09:19:39 veego Exp $");
+__RCSID("$NetBSD: cards.c,v 1.6 1999/08/21 09:23:44 simonb Exp $");
#endif
#endif /* not lint */
+# include <sys/types.h>
+# include <sys/endian.h>
# include "monop.ext"
# include "pathnames.h"
@@ -69,14 +71,22 @@ static void printmes __P((void));
void
init_decks()
{
+ int32_t nc;
if ((deckf=fopen(cardfile, "r")) == NULL) {
file_err:
perror(cardfile);
exit(1);
}
- if (fread(deck, sizeof (DECK), 2, deckf) != 2)
+
+ /* read number of community chest cards... */
+ if (fread(&nc, sizeof(nc), 1, deckf) != 1)
+ goto file_err;
+ CC_D.num_cards = be32toh(nc);
+ /* ... and number of community chest cards. */
+ if (fread(&nc, sizeof(nc), 1, deckf) != 1)
goto file_err;
+ CH_D.num_cards = be32toh(nc);
set_up(&CC_D);
set_up(&CH_D);
}
@@ -90,15 +100,19 @@ DECK *dp; {
int r1, r2;
int i;
- dp->offsets = (long *) calloc(sizeof (long), dp->num_cards);
- if (fread(dp->offsets, sizeof(long), dp->num_cards, deckf) != dp->num_cards) {
+ dp->offsets = (off_t *) calloc(sizeof (off_t), dp->num_cards);
+ if (fread(dp->offsets, sizeof(off_t), dp->num_cards, deckf) !=
+ dp->num_cards) {
perror(cardfile);
exit(1);
}
+ /* convert offsets from big-endian byte order */
+ for (i = 0; i < dp->num_cards; i++)
+ BE64TOH(dp->offsets[i]);
dp->last_card = 0;
dp->gojf_used = FALSE;
for (i = 0; i < dp->num_cards; i++) {
- long temp;
+ off_t temp;
r1 = roll(1, dp->num_cards) - 1;
r2 = roll(1, dp->num_cards) - 1;