]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.11 2001/03/27 02:23:28 simonb Exp $ */
4 * setup.c - set up all files for Phantasia
11 int main
__P((int, char *[]));
12 void Error
__P((const char *, const char *)) __attribute__((__noreturn__
));
13 double drandom
__P((void));
16 /************************************************************************
18 / FUNCTION NAME: main()
20 / FUNCTION: setup files for Phantasia 3.3.2
22 / AUTHOR: E. A. Estes, 12/4/85
28 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
29 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
30 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
32 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
34 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
38 / This program tries to verify the parameters specified in
41 / Create all necessary files. Note that nothing needs to be
43 / Also, the monster binary data base is created here.
45 / ************************************************************************/
47 static const char *const files
[] = { /* all files to create */
59 const char *monsterfile
= "monsters.asc";
66 const char *const *filename
; /* for pointing to file names */
67 int fd
; /* file descriptor */
68 FILE *fp
; /* for opening files */
69 struct stat fbuf
; /* for getting files statistics */
73 while ((ch
= getopt(argc
, argv
, "m:")) != -1)
85 srandom((unsigned) time(NULL
)); /* prime random numbers */
87 umask(0117); /* only owner can read/write created files */
89 /* try to create data files */
91 while (*filename
!= NULL
)
92 /* create each file */
94 path
= strrchr(*filename
, '/') + 1;
95 if (stat(path
, &fbuf
) == 0)
96 /* file exists; remove it */
99 Error("Cannot unlink %s.\n", path
);
103 if ((fd
= creat(path
, 0660)) < 0)
104 Error("Cannot create %s.\n", path
);
107 close(fd
); /* close newly created file */
109 ++filename
; /* process next file */
112 /* put holy grail info into energy void file */
113 Enrgyvoid
.ev_active
= TRUE
;
114 Enrgyvoid
.ev_x
= ROLL(-1.0e6
, 2.0e6
);
115 Enrgyvoid
.ev_y
= ROLL(-1.0e6
, 2.0e6
);
116 path
= strrchr(_PATH_VOID
, '/') + 1;
117 if ((fp
= fopen(path
, "w")) == NULL
)
118 Error("Cannot update %s.\n", path
);
121 fwrite(&Enrgyvoid
, SZ_VOIDSTRUCT
, 1, fp
);
124 Error("Writing %s.\n", path
);
128 /* create binary monster data base */
129 path
= strrchr(_PATH_MONST
, '/') + 1;
130 if ((Monstfp
= fopen(path
, "w")) == NULL
)
131 Error("Cannot update %s.\n", path
);
134 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
137 Error("cannot open %s to create monster database.\n", "monsters.asc");
141 Curmonster
.m_o_strength
=
142 Curmonster
.m_o_speed
=
143 Curmonster
.m_maxspeed
=
144 Curmonster
.m_o_energy
=
146 Curmonster
.m_skirmish
= 0.0;
148 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
149 /* read in text file, convert to binary */
151 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
152 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
153 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
154 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
155 &Curmonster
.m_type
, &Curmonster
.m_flock
);
157 strcpy(Curmonster
.m_name
, Databuf
);
158 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
163 Error("Writing %s.\n", path
);
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 path
= strrchr(_PATH_MOTD
, '/') + 1;
174 if ((fp
= fopen(path
, "w")) == NULL
)
175 Error("Cannot update %s.\n", path
);
178 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
182 /* report compile-time options */
183 printf("Compiled options:\n\n");
184 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
185 printf("Wizard: root UID: 0\n");
188 printf("Compiled for BSD 4.1\n");
192 printf("Compiled for BSD 4.2\n");
196 printf("Compiled for System III\n");
200 printf("Compiled for System V\n");
208 /************************************************************************
210 / FUNCTION NAME: Error()
212 / FUNCTION: print an error message, and exit
214 / AUTHOR: E. A. Estes, 12/4/85
217 / char *str - format string for printf()
218 / char *file - file which caused error
222 / MODULES CALLED: exit(), perror(), fprintf()
224 / GLOBAL INPUTS: _iob[]
226 / GLOBAL OUTPUTS: none
229 / Print an error message, then exit.
231 / ************************************************************************/
235 const char *str
, *file
;
237 fprintf(stderr
, "Error: ");
238 fprintf(stderr
, str
, file
);
244 /************************************************************************
246 / FUNCTION NAME: drandom()
248 / FUNCTION: return a random number
250 / AUTHOR: E. A. Estes, 2/7/86
256 / MODULES CALLED: random()
258 / GLOBAL INPUTS: none
260 / GLOBAL OUTPUTS: none
264 / ************************************************************************/
269 if (sizeof(int) != 2)
270 return((double) (random() & 0x7fff) / 32768.0);
272 return((double) random() / 32768.0);