]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.16 2007/12/15 19:44:42 perry Exp $ */
4 * setup.c - set up all files for Phantasia
12 int main(int, char *[]);
13 void Error(const char *, const char *) __dead
;
17 /************************************************************************
19 / FUNCTION NAME: main()
21 / FUNCTION: setup files for Phantasia 3.3.2
23 / AUTHOR: E. A. Estes, 12/4/85
29 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
30 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
31 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
33 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
35 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
39 / This program tries to verify the parameters specified in
42 / Create all necessary files. Note that nothing needs to be
44 / Also, the monster binary data base is created here.
46 / ************************************************************************/
48 static const char *const files
[] = { /* all files to create */
60 const char *monsterfile
= "monsters.asc";
67 const char *const *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 */
74 while ((ch
= getopt(argc
, argv
, "m:")) != -1)
86 srandom((unsigned) time(NULL
)); /* prime random numbers */
88 umask(0117); /* only owner can read/write created files */
90 /* try to create data files */
92 while (*filename
!= NULL
)
93 /* create each file */
95 path
= strrchr(*filename
, '/') + 1;
96 if (stat(path
, &fbuf
) == 0)
97 /* file exists; remove it */
100 Error("Cannot unlink %s.\n", path
);
104 if ((fd
= creat(path
, 0660)) < 0)
105 Error("Cannot create %s.\n", path
);
108 close(fd
); /* close newly created file */
110 ++filename
; /* process next file */
113 /* Initialize an empty file placeholder for the grail location. */
114 if ((fp
= fopen(path
, "w")) == NULL
)
115 Error("Cannot create %s.\n", path
);
118 /* create binary monster data base */
119 path
= strrchr(_PATH_MONST
, '/') + 1;
120 if ((Monstfp
= fopen(path
, "w")) == NULL
)
121 Error("Cannot update %s.\n", path
);
124 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
127 Error("cannot open %s to create monster database.\n", "monsters.asc");
131 Curmonster
.m_o_strength
=
132 Curmonster
.m_o_speed
=
133 Curmonster
.m_maxspeed
=
134 Curmonster
.m_o_energy
=
136 Curmonster
.m_skirmish
= 0.0;
138 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
139 /* read in text file, convert to binary */
141 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
142 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
143 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
144 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
145 &Curmonster
.m_type
, &Curmonster
.m_flock
);
147 strcpy(Curmonster
.m_name
, Databuf
);
148 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
153 Error("Writing %s.\n", path
);
158 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
159 /* write to motd file */
160 printf("One line 'motd' ? ");
161 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
163 path
= strrchr(_PATH_MOTD
, '/') + 1;
164 if ((fp
= fopen(path
, "w")) == NULL
)
165 Error("Cannot update %s.\n", path
);
168 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
172 /* report compile-time options */
173 printf("Compiled options:\n\n");
174 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
175 printf("Wizard: root UID: 0\n");
178 printf("Compiled for BSD 4.1\n");
182 printf("Compiled for BSD 4.2\n");
186 printf("Compiled for System III\n");
190 printf("Compiled for System V\n");
198 /************************************************************************
200 / FUNCTION NAME: Error()
202 / FUNCTION: print an error message, and exit
204 / AUTHOR: E. A. Estes, 12/4/85
207 / char *str - format string for printf()
208 / char *file - file which caused error
212 / MODULES CALLED: exit(), perror(), fprintf()
214 / GLOBAL INPUTS: _iob[]
216 / GLOBAL OUTPUTS: none
219 / Print an error message, then exit.
221 / ************************************************************************/
225 const char *str
, *file
;
227 fprintf(stderr
, "Error: ");
228 fprintf(stderr
, str
, file
);
234 /************************************************************************
236 / FUNCTION NAME: drandom()
238 / FUNCTION: return a random number
240 / AUTHOR: E. A. Estes, 2/7/86
246 / MODULES CALLED: random()
248 / GLOBAL INPUTS: none
250 / GLOBAL OUTPUTS: none
254 / ************************************************************************/
259 if (sizeof(int) != 2)
260 return((double) (random() & 0x7fff) / 32768.0);
262 return((double) random() / 32768.0);