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.3 2005/05/31 00:06:26 swildner Exp $
12 /* functions which we need to know about */
14 extern double drandom(void);
16 void Error(const char *, const char *);
18 static const char *files[] = { /* all files to create */
30 const char *monsterfile="monsters.asc";
33 /************************************************************************
35 / FUNCTION NAME: main()
37 / FUNCTION: setup files for Phantasia 3.3.2
39 / AUTHOR: E. A. Estes, 12/4/85
45 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
46 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
47 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
49 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
51 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
55 / This program tries to verify the parameters specified in
58 / Create all necessary files. Note that nothing needs to be
60 / Also, the monster binary data base is created here.
62 *************************************************************************/
65 main(int argc, char **argv)
67 const char **filename; /* for pointing to file names */
68 int fd; /* file descriptor */
69 FILE *fp; /* for opening files */
70 struct stat fbuf; /* for getting files statistics */
73 while ((ch = getopt(argc, argv, "m:")) != -1)
88 umask(0117); /* only owner can read/write created files */
91 /* try to create data files */
93 while (*filename != NULL)
94 /* create each file */
96 if (stat(*filename, &fbuf) == 0)
97 /* file exists; remove it */
99 if (!strcmp(*filename, _SPATH_PEOPLE))
100 /* do not reset character file if it already exists */
106 if (unlink(*filename) < 0)
107 Error("Cannot unlink %s.\n", *filename);
111 if ((fd = creat(*filename, 0666)) < 0)
112 Error("Cannot create %s.\n", *filename);
115 close(fd); /* close newly created file */
117 ++filename; /* process next file */
120 /* put holy grail info into energy void file */
121 Enrgyvoid.ev_active = TRUE;
122 Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
123 Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
124 if ((fp = fopen(_SPATH_VOID, "w")) == NULL)
125 Error("Cannot update %s.\n", _SPATH_VOID);
128 fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
132 /* create binary monster data base */
133 if ((Monstfp = fopen(_SPATH_MONST, "w")) == NULL)
134 Error("Cannot update %s.\n", _SPATH_MONST);
137 if ((fp = fopen(monsterfile, "r")) == NULL)
140 Error("cannot open %s to create monster database.\n", "monsters.asc");
144 Curmonster.m_o_strength =
145 Curmonster.m_o_speed =
146 Curmonster.m_maxspeed =
147 Curmonster.m_o_energy =
149 Curmonster.m_skirmish = 0.0;
151 while (fgets(Databuf, SZ_DATABUF, fp) != NULL)
152 /* read in text file, convert to binary */
154 sscanf(&Databuf[24], "%lf%lf%lf%lf%lf%d%d%lf",
155 &Curmonster.m_strength, &Curmonster.m_brains,
156 &Curmonster.m_speed, &Curmonster.m_energy,
157 &Curmonster.m_experience, &Curmonster.m_treasuretype,
158 &Curmonster.m_type, &Curmonster.m_flock);
160 strcpy(Curmonster.m_name, Databuf);
161 fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
168 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
169 /* write to motd file */
170 printf("One line 'motd' ? ");
171 if (fgets(Databuf, SZ_DATABUF, stdin) == NULL)
173 if ((fp = fopen(_SPATH_MOTD, "w")) == NULL)
174 Error("Cannot update %s.\n", _SPATH_MOTD);
177 fwrite(Databuf, sizeof(char), strlen(Databuf), fp);
181 /* report compile-time options */
182 printf("Compiled options:\n\n");
183 printf("Phantasia destination directory: %s\n", _SPATH_PHANTDIR);
184 printf("Wizard: root UID: 0\n");
187 printf("Compiled for BSD 4.1\n");
191 printf("Compiled for BSD 4.2\n");
195 printf("Compiled for System III\n");
199 printf("Compiled for System V\n");
207 /************************************************************************
209 / FUNCTION NAME: Error()
211 / FUNCTION: print an error message, and exit
213 / AUTHOR: E. A. Estes, 12/4/85
216 / char *str - format string for printf()
217 / char *file - file which caused error
221 / MODULES CALLED: exit(), perror(), fprintf()
223 / GLOBAL INPUTS: _iob[]
225 / GLOBAL OUTPUTS: none
228 / Print an error message, then exit.
230 *************************************************************************/
233 Error(const char *str, const char *file)
235 fprintf(stderr, "Error: ");
236 fprintf(stderr, str, file);