]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.19 2009/05/25 23:08:45 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 #ifndef __dead /* Not NetBSD */
20 int main(int, char *[]);
21 void Error(const char *, const char *) __dead
;
25 /************************************************************************
27 / FUNCTION NAME: main()
29 / FUNCTION: setup files for Phantasia 3.3.2
31 / AUTHOR: E. A. Estes, 12/4/85
37 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
38 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
39 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
41 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
43 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
47 / This program tries to verify the parameters specified in
50 / Create all necessary files. Note that nothing needs to be
52 / Also, the monster binary data base is created here.
54 / ************************************************************************/
56 static const char *const files
[] = { /* all files to create */
68 const char *monsterfile
= "monsters.asc";
71 main(int argc
, char *argv
[])
73 const char *const *filename
; /* for pointing to file names */
74 int fd
; /* file descriptor */
75 FILE *fp
; /* for opening files */
76 struct stat fbuf
; /* for getting files statistics */
80 while ((ch
= getopt(argc
, argv
, "m:")) != -1)
92 srandom((unsigned) time(NULL
)); /* prime random numbers */
94 umask(0117); /* only owner can read/write created files */
96 /* try to create data files */
98 while (*filename
!= NULL
)
99 /* create each file */
101 path
= strrchr(*filename
, '/') + 1;
102 if (stat(path
, &fbuf
) == 0)
103 /* file exists; remove it */
105 if (unlink(path
) < 0)
106 Error("Cannot unlink %s.\n", path
);
110 if ((fd
= creat(path
, 0660)) < 0)
111 Error("Cannot create %s.\n", path
);
114 close(fd
); /* close newly created file */
116 ++filename
; /* process next file */
119 /* Initialize an empty file placeholder for the grail location. */
120 if ((fp
= fopen(path
, "w")) == NULL
)
121 Error("Cannot create %s.\n", path
);
124 /* create binary monster data base */
125 path
= strrchr(_PATH_MONST
, '/') + 1;
126 if ((Monstfp
= fopen(path
, "w")) == NULL
)
127 Error("Cannot update %s.\n", path
);
130 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
133 Error("cannot open %s to create monster database.\n", "monsters.asc");
137 Curmonster
.m_o_strength
=
138 Curmonster
.m_o_speed
=
139 Curmonster
.m_maxspeed
=
140 Curmonster
.m_o_energy
=
142 Curmonster
.m_skirmish
= 0.0;
144 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
145 /* read in text file, convert to binary */
147 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
148 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
149 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
150 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
151 &Curmonster
.m_type
, &Curmonster
.m_flock
);
153 strcpy(Curmonster
.m_name
, Databuf
);
154 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
159 Error("Writing %s.\n", path
);
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 path
= strrchr(_PATH_MOTD
, '/') + 1;
170 if ((fp
= fopen(path
, "w")) == NULL
)
171 Error("Cannot update %s.\n", path
);
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", _PATH_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 / ************************************************************************/
230 Error(const char *str
, const char *file
)
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);