]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.20 2009/05/27 17:44:38 dholland Exp $ */
4 * setup.c - set up all files for Phantasia
5 * n.b.: this is used at build-time - i.e. during build.sh.
11 #include <sys/param.h>
16 int main(int, char *[]);
17 void Error(const char *, const char *) __dead
;
21 /************************************************************************
23 / FUNCTION NAME: main()
25 / FUNCTION: setup files for Phantasia 3.3.2
27 / AUTHOR: E. A. Estes, 12/4/85
33 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
34 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
35 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
37 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
39 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
43 / This program tries to verify the parameters specified in
46 / Create all necessary files. Note that nothing needs to be
48 / Also, the monster binary data base is created here.
50 / ************************************************************************/
52 static const char *const files
[] = { /* all files to create */
64 const char *monsterfile
= "monsters.asc";
67 main(int argc
, char *argv
[])
69 const char *const *filename
; /* for pointing to file names */
70 int fd
; /* file descriptor */
71 FILE *fp
; /* for opening files */
72 struct stat fbuf
; /* for getting files statistics */
76 while ((ch
= getopt(argc
, argv
, "m:")) != -1)
88 srandom((unsigned) time(NULL
)); /* prime random numbers */
90 umask(0117); /* only owner can read/write created files */
92 /* try to create data files */
94 while (*filename
!= NULL
)
95 /* create each file */
97 path
= strrchr(*filename
, '/') + 1;
98 if (stat(path
, &fbuf
) == 0)
99 /* file exists; remove it */
101 if (unlink(path
) < 0)
102 Error("Cannot unlink %s.\n", path
);
106 if ((fd
= creat(path
, 0660)) < 0)
107 Error("Cannot create %s.\n", path
);
110 close(fd
); /* close newly created file */
112 ++filename
; /* process next file */
115 /* Initialize an empty file placeholder for the grail location. */
116 if ((fp
= fopen(path
, "w")) == NULL
)
117 Error("Cannot create %s.\n", path
);
120 /* create binary monster data base */
121 path
= strrchr(_PATH_MONST
, '/') + 1;
122 if ((Monstfp
= fopen(path
, "w")) == NULL
)
123 Error("Cannot update %s.\n", path
);
126 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
129 Error("cannot open %s to create monster database.\n", "monsters.asc");
133 Curmonster
.m_o_strength
=
134 Curmonster
.m_o_speed
=
135 Curmonster
.m_maxspeed
=
136 Curmonster
.m_o_energy
=
138 Curmonster
.m_skirmish
= 0.0;
140 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
141 /* read in text file, convert to binary */
143 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
144 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
145 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
146 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
147 &Curmonster
.m_type
, &Curmonster
.m_flock
);
149 strcpy(Curmonster
.m_name
, Databuf
);
150 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
155 Error("Writing %s.\n", path
);
160 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
161 /* write to motd file */
162 printf("One line 'motd' ? ");
163 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
165 path
= strrchr(_PATH_MOTD
, '/') + 1;
166 if ((fp
= fopen(path
, "w")) == NULL
)
167 Error("Cannot update %s.\n", path
);
170 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
174 /* report compile-time options */
175 printf("Compiled options:\n\n");
176 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
177 printf("Wizard: root UID: 0\n");
180 printf("Compiled for BSD 4.1\n");
184 printf("Compiled for BSD 4.2\n");
188 printf("Compiled for System III\n");
192 printf("Compiled for System V\n");
200 /************************************************************************
202 / FUNCTION NAME: Error()
204 / FUNCTION: print an error message, and exit
206 / AUTHOR: E. A. Estes, 12/4/85
209 / char *str - format string for printf()
210 / char *file - file which caused error
214 / MODULES CALLED: exit(), perror(), fprintf()
216 / GLOBAL INPUTS: _iob[]
218 / GLOBAL OUTPUTS: none
221 / Print an error message, then exit.
223 / ************************************************************************/
226 Error(const char *str
, const char *file
)
228 fprintf(stderr
, "Error: ");
229 fprintf(stderr
, str
, file
);
235 /************************************************************************
237 / FUNCTION NAME: drandom()
239 / FUNCTION: return a random number
241 / AUTHOR: E. A. Estes, 2/7/86
247 / MODULES CALLED: random()
249 / GLOBAL INPUTS: none
251 / GLOBAL OUTPUTS: none
255 / ************************************************************************/
260 if (sizeof(int) != 2)
261 return((double) (random() & 0x7fff) / 32768.0);
263 return((double) random() / 32768.0);