-/* $NetBSD: setup.c,v 1.10 1999/09/19 18:14:52 jsm 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 <sys/param.h>
+#ifdef __NetBSD__
+#include <sys/cdefs.h>
+#endif
+
#include <sys/stat.h>
#include <fcntl.h>
-#include "include.h"
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#ifndef __dead /* Not NetBSD */
+#define __dead
+#endif
+
+#include "phantdefs.h"
+#include "phantstruct.h"
+#include "phantglobs.h"
+#include "pathnames.h"
-int main __P((int, char *[]));
-void Error __P((const char *, const char *)) __attribute__((__noreturn__));
-double drandom __P((void));
+int main(int, char *[]);
+void Error(const char *, const char *) __dead;
+double drandom(void);
/*\f*/
/************************************************************************
const char *monsterfile = "monsters.asc";
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
- register const char *const *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:")) != -1)
switch(ch) {
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 (!strcmp(*filename, _PATH_SCORE))
- /* do not reset score file if it already exists */
- {
- ++filename;
- continue;
- }
-
if (unlink(path) < 0)
Error("Cannot unlink %s.\n", path);
/*NOTREACHED*/
++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);
- fflush(fp);
- if (ferror(fp))
- Error("Writing %s.\n", path);
- 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
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
/ ************************************************************************/
void
-Error(str, file)
- const char *str, *file;
+Error(const char *str, const char *file)
{
fprintf(stderr, "Error: ");
fprintf(stderr, str, file);
/ ************************************************************************/
double
-drandom()
+drandom(void)
{
if (sizeof(int) != 2)
return((double) (random() & 0x7fff) / 32768.0);