1:
2:
3:
4:
5:
6: #include <sys/param.h>
7: #include <sys/stat.h>
8: #include <fcntl.h>
9: #include "include.h"
10:
11: int main(int, char *[]);
12: void Error(const char *, const char *) __attribute__((__noreturn__));
13: double drandom(void);
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47: static const char *const files[] = {
48: _PATH_MONST,
49: _PATH_PEOPLE,
50: _PATH_MESS,
51: _PATH_LASTDEAD,
52: _PATH_MOTD,
53: _PATH_GOLD,
54: _PATH_VOID,
55: _PATH_SCORE,
56: NULL,
57: };
58:
59: const char *monsterfile = "monsters.asc";
60:
61: int
62: main(argc, argv)
63: int argc;
64: char *argv[];
65: {
66: const char *const *filename;
67: int fd;
68: FILE *fp;
69: struct stat fbuf;
70: int ch;
71: char *path;
72:
73: while ((ch = getopt(argc, argv, "m:")) != -1)
74: switch(ch) {
75: case 'm':
76: monsterfile = optarg;
77: break;
78: case '?':
79: default:
80: break;
81: }
82: argc -= optind;
83: argv += optind;
84:
85: srandom((unsigned) time(NULL));
86:
87: umask(0117);
88:
89:
90: filename = &files[0];
91: while (*filename != NULL)
92:
93: {
94: path = strrchr(*filename, '/') + 1;
95: if (stat(path, &fbuf) == 0)
96:
97: {
98: if (unlink(path) < 0)
99: Error("Cannot unlink %s.\n", path);
100:
101: }
102:
103: if ((fd = creat(path, 0660)) < 0)
104: Error("Cannot create %s.\n", path);
105:
106:
107: close(fd);
108:
109: ++filename;
110: }
111:
112:
113: if ((fp = fopen(path, "w")) == NULL)
114: Error("Cannot create %s.\n", path);
115: fclose(fp);
116:
117:
118: path = strrchr(_PATH_MONST, '/') + 1;
119: if ((Monstfp = fopen(path, "w")) == NULL)
120: Error("Cannot update %s.\n", path);
121: else
122: {
123: if ((fp = fopen(monsterfile, "r")) == NULL)
124: {
125: fclose(Monstfp);
126: Error("cannot open %s to create monster database.\n", "monsters.asc");
127: }
128: else
129: {
130: Curmonster.m_o_strength =
131: Curmonster.m_o_speed =
132: Curmonster.m_maxspeed =
133: Curmonster.m_o_energy =
134: Curmonster.m_melee =
135: Curmonster.m_skirmish = 0.0;
136:
137: while (fgets(Databuf, SZ_DATABUF, fp) != NULL)
138:
139: {
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);
145: Databuf[24] = '\0';
146: strcpy(Curmonster.m_name, Databuf);
147: fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
148: }
149: fclose(fp);
150: fflush(Monstfp);
151: if (ferror(Monstfp))
152: Error("Writing %s.\n", path);
153: fclose(Monstfp);
154: }
155: }
156:
157: #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
158:
159: printf("One line 'motd' ? ");
160: if (fgets(Databuf, SZ_DATABUF, stdin) == NULL)
161: Databuf[0] = '\0';
162: path = strrchr(_PATH_MOTD, '/') + 1;
163: if ((fp = fopen(path, "w")) == NULL)
164: Error("Cannot update %s.\n", path);
165: else
166: {
167: fwrite(Databuf, sizeof(char), strlen(Databuf), fp);
168: fclose(fp);
169: }
170:
171:
172: printf("Compiled options:\n\n");
173: printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR);
174: printf("Wizard: root UID: 0\n");
175:
176: #ifdef BSD41
177: printf("Compiled for BSD 4.1\n");
178: #endif
179:
180: #ifdef BSD42
181: printf("Compiled for BSD 4.2\n");
182: #endif
183:
184: #ifdef SYS3
185: printf("Compiled for System III\n");
186: #endif
187:
188: #ifdef SYS5
189: printf("Compiled for System V\n");
190: #endif
191: #endif
192:
193: exit(0);
194:
195: }
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222: void
223: Error(str, file)
224: const char *str, *file;
225: {
226: fprintf(stderr, "Error: ");
227: fprintf(stderr, str, file);
228: perror(file);
229: exit(1);
230:
231: }
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255: double
256: drandom()
257: {
258: if (sizeof(int) != 2)
259: return((double) (random() & 0x7fff) / 32768.0);
260: else
261: return((double) random() / 32768.0);
262: }