2 * setup.c - set up all files for Phantasia
4 * $FreeBSD: src/games/phantasia/setup.c,v 1.11 1999/11/16 02:57:34 billf Exp $
5 * $DragonFly: src/games/phantasia/setup.c,v 1.2 2003/06/17 04:25:24 dillon Exp $
12 /************************************************************************
14 / FUNCTION NAME: main()
16 / FUNCTION: setup files for Phantasia 3.3.2
18 / AUTHOR: E. A. Estes, 12/4/85
24 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
25 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
26 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
28 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
30 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
34 / This program tries to verify the parameters specified in
37 / Create all necessary files. Note that nothing needs to be
39 / Also, the monster binary data base is created here.
41 *************************************************************************/
45 static char *files[] = { /* all files to create */
57 char *monsterfile="monsters.asc";
64 char **filename; /* for pointing to file names */
65 register int fd; /* file descriptor */
66 FILE *fp; /* for opening files */
67 struct stat fbuf; /* for getting files statistics */
70 while ((ch = getopt(argc, argv, "m:")) != -1)
85 umask(0117); /* only owner can read/write created files */
88 /* try to create data files */
90 while (*filename != NULL)
91 /* create each file */
93 if (stat(*filename, &fbuf) == 0)
94 /* file exists; remove it */
96 if (!strcmp(*filename, _SPATH_PEOPLE))
97 /* do not reset character file if it already exists */
103 if (unlink(*filename) < 0)
104 Error("Cannot unlink %s.\n", *filename);
108 if ((fd = creat(*filename, 0666)) < 0)
109 Error("Cannot create %s.\n", *filename);
112 close(fd); /* close newly created file */
114 ++filename; /* process next file */
117 /* put holy grail info into energy void file */
118 Enrgyvoid.ev_active = TRUE;
119 Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
120 Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
121 if ((fp = fopen(_SPATH_VOID, "w")) == NULL)
122 Error("Cannot update %s.\n", _SPATH_VOID);
125 fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
129 /* create binary monster data base */
130 if ((Monstfp = fopen(_SPATH_MONST, "w")) == NULL)
131 Error("Cannot update %s.\n", _SPATH_MONST);
134 if ((fp = fopen(monsterfile, "r")) == NULL)
137 Error("cannot open %s to create monster database.\n", "monsters.asc");
141 Curmonster.m_o_strength =
142 Curmonster.m_o_speed =
143 Curmonster.m_maxspeed =
144 Curmonster.m_o_energy =
146 Curmonster.m_skirmish = 0.0;
148 while (fgets(Databuf, SZ_DATABUF, fp) != NULL)
149 /* read in text file, convert to binary */
151 sscanf(&Databuf[24], "%lf%lf%lf%lf%lf%d%d%lf",
152 &Curmonster.m_strength, &Curmonster.m_brains,
153 &Curmonster.m_speed, &Curmonster.m_energy,
154 &Curmonster.m_experience, &Curmonster.m_treasuretype,
155 &Curmonster.m_type, &Curmonster.m_flock);
157 strcpy(Curmonster.m_name, Databuf);
158 fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
165 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
166 /* write to motd file */
167 printf("One line 'motd' ? ");
168 if (fgets(Databuf, SZ_DATABUF, stdin) == NULL)
170 if ((fp = fopen(_SPATH_MOTD, "w")) == NULL)
171 Error("Cannot update %s.\n", _SPATH_MOTD);
174 fwrite(Databuf, sizeof(char), strlen(Databuf), fp);
178 /* report compile-time options */
179 printf("Compiled options:\n\n");
180 printf("Phantasia destination directory: %s\n", _SPATH_PHANTDIR);
181 printf("Wizard: root UID: 0\n");
184 printf("Compiled for BSD 4.1\n");
188 printf("Compiled for BSD 4.2\n");
192 printf("Compiled for System III\n");
196 printf("Compiled for System V\n");
204 /************************************************************************
206 / FUNCTION NAME: Error()
208 / FUNCTION: print an error message, and exit
210 / AUTHOR: E. A. Estes, 12/4/85
213 / char *str - format string for printf()
214 / char *file - file which caused error
218 / MODULES CALLED: exit(), perror(), fprintf()
220 / GLOBAL INPUTS: _iob[]
222 / GLOBAL OUTPUTS: none
225 / Print an error message, then exit.
227 *************************************************************************/
233 fprintf(stderr, "Error: ");
234 fprintf(stderr, str, file);
240 /************************************************************************
242 / FUNCTION NAME: drandom()
244 / FUNCTION: return a random number
246 / AUTHOR: E. A. Estes, 2/7/86
252 / MODULES CALLED: random()
254 / GLOBAL INPUTS: none
256 / GLOBAL OUTPUTS: none
260 *************************************************************************/
265 if (sizeof(int) != 2)
266 return((double) (random() & 0x7fff) / 32768.0);
268 return((double) random() / 32768.0);