2 * setup.c - set up all files for Phantasia
11 /************************************************************************
13 / FUNCTION NAME: main()
15 / FUNCTION: setup files for Phantasia 3.3.2
17 / AUTHOR: E. A. Estes, 12/4/85
23 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
24 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
25 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
27 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
29 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
33 / This program tries to verify the parameters specified in
36 / Create all necessary files. Note that nothing needs to be
38 / Also, the monster binary data base is created here.
40 *************************************************************************/
44 static char *files[] = { /* all files to create */
56 char *monsterfile="monsters.asc";
63 char **filename; /* for pointing to file names */
64 register int fd; /* file descriptor */
65 FILE *fp; /* for opening files */
66 struct stat fbuf; /* for getting files statistics */
69 while ((ch = getopt(argc, argv, "m:")) != -1)
84 umask(0117); /* only owner can read/write created files */
87 /* try to create data files */
89 while (*filename != NULL)
90 /* create each file */
92 if (stat(*filename, &fbuf) == 0)
93 /* file exists; remove it */
95 if (!strcmp(*filename, _SPATH_PEOPLE))
96 /* do not reset character file if it already exists */
102 if (unlink(*filename) < 0)
103 Error("Cannot unlink %s.\n", *filename);
107 if ((fd = creat(*filename, 0666)) < 0)
108 Error("Cannot create %s.\n", *filename);
111 close(fd); /* close newly created file */
113 ++filename; /* process next file */
116 /* put holy grail info into energy void file */
117 Enrgyvoid.ev_active = TRUE;
118 Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
119 Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
120 if ((fp = fopen(_SPATH_VOID, "w")) == NULL)
121 Error("Cannot update %s.\n", _SPATH_VOID);
124 fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
128 /* create binary monster data base */
129 if ((Monstfp = fopen(_SPATH_MONST, "w")) == NULL)
130 Error("Cannot update %s.\n", _SPATH_MONST);
133 if ((fp = fopen(monsterfile, "r")) == NULL)
136 Error("cannot open %s to create monster database.\n", "monsters.asc");
140 Curmonster.m_o_strength =
141 Curmonster.m_o_speed =
142 Curmonster.m_maxspeed =
143 Curmonster.m_o_energy =
145 Curmonster.m_skirmish = 0.0;
147 while (fgets(Databuf, SZ_DATABUF, fp) != NULL)
148 /* read in text file, convert to binary */
150 sscanf(&Databuf[24], "%lf%lf%lf%lf%lf%d%d%lf",
151 &Curmonster.m_strength, &Curmonster.m_brains,
152 &Curmonster.m_speed, &Curmonster.m_energy,
153 &Curmonster.m_experience, &Curmonster.m_treasuretype,
154 &Curmonster.m_type, &Curmonster.m_flock);
156 strcpy(Curmonster.m_name, Databuf);
157 fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
164 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
165 /* write to motd file */
166 printf("One line 'motd' ? ");
167 if (fgets(Databuf, SZ_DATABUF, stdin) == NULL)
169 if ((fp = fopen(_SPATH_MOTD, "w")) == NULL)
170 Error("Cannot update %s.\n", _SPATH_MOTD);
173 fwrite(Databuf, sizeof(char), strlen(Databuf), fp);
177 /* report compile-time options */
178 printf("Compiled options:\n\n");
179 printf("Phantasia destination directory: %s\n", _SPATH_PHANTDIR);
180 printf("Wizard: root UID: 0\n");
183 printf("Compiled for BSD 4.1\n");
187 printf("Compiled for BSD 4.2\n");
191 printf("Compiled for System III\n");
195 printf("Compiled for System V\n");
203 /************************************************************************
205 / FUNCTION NAME: Error()
207 / FUNCTION: print an error message, and exit
209 / AUTHOR: E. A. Estes, 12/4/85
212 / char *str - format string for printf()
213 / char *file - file which caused error
217 / MODULES CALLED: exit(), perror(), fprintf()
219 / GLOBAL INPUTS: _iob[]
221 / GLOBAL OUTPUTS: none
224 / Print an error message, then exit.
226 *************************************************************************/
232 fprintf(stderr, "Error: ");
233 fprintf(stderr, str, file);
239 /************************************************************************
241 / FUNCTION NAME: drandom()
243 / FUNCTION: return a random number
245 / AUTHOR: E. A. Estes, 2/7/86
251 / MODULES CALLED: random()
253 / GLOBAL INPUTS: none
255 / GLOBAL OUTPUTS: none
259 *************************************************************************/
264 if (sizeof(int) != 2)
265 return((double) (random() & 0x7fff) / 32768.0);
267 return((double) random() / 32768.0);