Source:NetHack 2.2a/options.c
Jump to navigation
Jump to search
Below is the full text to options.c from the source code of NetHack 2.2a. To link to a particular line, write [[NetHack 2.2a/options.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
Screenshots and source code from Hack are used under the CWI license.
1. /* SCCS Id: @(#)options.c 2.0 87/09/14 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. 4. #include "config.h" 5. #include "hack.h" 6. extern char *eos(); 7. #ifdef SORTING 8. static boolean set_order; 9. #endif 10. 11. initoptions() 12. { 13. register char *opts; 14. extern char *getenv(); 15. 16. flags.time = flags.nonews = flags.notombstone = flags.end_own = 17. flags.standout = flags.nonull = FALSE; 18. flags.no_rest_on_space = TRUE; 19. flags.invlet_constant = TRUE; 20. flags.end_top = 5; 21. flags.end_around = 4; 22. flags.female = FALSE; /* players are usually male */ 23. #ifdef SORTING 24. flags.sortpack = TRUE; 25. #endif 26. #ifdef SAFE_ATTACK 27. flags.confirm = TRUE; 28. #endif 29. #ifdef DGKMOD 30. flags.silent = flags.pickup = TRUE; 31. #endif 32. #ifdef DGK 33. flags.IBMBIOS = flags.DECRainbow = flags.rawio = FALSE; 34. read_config_file(); 35. #endif 36. #ifdef HACKOPTIONS 37. if(opts = getenv("HACKOPTIONS")) 38. parseoptions(opts,TRUE); 39. #endif 40. } 41. 42. parseoptions(opts, from_env) 43. register char *opts; 44. boolean from_env; 45. { 46. register char *op,*op2; 47. unsigned num; 48. boolean negated; 49. 50. if(op = index(opts, ',')) { 51. *op++ = 0; 52. parseoptions(op, from_env); 53. } 54. if(op = index(opts, ' ')) { 55. op2 = op; 56. while(*op++) 57. if(*op != ' ') *op2++ = *op; 58. } 59. if(!*opts) return; 60. negated = FALSE; 61. while((*opts == '!') || !strncmp(opts, "no", 2)) { 62. if(*opts == '!') opts++; else opts += 2; 63. negated = !negated; 64. } 65. 66. #ifndef DGK 67. if(!strncmp(opts,"standout",4)) { 68. flags.standout = !negated; 69. return; 70. } 71. 72. if(!strncmp(opts,"null",4)) { 73. flags.nonull = negated; 74. return; 75. } 76. 77. if(!strncmp(opts,"tombstone",4)) { 78. flags.notombstone = negated; 79. return; 80. } 81. 82. if(!strncmp(opts,"news",4)) { 83. flags.nonews = negated; 84. return; 85. } 86. #endif 87. 88. #ifdef SAFE_ATTACK 89. if (!strncmp(opts, "conf", 4)) { 90. flags.confirm = !negated; 91. return; 92. } 93. 94. #endif 95. #ifdef DGKMOD 96. if (!strncmp(opts, "sile", 4)) { 97. flags.silent = !negated; 98. return; 99. } 100. 101. if (!strncmp(opts, "pick", 4)) { 102. flags.pickup = !negated; 103. return; 104. } 105. #endif 106. #ifdef DGK 107. if (!strncmp(opts, "IBMB", 4)) { 108. flags.IBMBIOS = !negated; 109. return; 110. } 111. 112. if (!strncmp(opts, "rawi", 4)) { 113. if (from_env) 114. flags.rawio = !negated; 115. else 116. pline("'rawio' only settable from %s.", configfile); 117. return; 118. } 119. 120. if (!strncmp(opts, "DECR", 4)) { 121. flags.DECRainbow = !negated; 122. return; 123. } 124. #endif 125. 126. #ifdef SORTING 127. if (!strncmp(opts, "sort", 4)) { 128. flags.sortpack = !negated; 129. return; 130. } 131. 132. /* 133. * the order to list the pack 134. */ 135. if (!strncmp(opts,"packorder",4)) { 136. register char *sp, *tmp; 137. extern char inv_order[]; 138. int tmpend; 139. 140. op = index(opts,':'); 141. if(!op) goto bad; 142. op++; /* skip : */ 143. 144. /* Missing characters in new order are filled in at the end 145. * from inv_order. 146. */ 147. for (sp = op; *sp; sp++) 148. if (!index(inv_order, *sp)) 149. goto bad; /* bad char in order */ 150. else if (index(sp + 1, *sp)) 151. goto bad; /* dup char in order */ 152. tmp = (char *) alloc(strlen(inv_order) + 1); 153. (void) strcpy(tmp, op); 154. for (sp = inv_order, tmpend = strlen(tmp); *sp; sp++) 155. if (!index(tmp, *sp)) { 156. tmp[tmpend++] = *sp; 157. tmp[tmpend] = 0; 158. } 159. (void) strcpy(inv_order, tmp); 160. free(tmp); 161. set_order = TRUE; 162. return; 163. } 164. #endif 165. 166. if(!strncmp(opts,"time",4)) { 167. flags.time = !negated; 168. flags.botl = 1; 169. return; 170. } 171. 172. if(!strncmp(opts,"restonspace",4)) { 173. flags.no_rest_on_space = negated; 174. return; 175. } 176. 177. if(!strncmp(opts,"fixinv",4)) { 178. flags.invlet_constant = !negated; 179. if(!from_env && flags.invlet_constant) reassign (); 180. return; 181. } 182. 183. if(!strncmp(opts,"male",4)) { 184. #ifdef KAA 185. if(!from_env && flags.female != negated) 186. pline("That is not anatomically possible."); 187. else 188. #endif 189. flags.female = negated; 190. return; 191. } 192. if(!strncmp(opts,"female",6)) { 193. #ifdef KAA 194. if(!from_env && flags.female == negated) 195. pline("That is not anatomically possible."); 196. else 197. #endif 198. flags.female = !negated; 199. return; 200. } 201. 202. /* name:string */ 203. if(!strncmp(opts,"name",4)) { 204. extern char plname[PL_NSIZ]; 205. if(!from_env) { 206. #ifdef DGK 207. pline("'name' only settable from %s.", configfile); 208. #else 209. pline("The playername can be set only from HACKOPTIONS."); 210. #endif 211. return; 212. } 213. op = index(opts,':'); 214. if(!op) goto bad; 215. nmcpy(plname, op+1, sizeof(plname)-1); 216. return; 217. } 218. 219. #ifdef GRAPHICS 220. /* graphics:string */ 221. if(!strncmp(opts,"graphics",4)) { 222. if(!from_env) { 223. #ifdef DGK 224. pline("'graphics' only settable from %s.", configfile); 225. #else 226. pline("The graphics string can be set only from HACKOPTIONS."); 227. #endif 228. return; 229. } 230. op = index(opts,':'); 231. if(!op) 232. goto bad; 233. else 234. opts = op + 1; 235. /* 236. * You could have problems here if you configure FOUNTAINS, SPIDERS or NEWCLASS 237. * in or out and forget to change the tail entries in your graphics string. 238. */ 239. #define SETPCHAR(f, n) showsyms.f = (strlen(opts) > n) ? opts[n] : defsyms.f 240. SETPCHAR(stone, 0); 241. SETPCHAR(vwall, 1); 242. SETPCHAR(hwall, 2); 243. SETPCHAR(tlcorn, 3); 244. SETPCHAR(trcorn, 4); 245. SETPCHAR(blcorn, 5); 246. SETPCHAR(brcorn, 6); 247. SETPCHAR(door, 7); 248. SETPCHAR(room, 8); 249. SETPCHAR(corr, 9); 250. SETPCHAR(upstair, 10); 251. SETPCHAR(dnstair, 11); 252. SETPCHAR(trap, 12); 253. #ifdef FOUNTAINS 254. SETPCHAR(pool, 13); 255. SETPCHAR(fountain, 14); 256. #endif 257. #ifdef NEWCLASS 258. SETPCHAR(throne, 15); 259. #endif 260. #ifdef SPIDERS 261. SETPCHAR(web, 16); 262. #endif 263. #undef SETPCHAR 264. return; 265. } 266. #endif /* GRAPHICS */ 267. 268. /* endgame:5t[op] 5a[round] o[wn] */ 269. if(!strncmp(opts,"endgame",3)) { 270. op = index(opts,':'); 271. if(!op) goto bad; 272. op++; 273. while(*op) { 274. num = 1; 275. if(digit(*op)) { 276. num = atoi(op); 277. while(digit(*op)) op++; 278. } else 279. if(*op == '!') { 280. negated = !negated; 281. op++; 282. } 283. switch(*op) { 284. case 't': 285. flags.end_top = num; 286. break; 287. case 'a': 288. flags.end_around = num; 289. break; 290. case 'o': 291. flags.end_own = !negated; 292. break; 293. default: 294. goto bad; 295. } 296. while(letter(*++op)) ; 297. if(*op == '/') op++; 298. } 299. return; 300. } 301. #ifdef DOGNAME 302. if(!strncmp(opts, "dogname", 3)) { 303. extern char dogname[]; 304. op = index(opts, ':'); 305. if (!op) goto bad; 306. nmcpy(dogname, ++op, 62); 307. return; 308. } 309. #endif /* DOGNAME */ 310. bad: 311. if(!from_env) { 312. if(!strncmp(opts, "help", 4)) { 313. option_help(); 314. return; 315. } 316. pline("Bad option: %s. Type `O help<cr>' for help.", opts); 317. return; 318. } 319. #ifdef DGK 320. printf("Bad syntax in OPTIONS in %s.", configfile); 321. #else 322. puts("Bad syntax in HACKOPTIONS."); 323. puts("Use for example:"); 324. puts( 325. "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\"" 326. ); 327. #endif 328. getret(); 329. } 330. 331. doset() 332. { 333. char buf[BUFSZ]; 334. #ifdef SORTING 335. extern char inv_order[]; 336. #endif 337. 338. pline("What options do you want to set? "); 339. getlin(buf); 340. if(!buf[0] || buf[0] == '\033') { 341. #ifdef DGK 342. (void) strcpy(buf,"OPTIONS="); 343. #else 344. (void) strcpy(buf,"HACKOPTIONS="); 345. (void) strcat(buf, flags.female ? "female," : "male,"); 346. if(flags.standout) (void) strcat(buf,"standout,"); 347. if(flags.nonull) (void) strcat(buf,"nonull,"); 348. if(flags.nonews) (void) strcat(buf,"nonews,"); 349. if(flags.notombstone) (void) strcat(buf,"notombstone,"); 350. if(flags.no_rest_on_space) (void) strcat(buf,"!rest_on_space,"); 351. #endif 352. #ifdef SORTING 353. if (flags.sortpack) (void) strcat(buf,"sortpack,"); 354. if (set_order){ 355. (void) strcat(buf, "packorder: "); 356. (void) strcat(buf, inv_order); 357. (void) strcat(buf, ","); 358. } 359. #endif 360. #ifdef SAFE_ATTACK 361. if (flags.confirm) (void) strcat(buf,"confirm,"); 362. #endif 363. #ifdef DGKMOD 364. if (flags.pickup) (void) strcat(buf,"pickup,"); 365. if (flags.silent) (void) strcat(buf,"silent,"); 366. #endif 367. #ifdef DGK 368. if (flags.rawio) (void) strcat(buf,"rawio,"); 369. if (flags.IBMBIOS) (void) strcat(buf,"IBMBIOS,"); 370. if (flags.DECRainbow) (void) strcat(buf,"DECRainbow,"); 371. #endif 372. if(flags.time) (void) strcat(buf,"time,"); 373. if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){ 374. (void) sprintf(eos(buf), "endgame: %u topscores/%u around me", 375. flags.end_top, flags.end_around); 376. if(flags.end_own) (void) strcat(buf, "/own scores"); 377. } else { 378. register char *eop = eos(buf); 379. if(*--eop == ',') *eop = 0; 380. } 381. pline(buf); 382. } else 383. parseoptions(buf, FALSE); 384. 385. return(0); 386. } 387. 388. #ifdef DGKMOD 389. dotogglepickup() { 390. flags.pickup = !flags.pickup; 391. pline("Pickup: %s.", flags.pickup ? "ON" : "OFF"); 392. return (0); 393. } 394. #endif 395. 396. nmcpy(dest, source, maxlen) 397. char *dest, *source; 398. int maxlen; 399. { 400. char *cs, *cd; 401. int count; 402. 403. cd = dest; 404. cs = source; 405. for(count = 1; count < maxlen; count++) { 406. if(*cs == ',') break; 407. *cd++ = *cs++; 408. } 409. *cd = 0; 410. } 411. 412. #ifdef SORTING 413. char *packorder = 414. # ifdef SPELLS 415. "\")[%?+/=!(*0"; 416. # else 417. "\")[%?/=!(*0"; 418. # endif 419. #endif 420. #define Page_line(x) if(page_line(x)) goto quit 421. 422. option_help() { 423. char buf[BUFSZ]; 424. 425. set_pager(0); 426. (void) sprintf(buf, " Net%s Options Help:", 427. #ifndef QUEST 428. "Hack"); 429. #else 430. "Quest); 431. #endif 432. if(page_line("") || page_line(buf) || page_line("")) goto quit; 433. 434. #ifdef DGK 435. (void) sprintf(buf, "To set options use OPTIONS=<options> in %s", configfile); 436. Page_line(buf); 437. #else 438. Page_line("To set options use `HACKOPTIONS=\"<options>\"' in your environment"); 439. #endif 440. 441. Page_line("or give the command \"O\" followed by the line <options> while playing."); 442. Page_line("Here <options> is a list of options separated by commas."); 443. Page_line(""); 444. 445. #ifdef DGK 446. Page_line("Boolean options are confirm, pickup, rawio, silent, sortpack, time, IBMBIOS,") 447. Page_line("and DECRainbow. These can be negated by prefixing them with '!' or \"no\"."); 448. #else 449. Page_line("Boolean options are rest_on_space, news, time, null tombstone, and (fe)male,"); 450. Page_line("These can be negated by prefixing them with '!' or \"no\"."); 451. #endif 452. Page_line(""); 453. 454. Page_line("The compound options are `name', (eg. name:Merlin-W,),"); 455. #ifdef DOGNAME 456. Page_line("`dogname', the name of your (first) dog (eg. dogname:Fang,),"); 457. #endif 458. 459. #ifdef SORTING 460. Page_line("`packorder'; the order that items should appear in your pack"); 461. (void)sprintf(buf, "(the default is: packorder:%s ), ", packorder); 462. Page_line(buf); 463. #endif 464. 465. #ifdef GRAPHICS 466. Page_line("`endgame', and `graphics'."); 467. #else 468. Page_line("and `endgame'."); 469. #endif 470. Page_line(""); 471. 472. Page_line("The `endgame' option is followed by a description of which parts of"); 473. Page_line("the scorelist you wish to see. You might for example say:"); 474. Page_line(""); 475. Page_line("\"endgame:own scores/5 top scores/4 around my score\"."); 476. 477. set_pager(1); 478. return; 479. quit: 480. set_pager(2); 481. return; 482. }