]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.18 2008/01/16 23:23:25 lukem 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";
75 const char *const *filename
; /* for pointing to file names */
76 int fd
; /* file descriptor */
77 FILE *fp
; /* for opening files */
78 struct stat fbuf
; /* for getting files statistics */
82 while ((ch
= getopt(argc
, argv
, "m:")) != -1)
94 srandom((unsigned) time(NULL
)); /* prime random numbers */
96 umask(0117); /* only owner can read/write created files */
98 /* try to create data files */
100 while (*filename
!= NULL
)
101 /* create each file */
103 path
= strrchr(*filename
, '/') + 1;
104 if (stat(path
, &fbuf
) == 0)
105 /* file exists; remove it */
107 if (unlink(path
) < 0)
108 Error("Cannot unlink %s.\n", path
);
112 if ((fd
= creat(path
, 0660)) < 0)
113 Error("Cannot create %s.\n", path
);
116 close(fd
); /* close newly created file */
118 ++filename
; /* process next file */
121 /* Initialize an empty file placeholder for the grail location. */
122 if ((fp
= fopen(path
, "w")) == NULL
)
123 Error("Cannot create %s.\n", path
);
126 /* create binary monster data base */
127 path
= strrchr(_PATH_MONST
, '/') + 1;
128 if ((Monstfp
= fopen(path
, "w")) == NULL
)
129 Error("Cannot update %s.\n", path
);
132 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
135 Error("cannot open %s to create monster database.\n", "monsters.asc");
139 Curmonster
.m_o_strength
=
140 Curmonster
.m_o_speed
=
141 Curmonster
.m_maxspeed
=
142 Curmonster
.m_o_energy
=
144 Curmonster
.m_skirmish
= 0.0;
146 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
147 /* read in text file, convert to binary */
149 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
150 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
151 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
152 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
153 &Curmonster
.m_type
, &Curmonster
.m_flock
);
155 strcpy(Curmonster
.m_name
, Databuf
);
156 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
161 Error("Writing %s.\n", path
);
166 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
167 /* write to motd file */
168 printf("One line 'motd' ? ");
169 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
171 path
= strrchr(_PATH_MOTD
, '/') + 1;
172 if ((fp
= fopen(path
, "w")) == NULL
)
173 Error("Cannot update %s.\n", path
);
176 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
180 /* report compile-time options */
181 printf("Compiled options:\n\n");
182 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
183 printf("Wizard: root UID: 0\n");
186 printf("Compiled for BSD 4.1\n");
190 printf("Compiled for BSD 4.2\n");
194 printf("Compiled for System III\n");
198 printf("Compiled for System V\n");
206 /************************************************************************
208 / FUNCTION NAME: Error()
210 / FUNCTION: print an error message, and exit
212 / AUTHOR: E. A. Estes, 12/4/85
215 / char *str - format string for printf()
216 / char *file - file which caused error
220 / MODULES CALLED: exit(), perror(), fprintf()
222 / GLOBAL INPUTS: _iob[]
224 / GLOBAL OUTPUTS: none
227 / Print an error message, then exit.
229 / ************************************************************************/
233 const char *str
, *file
;
235 fprintf(stderr
, "Error: ");
236 fprintf(stderr
, str
, file
);
242 /************************************************************************
244 / FUNCTION NAME: drandom()
246 / FUNCTION: return a random number
248 / AUTHOR: E. A. Estes, 2/7/86
254 / MODULES CALLED: random()
256 / GLOBAL INPUTS: none
258 / GLOBAL OUTPUTS: none
262 / ************************************************************************/
267 if (sizeof(int) != 2)
268 return((double) (random() & 0x7fff) / 32768.0);
270 return((double) random() / 32768.0);