]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.14 2004/12/09 05:15:59 jmc Exp $ */
4 * setup.c - set up all files for Phantasia
11 int main(int, char *[]);
12 void Error(const char *, const char *) __attribute__((__noreturn__
));
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 /* Initialize an empty file placeholder for the grail location. */
113 if ((fp
= fopen(path
, "w")) == NULL
)
114 Error("Cannot create %s.\n", path
);
117 /* create binary monster data base */
118 path
= strrchr(_PATH_MONST
, '/') + 1;
119 if ((Monstfp
= fopen(path
, "w")) == NULL
)
120 Error("Cannot update %s.\n", path
);
123 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
126 Error("cannot open %s to create monster database.\n", "monsters.asc");
130 Curmonster
.m_o_strength
=
131 Curmonster
.m_o_speed
=
132 Curmonster
.m_maxspeed
=
133 Curmonster
.m_o_energy
=
135 Curmonster
.m_skirmish
= 0.0;
137 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
138 /* read in text file, convert to binary */
140 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
141 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
142 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
143 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
144 &Curmonster
.m_type
, &Curmonster
.m_flock
);
146 strcpy(Curmonster
.m_name
, Databuf
);
147 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
152 Error("Writing %s.\n", path
);
157 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
158 /* write to motd file */
159 printf("One line 'motd' ? ");
160 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
162 path
= strrchr(_PATH_MOTD
, '/') + 1;
163 if ((fp
= fopen(path
, "w")) == NULL
)
164 Error("Cannot update %s.\n", path
);
167 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
171 /* report compile-time options */
172 printf("Compiled options:\n\n");
173 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
174 printf("Wizard: root UID: 0\n");
177 printf("Compiled for BSD 4.1\n");
181 printf("Compiled for BSD 4.2\n");
185 printf("Compiled for System III\n");
189 printf("Compiled for System V\n");
197 /************************************************************************
199 / FUNCTION NAME: Error()
201 / FUNCTION: print an error message, and exit
203 / AUTHOR: E. A. Estes, 12/4/85
206 / char *str - format string for printf()
207 / char *file - file which caused error
211 / MODULES CALLED: exit(), perror(), fprintf()
213 / GLOBAL INPUTS: _iob[]
215 / GLOBAL OUTPUTS: none
218 / Print an error message, then exit.
220 / ************************************************************************/
224 const char *str
, *file
;
226 fprintf(stderr
, "Error: ");
227 fprintf(stderr
, str
, file
);
233 /************************************************************************
235 / FUNCTION NAME: drandom()
237 / FUNCTION: return a random number
239 / AUTHOR: E. A. Estes, 2/7/86
245 / MODULES CALLED: random()
247 / GLOBAL INPUTS: none
249 / GLOBAL OUTPUTS: none
253 / ************************************************************************/
258 if (sizeof(int) != 2)
259 return((double) (random() & 0x7fff) / 32768.0);
261 return((double) random() / 32768.0);