X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/1ba319c5714af32ed91f3c11e1bdd1440cc90b8a..1bb28c57a5d2c06152fff5de57a902bec60cc30d:/phantasia/setup.c diff --git a/phantasia/setup.c b/phantasia/setup.c index 7a53f610..a13c5211 100644 --- a/phantasia/setup.c +++ b/phantasia/setup.c @@ -1,13 +1,35 @@ -/* $NetBSD: setup.c,v 1.5 1997/01/07 12:20:39 tls Exp $ */ +/* $NetBSD: setup.c,v 1.22 2017/10/02 22:03:10 joerg Exp $ */ /* * setup.c - set up all files for Phantasia + * n.b.: this is used at build-time - i.e. during build.sh. */ -#include +#ifdef __NetBSD__ +#include +#endif + #include +#include +#include +#include #include +#include +#include #include -#include "include.h" + +#ifndef __dead /* Not NetBSD */ +#define __dead +#endif + +#include "phantdefs.h" +#include "phantstruct.h" +#include "phantglobs.h" +#include "pathnames.h" + +int main(int, char *[]); +void Error(const char *, const char *) __dead; +double drandom(void); + /* */ /************************************************************************ / @@ -38,9 +60,9 @@ / put in these files. / Also, the monster binary data base is created here. / -/************************************************************************/ +/ ************************************************************************/ -static char *files[] = { /* all files to create */ +static const char *const files[] = { /* all files to create */ _PATH_MONST, _PATH_PEOPLE, _PATH_MESS, @@ -52,21 +74,19 @@ static char *files[] = { /* all files to create */ NULL, }; -char *monsterfile="monsters.asc"; +const char *monsterfile = "monsters.asc"; int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { - register char **filename; /* for pointing to file names */ - register int fd; /* file descriptor */ - FILE *fp; /* for opening files */ + const char *const *filename; /* for pointing to file names */ + int fd; /* file descriptor */ + FILE *fp; /* for opening files */ struct stat fbuf; /* for getting files statistics */ int ch; - char path[MAXPATHLEN], *prefix; + char *path; - while ((ch = getopt(argc, argv, "m:")) != EOF) + while ((ch = getopt(argc, argv, "m:")) != -1) switch(ch) { case 'm': monsterfile = optarg; @@ -82,24 +102,15 @@ main(argc, argv) umask(0117); /* only owner can read/write created files */ - prefix = getenv("DESTDIR"); - /* try to create data files */ filename = &files[0]; while (*filename != NULL) /* create each file */ { - snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", *filename); + path = strrchr(*filename, '/') + 1; if (stat(path, &fbuf) == 0) /* file exists; remove it */ { - if (!strcmp(*filename, _PATH_PEOPLE)) - /* do not reset character file if it already exists */ - { - ++filename; - continue; - } - if (unlink(path) < 0) Error("Cannot unlink %s.\n", path); /*NOTREACHED*/ @@ -114,21 +125,13 @@ main(argc, argv) ++filename; /* process next file */ } - /* put holy grail info into energy void file */ - Enrgyvoid.ev_active = TRUE; - Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6); - Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6); - snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_VOID); + /* Initialize an empty file placeholder for the grail location. */ if ((fp = fopen(path, "w")) == NULL) - Error("Cannot update %s.\n", path); - else - { - fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp); - fclose(fp); - } + Error("Cannot create %s.\n", path); + fclose(fp); /* create binary monster data base */ - snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_MONST); + path = strrchr(_PATH_MONST, '/') + 1; if ((Monstfp = fopen(path, "w")) == NULL) Error("Cannot update %s.\n", path); else @@ -160,6 +163,9 @@ main(argc, argv) fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp); } fclose(fp); + fflush(Monstfp); + if (ferror(Monstfp)) + Error("Writing %s.\n", path); fclose(Monstfp); } } @@ -169,7 +175,7 @@ main(argc, argv) printf("One line 'motd' ? "); if (fgets(Databuf, SZ_DATABUF, stdin) == NULL) Databuf[0] = '\0'; - snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_MOTD); + path = strrchr(_PATH_MOTD, '/') + 1; if ((fp = fopen(path, "w")) == NULL) Error("Cannot update %s.\n", path); else @@ -227,10 +233,10 @@ main(argc, argv) / DESCRIPTION: / Print an error message, then exit. / -/************************************************************************/ +/ ************************************************************************/ -Error(str, file) -char *str, *file; +void +Error(const char *str, const char *file) { fprintf(stderr, "Error: "); fprintf(stderr, str, file); @@ -259,10 +265,10 @@ char *str, *file; / / DESCRIPTION: / -/************************************************************************/ +/ ************************************************************************/ double -drandom() +drandom(void) { if (sizeof(int) != 2) return((double) (random() & 0x7fff) / 32768.0);