diff options
Diffstat (limited to 'monop/initdeck.c')
| -rw-r--r-- | monop/initdeck.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/monop/initdeck.c b/monop/initdeck.c index f1e36c4c..d066ed6d 100644 --- a/monop/initdeck.c +++ b/monop/initdeck.c @@ -1,4 +1,4 @@ -/* $NetBSD: initdeck.c,v 1.5 1997/10/12 17:45:12 christos Exp $ */ +/* $NetBSD: initdeck.c,v 1.6 1999/08/21 09:23:44 simonb Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,12 +43,14 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ #if 0 static char sccsid[] = "@(#)initdeck.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: initdeck.c,v 1.5 1997/10/12 17:45:12 christos Exp $"); +__RCSID("$NetBSD: initdeck.c,v 1.6 1999/08/21 09:23:44 simonb Exp $"); #endif #endif /* not lint */ #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> +#include <sys/endian.h> #include "deck.h" /* @@ -86,6 +88,9 @@ main(ac, av) int ac; char *av[]; { + int i; + int32_t nc; + getargs(ac, av); if ((inf = fopen(infile, "r")) == NULL) { perror(infile); @@ -95,24 +100,47 @@ char *av[]; { /* * allocate space for pointers. */ - CC_D.offsets = (long *)calloc(CC_D.num_cards + 1, sizeof (long)); - CH_D.offsets = (long *)calloc(CH_D.num_cards + 1, sizeof (long)); + CC_D.offsets = (off_t *)calloc(CC_D.num_cards + 1, sizeof (off_t)); + CH_D.offsets = (off_t *)calloc(CH_D.num_cards + 1, sizeof (off_t)); fseek(inf, 0L, 0); if ((outf = fopen(outfile, "w")) == NULL) { perror(outfile); exit(0); } - fwrite(deck, sizeof (DECK), 2, outf); - fwrite(CC_D.offsets, sizeof (long), CC_D.num_cards, outf); - fwrite(CH_D.offsets, sizeof (long), CH_D.num_cards, outf); + /* + * these fields will be overwritten after the offsets are calculated, + * so byte-order doesn't matter yet. + */ + fwrite(&nc, sizeof(nc), 1, outf); + fwrite(&nc, sizeof(nc), 1, outf); + fwrite(CC_D.offsets, sizeof (off_t), CC_D.num_cards, outf); + fwrite(CH_D.offsets, sizeof (off_t), CH_D.num_cards, outf); + + /* + * write out the cards themselves (calculating the offsets). + */ putem(); fclose(inf); fseek(outf, 0, 0L); - fwrite(deck, sizeof (DECK), 2, outf); - fwrite(CC_D.offsets, sizeof (long), CC_D.num_cards, outf); - fwrite(CH_D.offsets, sizeof (long), CH_D.num_cards, outf); + + /* number of community chest cards first... */ + nc = htobe32(CC_D.num_cards); + fwrite(&nc, sizeof(nc), 1, outf); + /* ... then number of chance cards. */ + nc = htobe32(CH_D.num_cards); + fwrite(&nc, sizeof(nc), 1, outf); + + /* convert offsets to big-endian byte order */ + for (i = 0; i < CC_D.num_cards; i++) + HTOBE64(CC_D.offsets[i]); + for (i = 0; i < CH_D.num_cards; i++) + HTOBE64(CH_D.offsets[i]); + /* then dump the offsets out */ + fwrite(CC_D.offsets, sizeof (off_t), CC_D.num_cards, outf); + fwrite(CH_D.offsets, sizeof (off_t), CH_D.num_cards, outf); + fclose(outf); printf("There were %d com. chest and %d chance cards\n", CC_D.num_cards, CH_D.num_cards); exit(0); |
