* setup.c - set up all files for Phantasia
/************************************************************************
/ FUNCTION: setup files for Phantasia 3.3.2
/ AUTHOR: E. A. Estes, 12/4/85
/ 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: Peoplefile[], Curmonster, _iob[], Databuf[], *Monstfp,
/ Lastdead[], Goldfile[], Voidfile[], Motdfile[], Messfile[], Scorefile[],
/ Enemyfile[], Monstfile[], Enrgyvoid
/ GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
/ This program tries to verify the parameters specified in
/ Create all necessary files. Note that nothing needs to be
/ Also, the monster binary data base is created here.
/************************************************************************/
FILE *fp
; /* for opening files */
struct stat fbuf
; /* for getting files statistics */
register char **filename
; /* for pointing to file names */
register int fd
; /* file descriptor */
static char *files
[] = /* all files to create */
srandom((unsigned) time((long *) NULL
)); /* prime random numbers */
umask(0117); /* only owner can read/write created files */
fprintf(stderr
, "Warning: UID (%d) is not equal to current uid.\n", UID
);
/* check Phantasia destination directory */
if (stat(DEST
", &fbuf) < 0)
Error("Cannot stat
%s
.\n", DEST");
if ((fbuf
.st_mode
& S_IFDIR
) == 0)
Error("%s is not a directory.\n", DEST
");
/* try to create data files */
while (*filename != NULL)
if (stat(*filename, &fbuf) == 0)
/* file exists; remove it */
if (*filename == Peoplefile)
/* do not reset character file if it already exists */
if (unlink(*filename) < 0)
Error("Cannot unlink
%s
.\n", *filename);
if ((fd = creat(*filename, 0660)) < 0)
Error("Cannot create
%s
.\n", *filename);
close(fd); /* close newly created file */
++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);
if ((fp = fopen(Voidfile, "w
")) == NULL)
Error("Cannot update
%s
.\n", Voidfile);
fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
/* create binary monster data base */
if ((Monstfp = fopen(Monstfile, "w
")) == NULL)
Error("Cannot update
%s
.\n", Monstfile);
if ((fp = fopen("monsters
.asc
", "r
")) == NULL)
Error("cannot open
%s to create monster database
.\n", "monsters
.asc
");
Curmonster.m_o_strength =
Curmonster.m_skirmish = 0.0;
while (fgets(Databuf, SZ_DATABUF, fp) != NULL)
/* read in text file, convert to binary */
sscanf(&Databuf[24], "%F
%F
%F
%F
%F
%d
%d
%F
",
&Curmonster.m_strength, &Curmonster.m_brains,
&Curmonster.m_speed, &Curmonster.m_energy,
&Curmonster.m_experience, &Curmonster.m_treasuretype,
&Curmonster.m_type, &Curmonster.m_flock);
strcpy(Curmonster.m_name, Databuf);
fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
#ifdef MAKE_INSTALLS_THIS_AND_DOESNT_ANSWER_QUESTIONS
printf("One line
'motd' ? ");
if (fgets(Databuf, SZ_DATABUF, stdin) == NULL)
if ((fp = fopen(Motdfile, "w
")) == NULL)
Error("Cannot update
%s
.\n", Motdfile);
fwrite(Databuf, sizeof(char), strlen(Databuf), fp);
/* report compile-time options */
printf("Compiled options
:\n\n");
printf("Phantasia destination directory
: %s
\n", DEST");
printf("Wizard: %s UID: %d\n", WIZARD
, UID
);
printf("Restricted playing enabled.\n");
printf("Playing unrestricted.\n");
printf("Enemy list enabled.\n");
printf("Enemy list disabled.\n");
printf("Shell escapes enabled. Default shell: %s\n", SHELL
);
printf("Shell escapes disabled.\n");
printf("Compiled for BSD 4.1\n");
printf("Compiled for BSD 4.2\n");
printf("Compiled for System III\n");
printf("Compiled for System V\n");
/************************************************************************
/ FUNCTION: print an error message, and exit
/ AUTHOR: E. A. Estes, 12/4/85
/ char *str - format string for printf()
/ char *file - file which caused error
/ MODULES CALLED: exit(), perror(), fprintf()
/ Print an error message, then exit.
/************************************************************************/
fprintf(stderr
, "Error: ");
fprintf(stderr
, str
, file
);
/************************************************************************
/ FUNCTION NAME: drandom()
/ FUNCTION: return a random number
/ AUTHOR: E. A. Estes, 2/7/86
/ MODULES CALLED: random()
/************************************************************************/
return((double) (random() & 0x7fff) / 32768.0);
return((double) random() / 32768.0);