From bae50c403e053e5ef8d399f1adb6677e2c4fabf8 Mon Sep 17 00:00:00 2001 From: simonb Date: Tue, 27 Mar 2001 02:23:28 +0000 Subject: Build the data files in the obj/compile directory and install them with FILES and FILESDIR. "Problem" reported by David Querbach on current-users. --- phantasia/setup.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'phantasia/setup.c') diff --git a/phantasia/setup.c b/phantasia/setup.c index ab6e625a..6a1d4c0e 100644 --- a/phantasia/setup.c +++ b/phantasia/setup.c @@ -1,4 +1,4 @@ -/* $NetBSD: setup.c,v 1.10 1999/09/19 18:14:52 jsm Exp $ */ +/* $NetBSD: setup.c,v 1.11 2001/03/27 02:23:28 simonb Exp $ */ /* * setup.c - set up all files for Phantasia @@ -63,12 +63,12 @@ main(argc, argv) 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) { @@ -86,31 +86,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 (!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*/ @@ -129,7 +113,7 @@ main(argc, argv) 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); + path = strrchr(_PATH_VOID, '/') + 1; if ((fp = fopen(path, "w")) == NULL) Error("Cannot update %s.\n", path); else @@ -142,7 +126,7 @@ main(argc, argv) } /* 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 @@ -186,7 +170,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 -- cgit v1.2.3-56-ge451