abstract
| - Below is the full text to options.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/options.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)options.c 1.3 87/07/14 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* options.c - version 1.0.3 */ 4. 5. #include "config.h" 6. #include "hack.h" 7. extern char *eos(); 8. #ifdef SORTING 9. static boolean set_order; 10. #endif 11. 12. initoptions() 13. { 14. register char *opts; 15. extern char *getenv(); 16. 17. flags.time = flags.nonews = flags.notombstone = flags.end_own = 18. flags.standout = flags.nonull = FALSE; 19. flags.no_rest_on_space = TRUE; 20. flags.invlet_constant = TRUE; 21. flags.end_top = 5; 22. flags.end_around = 4; 23. flags.female = FALSE; /* players are usually male */ 24. #ifdef SORTING 25. flags.sortpack = TRUE; 26. #endif 27. #ifdef SAFE_ATTACK 28. flags.confirm = TRUE; 29. #endif 30. #ifdef DGKMOD 31. flags.silent = flags.pickup = TRUE; 32. #endif 33. #ifdef DGK 34. flags.IBMBIOS = flags.DECRainbow = flags.rawio = FALSE; 35. read_config_file(); 36. #else 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. #ifndef DGK 178. if(!strncmp(opts,"fixinv",4)) { 179. if(from_env) 180. flags.invlet_constant = !negated; 181. else 182. pline("The fixinvlet option must be in HACKOPTIONS."); 183. return; 184. } 185. #endif 186. 187. if(!strncmp(opts,"male",4)) { 188. #ifdef KAA 189. if(!from_env && flags.female != negated) 190. pline("That is not anatomically possible."); 191. else 192. #endif 193. flags.female = negated; 194. return; 195. } 196. if(!strncmp(opts,"female",6)) { 197. #ifdef KAA 198. if(!from_env && flags.female == negated) 199. pline("That is not anatomically possible."); 200. else 201. #endif 202. flags.female = !negated; 203. return; 204. } 205. 206. /* name:string */ 207. if(!strncmp(opts,"name",4)) { 208. extern char plname[PL_NSIZ]; 209. if(!from_env) { 210. #ifdef DGK 211. pline("'name' only settable from %s.", configfile); 212. #else 213. pline("The playername can be set only from HACKOPTIONS."); 214. #endif 215. return; 216. } 217. op = index(opts,':'); 218. if(!op) goto bad; 219. (void) strncpy(plname, op+1, sizeof(plname)-1); 220. return; 221. } 222. 223. /* endgame:5t[op] 5a[round] o[wn] */ 224. if(!strncmp(opts,"endgame",3)) { 225. op = index(opts,':'); 226. if(!op) goto bad; 227. op++; 228. while(*op) { 229. num = 1; 230. if(digit(*op)) { 231. num = atoi(op); 232. while(digit(*op)) op++; 233. } else 234. if(*op == '!') { 235. negated = !negated; 236. op++; 237. } 238. switch(*op) { 239. case 't': 240. flags.end_top = num; 241. break; 242. case 'a': 243. flags.end_around = num; 244. break; 245. case 'o': 246. flags.end_own = !negated; 247. break; 248. default: 249. goto bad; 250. } 251. while(letter(*++op)) ; 252. if(*op == '/') op++; 253. } 254. return; 255. } 256. bad: 257. if(!from_env) { 258. if(!strncmp(opts, "help", 4)) { 259. pline("%s%s%s", 260. #ifdef DGK 261. 262. "To set options use OPTIONS= in ", configfile, 263. " or give the command \"O\" followed by the line while playing. ", 264. "Here is a list of options separated by commas." ); 265. pline("%s%s", 266. "Boolean options are confirm, pickup, rawio, silent, sortpack, time, IBMBIOS,", 267. " and DECRainbow. These can be negated by prefixing them with '!' or \"no\"." ); 268. pline("%s%s%s", 269. "The compound options are name, as in OPTIONS=name:Merlin-W,", 270. #ifdef SORTING 271. " packorder, which lists the order that items should appear in your pack", 272. #ifdef SPELLS 273. " (the default is: packorder:\")[%?+/=!(*0 ), and endgame." ); 274. #else 275. " (the default is: packorder:\")[%?/=!(*0 ), and endgame." ); 276. #endif /* SPELLS /**/ 277. #else 278. "and engame.", ""); 279. #endif /* SORTING /**/ 280. pline("%s%s%s", 281. "Endgame is followed by a description of which parts of the scorelist ", 282. "you wish to see. You might for example say: ", 283. "\"endgame:own scores/5 top scores/4 around my score\"." ); 284. 285. #else 286. 287. "To set options use `HACKOPTIONS=\"\"' in your environment, or ", 288. "give the command 'O' followed by the line `' while playing. ", 289. "Here is a list of s separated by commas." ); 290. pline("%s%s%s", 291. "Simple (boolean) options are rest_on_space, news, time, ", 292. "null, tombstone, (fe)male. ", 293. "These can be negated by prefixing them with '!' or \"no\"." ); 294. pline("%s%s%s", 295. "The compound options are name, as in OPTIONS=name:Merlin-W,", 296. #ifdef SORTING 297. " packorder, which lists the order that items should appear in your pack", 298. #ifdef SPELLS 299. " (the default is: packorder:\")[%?+/=!(*0 ), and endgame." ); 300. #else 301. " (the default is: packorder:\")[%?/=!(*0 ), and endgame." ); 302. #endif /* SPELLS /**/ 303. #else 304. "and engame.", ""); 305. #endif /* SORTING /**/ 306. pline("%s%s%s", 307. "Endgame is followed by a description of what parts of the scorelist", 308. "you want to see. You might for example say: ", 309. "`endgame:own scores/5 top scores/4 around my score'." ); 310. 311. #endif /* DGK /**/ 312. return; 313. } 314. pline("Bad option: %s.", opts); 315. pline("Type `o help' for help."); 316. return; 317. } 318. #ifdef DGK 319. printf("Bad syntax in OPTIONS in %s.", configfile); 320. #else 321. puts("Bad syntax in HACKOPTIONS."); 322. puts("Use for example:"); 323. puts( 324. "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\"" 325. ); 326. #endif 327. getret(); 328. } 329. 330. doset() 331. { 332. char buf[BUFSZ]; 333. #ifdef SORTING 334. extern char inv_order[]; 335. #endif 336. 337. pline("What options do you want to set? "); 338. getlin(buf); 339. if(!buf[0] || buf[0] == '\033') { 340. #ifdef DGK 341. (void) strcpy(buf,"OPTIONS="); 342. #else 343. (void) strcpy(buf,"HACKOPTIONS="); 344. (void) strcat(buf, flags.female ? "female," : "male,"); 345. if(flags.standout) (void) strcat(buf,"standout,"); 346. if(flags.nonull) (void) strcat(buf,"nonull,"); 347. if(flags.nonews) (void) strcat(buf,"nonews,"); 348. if(flags.notombstone) (void) strcat(buf,"notombstone,"); 349. if(flags.no_rest_on_space) (void) strcat(buf,"!rest_on_space,"); 350. #endif 351. #ifdef SORTING 352. if (flags.sortpack) (void) strcat(buf,"sortpack,"); 353. if (set_order){ 354. (void) strcat(buf, "packorder: "); 355. (void) strcat(buf, inv_order); 356. (void) strcat(buf, ","); 357. } 358. #endif 359. #ifdef SAFE_ATTACK 360. if (flags.confirm) (void) strcat(buf,"confirm,"); 361. #endif 362. #ifdef DGKMOD 363. if (flags.pickup) (void) strcat(buf,"pickup,"); 364. if (flags.silent) (void) strcat(buf,"silent,"); 365. #endif 366. #ifdef DGK 367. if (flags.rawio) (void) strcat(buf,"rawio,"); 368. if (flags.IBMBIOS) (void) strcat(buf,"IBMBIOS,"); 369. if (flags.DECRainbow) (void) strcat(buf,"DECRainbow,"); 370. #endif 371. if(flags.time) (void) strcat(buf,"time,"); 372. if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){ 373. (void) sprintf(eos(buf), "endgame: %u topscores/%u around me", 374. flags.end_top, flags.end_around); 375. if(flags.end_own) (void) strcat(buf, "/own scores"); 376. } else { 377. register char *eop = eos(buf); 378. if(*--eop == ',') *eop = 0; 379. } 380. pline(buf); 381. } else 382. parseoptions(buf, FALSE); 383. 384. return(0); 385. } 386. 387. #ifdef DGKMOD 388. dotogglepickup() { 389. flags.pickup = !flags.pickup; 390. pline("Pickup: %s.", flags.pickup ? "ON" : "OFF"); 391. return (0); 392. } 393. #endif
|