2004-04-07 21:46:47 +04:00
|
|
|
|
/* $NetBSD: setup.c,v 1.13 2004/04/07 17:46:47 ross Exp $ */
|
1995-03-24 06:58:08 +03:00
|
|
|
|
|
1994-10-22 00:19:39 +03:00
|
|
|
|
/*
|
|
|
|
|
* setup.c - set up all files for Phantasia
|
|
|
|
|
*/
|
1995-03-08 22:41:53 +03:00
|
|
|
|
#include <sys/param.h>
|
1994-10-22 00:19:39 +03:00
|
|
|
|
#include <sys/stat.h>
|
1999-09-19 22:14:52 +04:00
|
|
|
|
#include <fcntl.h>
|
1995-04-24 16:21:37 +04:00
|
|
|
|
#include "include.h"
|
1999-09-19 22:14:52 +04:00
|
|
|
|
|
2003-05-08 17:03:49 +04:00
|
|
|
|
int main(int, char *[]);
|
|
|
|
|
void Error(const char *, const char *) __attribute__((__noreturn__));
|
|
|
|
|
double drandom(void);
|
1999-09-19 22:14:52 +04:00
|
|
|
|
|
1994-10-22 00:19:39 +03:00
|
|
|
|
/**/
|
|
|
|
|
/************************************************************************
|
|
|
|
|
/
|
|
|
|
|
/ FUNCTION NAME: main()
|
|
|
|
|
/
|
|
|
|
|
/ FUNCTION: setup files for Phantasia 3.3.2
|
|
|
|
|
/
|
|
|
|
|
/ AUTHOR: E. A. Estes, 12/4/85
|
|
|
|
|
/
|
|
|
|
|
/ ARGUMENTS: none
|
|
|
|
|
/
|
|
|
|
|
/ RETURN VALUE: none
|
|
|
|
|
/
|
|
|
|
|
/ MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
|
|
|
|
|
/ fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
|
|
|
|
|
/ unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
|
|
|
|
|
/
|
|
|
|
|
/ GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
|
|
|
|
|
/
|
|
|
|
|
/ GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
|
|
|
|
|
/
|
|
|
|
|
/ DESCRIPTION:
|
|
|
|
|
/
|
|
|
|
|
/ This program tries to verify the parameters specified in
|
|
|
|
|
/ the Makefile.
|
|
|
|
|
/
|
|
|
|
|
/ Create all necessary files. Note that nothing needs to be
|
|
|
|
|
/ put in these files.
|
|
|
|
|
/ Also, the monster binary data base is created here.
|
|
|
|
|
/
|
1999-09-19 22:14:52 +04:00
|
|
|
|
/ ************************************************************************/
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
|
static const char *const files[] = { /* all files to create */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
_PATH_MONST,
|
|
|
|
|
_PATH_PEOPLE,
|
|
|
|
|
_PATH_MESS,
|
|
|
|
|
_PATH_LASTDEAD,
|
|
|
|
|
_PATH_MOTD,
|
|
|
|
|
_PATH_GOLD,
|
|
|
|
|
_PATH_VOID,
|
|
|
|
|
_PATH_SCORE,
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
|
const char *monsterfile = "monsters.asc";
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(argc, argv)
|
|
|
|
|
int argc;
|
|
|
|
|
char *argv[];
|
|
|
|
|
{
|
2001-03-27 06:23:28 +04:00
|
|
|
|
const char *const *filename; /* for pointing to file names */
|
|
|
|
|
int fd; /* file descriptor */
|
|
|
|
|
FILE *fp; /* for opening files */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
struct stat fbuf; /* for getting files statistics */
|
|
|
|
|
int ch;
|
2001-03-27 06:23:28 +04:00
|
|
|
|
char *path;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
1997-10-12 18:19:17 +04:00
|
|
|
|
while ((ch = getopt(argc, argv, "m:")) != -1)
|
1994-10-22 00:19:39 +03:00
|
|
|
|
switch(ch) {
|
|
|
|
|
case 'm':
|
|
|
|
|
monsterfile = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case '?':
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
argc -= optind;
|
|
|
|
|
argv += optind;
|
|
|
|
|
|
1995-04-24 16:21:37 +04:00
|
|
|
|
srandom((unsigned) time(NULL)); /* prime random numbers */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
|
|
|
|
umask(0117); /* only owner can read/write created files */
|
|
|
|
|
|
|
|
|
|
/* try to create data files */
|
|
|
|
|
filename = &files[0];
|
|
|
|
|
while (*filename != NULL)
|
|
|
|
|
/* create each file */
|
|
|
|
|
{
|
2001-03-27 06:23:28 +04:00
|
|
|
|
path = strrchr(*filename, '/') + 1;
|
1995-03-08 22:41:53 +03:00
|
|
|
|
if (stat(path, &fbuf) == 0)
|
1994-10-22 00:19:39 +03:00
|
|
|
|
/* file exists; remove it */
|
|
|
|
|
{
|
1995-03-08 22:41:53 +03:00
|
|
|
|
if (unlink(path) < 0)
|
|
|
|
|
Error("Cannot unlink %s.\n", path);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
}
|
|
|
|
|
|
1995-03-08 22:41:53 +03:00
|
|
|
|
if ((fd = creat(path, 0660)) < 0)
|
|
|
|
|
Error("Cannot create %s.\n", path);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
|
|
|
|
|
close(fd); /* close newly created file */
|
|
|
|
|
|
|
|
|
|
++filename; /* process next file */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* put holy grail info into energy void file */
|
2004-04-07 21:46:47 +04:00
|
|
|
|
Enrgyvoid.ev_active = 1;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
|
|
|
|
|
Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
|
2001-03-27 06:23:28 +04:00
|
|
|
|
path = strrchr(_PATH_VOID, '/') + 1;
|
1995-03-08 22:41:53 +03:00
|
|
|
|
if ((fp = fopen(path, "w")) == NULL)
|
|
|
|
|
Error("Cannot update %s.\n", path);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
|
1999-09-19 22:14:52 +04:00
|
|
|
|
fflush(fp);
|
|
|
|
|
if (ferror(fp))
|
|
|
|
|
Error("Writing %s.\n", path);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create binary monster data base */
|
2001-03-27 06:23:28 +04:00
|
|
|
|
path = strrchr(_PATH_MONST, '/') + 1;
|
1995-03-08 22:41:53 +03:00
|
|
|
|
if ((Monstfp = fopen(path, "w")) == NULL)
|
|
|
|
|
Error("Cannot update %s.\n", path);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((fp = fopen(monsterfile, "r")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
fclose(Monstfp);
|
|
|
|
|
Error("cannot open %s to create monster database.\n", "monsters.asc");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Curmonster.m_o_strength =
|
|
|
|
|
Curmonster.m_o_speed =
|
|
|
|
|
Curmonster.m_maxspeed =
|
|
|
|
|
Curmonster.m_o_energy =
|
|
|
|
|
Curmonster.m_melee =
|
|
|
|
|
Curmonster.m_skirmish = 0.0;
|
|
|
|
|
|
|
|
|
|
while (fgets(Databuf, SZ_DATABUF, fp) != NULL)
|
|
|
|
|
/* read in text file, convert to binary */
|
|
|
|
|
{
|
|
|
|
|
sscanf(&Databuf[24], "%lf%lf%lf%lf%lf%d%d%lf",
|
|
|
|
|
&Curmonster.m_strength, &Curmonster.m_brains,
|
|
|
|
|
&Curmonster.m_speed, &Curmonster.m_energy,
|
|
|
|
|
&Curmonster.m_experience, &Curmonster.m_treasuretype,
|
|
|
|
|
&Curmonster.m_type, &Curmonster.m_flock);
|
|
|
|
|
Databuf[24] = '\0';
|
|
|
|
|
strcpy(Curmonster.m_name, Databuf);
|
|
|
|
|
fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
1999-09-19 22:14:52 +04:00
|
|
|
|
fflush(Monstfp);
|
|
|
|
|
if (ferror(Monstfp))
|
|
|
|
|
Error("Writing %s.\n", path);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
fclose(Monstfp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
|
|
|
|
|
/* write to motd file */
|
|
|
|
|
printf("One line 'motd' ? ");
|
|
|
|
|
if (fgets(Databuf, SZ_DATABUF, stdin) == NULL)
|
|
|
|
|
Databuf[0] = '\0';
|
2001-03-27 06:23:28 +04:00
|
|
|
|
path = strrchr(_PATH_MOTD, '/') + 1;
|
1995-03-08 22:41:53 +03:00
|
|
|
|
if ((fp = fopen(path, "w")) == NULL)
|
|
|
|
|
Error("Cannot update %s.\n", path);
|
1994-10-22 00:19:39 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fwrite(Databuf, sizeof(char), strlen(Databuf), fp);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* report compile-time options */
|
|
|
|
|
printf("Compiled options:\n\n");
|
|
|
|
|
printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR);
|
|
|
|
|
printf("Wizard: root UID: 0\n");
|
|
|
|
|
|
|
|
|
|
#ifdef BSD41
|
|
|
|
|
printf("Compiled for BSD 4.1\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef BSD42
|
|
|
|
|
printf("Compiled for BSD 4.2\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef SYS3
|
|
|
|
|
printf("Compiled for System III\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef SYS5
|
|
|
|
|
printf("Compiled for System V\n");
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
}
|
|
|
|
|
/**/
|
|
|
|
|
/************************************************************************
|
|
|
|
|
/
|
|
|
|
|
/ FUNCTION NAME: Error()
|
|
|
|
|
/
|
|
|
|
|
/ FUNCTION: print an error message, and exit
|
|
|
|
|
/
|
|
|
|
|
/ AUTHOR: E. A. Estes, 12/4/85
|
|
|
|
|
/
|
|
|
|
|
/ ARGUMENTS:
|
|
|
|
|
/ char *str - format string for printf()
|
|
|
|
|
/ char *file - file which caused error
|
|
|
|
|
/
|
|
|
|
|
/ RETURN VALUE: none
|
|
|
|
|
/
|
|
|
|
|
/ MODULES CALLED: exit(), perror(), fprintf()
|
|
|
|
|
/
|
|
|
|
|
/ GLOBAL INPUTS: _iob[]
|
|
|
|
|
/
|
|
|
|
|
/ GLOBAL OUTPUTS: none
|
|
|
|
|
/
|
|
|
|
|
/ DESCRIPTION:
|
|
|
|
|
/ Print an error message, then exit.
|
|
|
|
|
/
|
1999-09-19 22:14:52 +04:00
|
|
|
|
/ ************************************************************************/
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
1999-09-19 22:14:52 +04:00
|
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
|
Error(str, file)
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
|
const char *str, *file;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Error: ");
|
|
|
|
|
fprintf(stderr, str, file);
|
|
|
|
|
perror(file);
|
|
|
|
|
exit(1);
|
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
}
|
|
|
|
|
/**/
|
|
|
|
|
/************************************************************************
|
|
|
|
|
/
|
|
|
|
|
/ FUNCTION NAME: drandom()
|
|
|
|
|
/
|
|
|
|
|
/ FUNCTION: return a random number
|
|
|
|
|
/
|
|
|
|
|
/ AUTHOR: E. A. Estes, 2/7/86
|
|
|
|
|
/
|
|
|
|
|
/ ARGUMENTS: none
|
|
|
|
|
/
|
|
|
|
|
/ RETURN VALUE: none
|
|
|
|
|
/
|
|
|
|
|
/ MODULES CALLED: random()
|
|
|
|
|
/
|
|
|
|
|
/ GLOBAL INPUTS: none
|
|
|
|
|
/
|
|
|
|
|
/ GLOBAL OUTPUTS: none
|
|
|
|
|
/
|
|
|
|
|
/ DESCRIPTION:
|
|
|
|
|
/
|
1999-09-19 22:14:52 +04:00
|
|
|
|
/ ************************************************************************/
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
|
|
|
|
double
|
|
|
|
|
drandom()
|
|
|
|
|
{
|
|
|
|
|
if (sizeof(int) != 2)
|
|
|
|
|
return((double) (random() & 0x7fff) / 32768.0);
|
|
|
|
|
else
|
|
|
|
|
return((double) random() / 32768.0);
|
|
|
|
|
}
|