Difference between revisions of "Source:NetHack 3.0.0/makedefs.c"
Jump to navigation
Jump to search
m (Automated source code upload) |
Kernigh bot (talk | contribs) m (NetHack 3.0.0/makedefs.c moved to Source:NetHack 3.0.0/makedefs.c: Robot: moved page) |
(No difference)
|
Latest revision as of 04:50, 4 March 2008
Below is the full text to makedefs.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/makedefs.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 2. /* NetHack may be freely redistributed. See license for details. */ 3. /* makedefs.c - NetHack version 3.0 */ 4. 5. #define MAKEDEFS_C 6. 7. #define EXTERN_H 8. #include "config.h" 9. #include "permonst.h" 10. #include "objclass.h" 11. #ifdef NULL 12. #undef NULL 13. #endif /* NULL */ 14. #define NULL ((genericptr_t)0) 15. 16. #ifndef LINT 17. static const char SCCS_Id[] = "@(#)makedefs.c\t3.0\t89/01/10"; 18. #endif 19. 20. #ifdef MSDOS 21. # define freopen _freopen 22. # undef exit 23. extern void exit P((int)); 24. # define RDMODE "r" 25. # define WRMODE "w" 26. #else 27. # define RDMODE "r+" 28. # define WRMODE "w+" 29. #endif 30. #if defined(SYSV) || defined(GENIX) || defined(UNIXDEBUG) 31. void rename(); 32. #endif 33. #ifdef AMIGA 34. # undef freopen 35. # undef printf 36. # undef puts 37. # undef fflush 38. # define fflush FFLUSH 39. # undef fputs 40. # undef fprintf 41. #endif 42. 43. /* construct definitions of object constants */ 44. 45. #ifdef AMIGA 46. # define MONST_FILE "include:pm.h" 47. # define ONAME_FILE "include:onames.h" 48. # define TRAP_FILE "include:trap.h" 49. # define DATE_FILE "include:date.h" 50. # define DATA_FILE "auxil:data" 51. # define RUMOR_FILE "auxil:rumors" 52. #else 53. # define MONST_FILE "../include/pm.h" 54. # define ONAME_FILE "../include/onames.h" 55. # define TRAP_FILE "../include/trap.h" 56. # define DATE_FILE "../include/date.h" 57. # define DATA_FILE "../auxil/data" 58. # define RUMOR_FILE "../auxil/rumors" 59. #endif 60. 61. char in_line[256]; 62. extern char *gets P((char *)); 63. void do_objs(), do_traps(), do_data(), do_date(), do_permonst(), do_rumors(); 64. char *limit P((char *,boolean)); 65. FILE *_freopen(); 66. 67. int 68. main(argc, argv) 69. int argc; 70. char *argv[]; 71. { 72. char *option; 73. 74. if(argc == 2) { 75. option = argv[1]; 76. switch (option[1]) { 77. 78. case 'o': 79. case 'O': do_objs(); 80. break; 81. case 't': 82. case 'T': do_traps(); 83. break; 84. 85. case 'd': 86. case 'D': do_data(); 87. break; 88. 89. case 'v': 90. case 'V': do_date(); 91. break; 92. 93. case 'p': 94. case 'P': do_permonst(); 95. break; 96. 97. case 'r': 98. case 'R': do_rumors(); 99. break; 100. 101. default: 102. (void) fprintf(stderr, "Unknown option '%c'.\n", option[1]); 103. (void) fflush(stderr); 104. exit(1); 105. } 106. exit(0); 107. } else (void) fprintf(stderr, "Bad arg count (%d).\n", argc-1); 108. (void) fflush(stderr); 109. exit(1); 110. /*NOTREACHED*/ 111. #ifdef MSDOS 112. return 0; 113. #endif 114. } 115. 116. void 117. do_traps() { 118. int ntrap; 119. char tempfile[30]; 120. 121. Sprintf(tempfile, "makedefs.%d", getpid()); 122. if(freopen(tempfile, WRMODE, stdout) == (FILE *)0) { 123. perror(tempfile); 124. exit(1); 125. } 126. 127. if(freopen(TRAP_FILE, RDMODE, stdin) == (FILE *)0) { 128. perror(TRAP_FILE); 129. exit(1); 130. } 131. 132. while(gets(in_line) != NULL) { 133. (void) puts(in_line); 134. if(!strncmp(in_line, "/* DO NOT REMOVE THIS LINE */", 29)) break; 135. } 136. ntrap = 10; 137. Printf("\n"); 138. Printf("#define\tMGTRP\t\t%d\n", ntrap++); 139. Printf("#define\tSQBRD\t\t%d\n", ntrap++); 140. Printf("#define\tWEB\t\t%d\n", ntrap++); 141. Printf("#define\tSPIKED_PIT\t%d\n", ntrap++); 142. Printf("#define\tLEVEL_TELEP\t%d\n", ntrap++); 143. #ifdef SPELLS 144. Printf("#define\tANTI_MAGIC\t%d\n", ntrap++); 145. #endif 146. Printf("#define\tRUST_TRAP\t%d\n", ntrap++); 147. #ifdef POLYSELF 148. Printf("#define\tPOLY_TRAP\t%d\n", ntrap++); 149. #endif 150. Printf("#define\tLANDMINE\t%d\n", ntrap++); 151. Printf("\n#define\tTRAPNUM\t%d\n", ntrap); 152. Printf("\n#endif /* TRAP_H /**/\n"); 153. (void) fclose(stdin); 154. (void) fclose(stdout); 155. #ifdef MSDOS 156. remove(TRAP_FILE); 157. #endif 158. rename(tempfile, TRAP_FILE); 159. return; 160. } 161. 162. 163. void 164. do_rumors(){ 165. char infile[30]; 166. FILE *freopen(); 167. long true_rumor_size; 168. 169. if(freopen(RUMOR_FILE, WRMODE, stdout) == (FILE *)0) { 170. perror(RUMOR_FILE); 171. exit(1); 172. } 173. 174. Sprintf(infile, "%s.tru", RUMOR_FILE); 175. if(freopen(infile, RDMODE, stdin) == (FILE *)0) { 176. perror(infile); 177. exit(1); 178. } 179. 180. /* get size of true rumors file */ 181. (void) fseek(stdin, 0L, 2); 182. true_rumor_size = ftell(stdin); 183. (void) fwrite((genericptr_t)&true_rumor_size,sizeof(long),1,stdout); 184. (void) fseek(stdin, 0L, 0); 185. 186. /* copy true rumors */ 187. while(gets(in_line) != NULL) (void) puts(in_line); 188. 189. Sprintf(infile, "%s.fal", RUMOR_FILE); 190. if(freopen(infile, RDMODE, stdin) == (FILE *)0) { 191. perror(infile); 192. exit(1); 193. } 194. 195. /* copy false rumors */ 196. while(gets(in_line) != NULL) (void) puts(in_line); 197. 198. (void) fclose(stdin); 199. (void) fclose(stdout); 200. return; 201. } 202. 203. #ifdef SYSV 204. extern long time(); 205. #endif 206. 207. void 208. do_date(){ 209. long clock; 210. char cbuf[30], *c; 211. 212. if(freopen(DATE_FILE, WRMODE, stdout) == (FILE *)0) { 213. perror(DATE_FILE); 214. exit(1); 215. } 216. Printf("/*\tSCCS Id: @(#)date.h\t3.0\t88/11/20 */\n\n"); 217. 218. (void) time(&clock); 219. Strcpy(cbuf, ctime(&clock)); 220. for(c = cbuf; *c != '\n'; c++); *c = 0; /* strip off the '\n' */ 221. Printf("const char datestring[] = \"%s\";\n", cbuf); 222. 223. (void) fclose(stdout); 224. return; 225. } 226. 227. void 228. do_data(){ 229. char tempfile[30]; 230. 231. Sprintf(tempfile, "%s.base", DATA_FILE); 232. if(freopen(tempfile, RDMODE, stdin) == (FILE *)0) { 233. perror(tempfile); 234. exit(1); 235. } 236. 237. if(freopen(DATA_FILE, WRMODE, stdout) == (FILE *)0) { 238. perror(DATA_FILE); 239. exit(1); 240. } 241. 242. while(gets(in_line) != NULL) { 243. #ifdef SINKS 244. if(!strcmp(in_line, "#\ta corridor")) 245. Printf("#\ta corridor (or a kitchen sink)\n"); 246. else 247. #endif 248. #ifdef ALTARS 249. if(!strcmp(in_line, "_\tan iron chain")) 250. Printf("_\tan iron chain (or an altar)\n"); 251. else 252. #endif 253. #ifdef SPELLS 254. if(!strcmp(in_line, "+\ta door")) 255. Printf("+\ta door (or a spell book)\n"); 256. else 257. #endif 258. #ifdef FOUNTAINS 259. if(!strcmp(in_line, "}\twater filled area")) { 260. (void) puts(in_line); 261. Printf("{\ta fountain\n"); 262. } else 263. #endif 264. #ifdef THRONES 265. if(!strcmp(in_line, "^\ta trap")) { 266. (void) puts(in_line); 267. Printf("\\\tan opulent throne\n"); 268. } else 269. #endif 270. if(!strcmp(in_line, ";\ta giant eel")) { 271. (void) puts(in_line); 272. #ifdef WORM 273. Printf("~\tthe tail of a long worm\n"); 274. #endif 275. #ifdef GOLEMS 276. Printf("'\ta golem\n"); 277. Printf("\t\tThese creatures, not quite living but not really nonliving\n"); 278. Printf("\t\teither, are created from inanimate materials by powerful\n"); 279. Printf("\t\tmages or priests.\n"); 280. #endif 281. } else 282. (void) puts(in_line); 283. } 284. (void) fclose(stdin); 285. (void) fclose(stdout); 286. return; 287. } 288. 289. void 290. do_permonst() { 291. 292. int i; 293. char *c; 294. 295. if(freopen(MONST_FILE, WRMODE, stdout) == (FILE *)0) { 296. perror(MONST_FILE); 297. exit(1); 298. } 299. Printf("/*\tSCCS Id: @(#)pm.h\t3.0\t88/11/20 */\n\n"); 300. Printf("#ifndef PM_H\n#define PM_H\n"); 301. 302. for(i = 0; mons[i].mlet; i++) { 303. Printf("\n#define\tPM_"); 304. for(c = mons[i].mname; *c; c++) { 305. if((*c >= 'a') && (*c <= 'z')) *c -= (char)('a' - 'A'); 306. else if(*c == ' ' || *c == '-') *c = '_'; 307. } 308. Printf("%s\t%d", mons[i].mname, i); 309. } 310. Printf("\n\n#define\tNUMMONS\t%d\n", i); 311. Printf("\n#endif /* PM_H /**/\n"); 312. (void) fclose(stdout); 313. return; 314. } 315. 316. static char temp[32]; 317. 318. char * 319. limit(name,pref) /* limit a name to 30 characters length */ 320. char *name; 321. boolean pref; 322. { 323. (void) strncpy(temp, name, pref ? 26 : 30); 324. temp[pref ? 26 : 30] = 0; 325. return temp; 326. } 327. 328. void 329. do_objs() { 330. 331. register int i = 0, sum = 0; 332. register char *c; 333. #ifdef SPELLS 334. register int nspell = 0; 335. #endif 336. register boolean prefix = 0; 337. register char let = '\0'; 338. boolean sumerr = FALSE; 339. 340. if(freopen(ONAME_FILE, WRMODE, stdout) == (FILE *)0) { 341. perror(ONAME_FILE); 342. exit(1); 343. } 344. Printf("/*\tSCCS Id: @(#)onames.h\t3.0\t89/01/10 */\n\n"); 345. Printf("#ifndef ONAMES_H\n#define ONAMES_H\n\n"); 346. 347. for(i = 0; !i || objects[i].oc_olet != ILLOBJ_SYM; i++) { 348. if (!(c = objects[i].oc_name)) continue; 349. 350. /* make sure probabilities add up to 1000 */ 351. if(objects[i].oc_olet != let) { 352. if (sum && sum != 1000) { 353. (void) fprintf(stderr, "prob error for %c (%d%%)", let, sum); 354. (void) fflush(stderr); 355. sumerr = TRUE; 356. } 357. let = objects[i].oc_olet; 358. sum = 0; 359. } 360. 361. for(; *c; c++) { 362. if((*c >= 'a') && (*c <= 'z')) *c -= (char)('a' - 'A'); 363. else if(*c == ' ' || *c == '-') *c = '_'; 364. } 365. 366. switch (let) { 367. case WAND_SYM: 368. Printf("#define\tWAN_"); prefix = 1; break; 369. case RING_SYM: 370. Printf("#define\tRIN_"); prefix = 1; break; 371. case POTION_SYM: 372. Printf("#define\tPOT_"); prefix = 1; break; 373. #ifdef SPELLS 374. case SPBOOK_SYM: 375. Printf("#define\tSPE_"); prefix = 1; nspell++; break; 376. #endif 377. case SCROLL_SYM: 378. Printf("#define\tSCR_"); prefix = 1; break; 379. case GEM_SYM: 380. /* avoid trouble with stupid C preprocessors */ 381. if(objects[i].oc_material == GLASS) { 382. Printf("/* #define\t%s\t%d */\n", objects[i].oc_name, i); 383. continue; 384. } 385. default: 386. Printf("#define\t"); 387. } 388. Printf("%s\t%d\n", limit(objects[i].oc_name, prefix), i); 389. prefix = 0; 390. 391. sum += objects[i].oc_prob; 392. } 393. Printf("#define\tLAST_GEM\t(JADE+1)\n"); 394. #ifdef SPELLS 395. Printf("#define\tMAXSPELL\t%d\n", nspell+1); 396. #endif 397. Printf("#define\tNROFOBJECTS\t%d\n", i-1); 398. Printf("\n#endif /* ONAMES_H /**/\n"); 399. (void) fclose(stdout); 400. if (sumerr) exit(1); 401. return; 402. } 403. 404. #if defined(SYSV) || defined(GENIX) || defined(UNIXDEBUG) 405. void 406. rename(oldname, newname) 407. char *oldname, *newname; 408. { 409. if (strcmp(oldname, newname)) { 410. (void) unlink(newname); 411. (void) link(oldname, newname); 412. (void) unlink(oldname); 413. } 414. return; 415. } 416. #endif 417. 418. #ifdef MSDOS 419. # ifndef AMIGA 420. /* Get around bug in freopen when opening for writing */ 421. /* Supplied by Nathan Glasser (nathan@mit-eddie) */ 422. #undef freopen 423. FILE * 424. _freopen(fname, fmode, fp) 425. char *fname, *fmode; 426. FILE *fp; 427. { 428. if (!strncmp(fmode,"w",1)) 429. { 430. FILE *tmpfp; 431. 432. if ((tmpfp = fopen(fname,fmode)) == (FILE *)0) 433. return (FILE *)0; 434. if (dup2(fileno(tmpfp),fileno(fp)) < 0) 435. return (FILE *)0; 436. (void) fclose(tmpfp); 437. return fp; 438. } 439. else 440. return freopen(fname,fmode,fp); 441. } 442. # endif /* AMIGA */ 443. 444. # if defined(__TURBOC__) || defined(AMIGA) 445. int 446. getpid() 447. { 448. return 1; 449. } 450. # endif 451. #endif /* MSDOS */