Source:NetHack 3.6.5/src/options.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to options.c from the source code of NetHack 3.6.5. To link to a particular line, write [[Source:NetHack 3.6.5/src/options.c#line12]], for example.

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. /* NetHack 3.6	options.c	$NHDT-Date: 1578996303 2020/01/14 10:05:03 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.396 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Michael Allison, 2008. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #ifdef OPTION_LISTS_ONLY /* (AMIGA) external program for opt lists */
7. #include "config.h"
8. #include "objclass.h"
9. #include "flag.h"
10. NEARDATA struct flag flags; /* provide linkage */
11. #ifdef SYSFLAGS
12. NEARDATA struct sysflag sysflags; /* provide linkage */
13. #endif
14. NEARDATA struct instance_flags iflags; /* provide linkage */
15. #define static
16. #else
17. #include "hack.h"
18. #include "tcap.h"
19. #include <ctype.h>
20. #endif
21. 
22. #define BACKWARD_COMPAT
23. 
24. #ifdef DEFAULT_WC_TILED_MAP
25. #define PREFER_TILED TRUE
26. #else
27. #define PREFER_TILED FALSE
28. #endif
29. 
30. #ifdef CURSES_GRAPHICS
31. extern int curses_read_attrs(const char *attrs);
32. extern char *curses_fmt_attrs(char *);
33. #endif
34. 
35. enum window_option_types {
36.     MESSAGE_OPTION = 1,
37.     STATUS_OPTION,
38.     MAP_OPTION,
39.     MENU_OPTION,
40.     TEXT_OPTION
41. };
42. 
43. #define PILE_LIMIT_DFLT 5
44. 
45. static char empty_optstr[] = { '\0' };
46. 
47. /*
48.  *  NOTE:  If you add (or delete) an option, please update the short
49.  *  options help (option_help()), the long options help (dat/opthelp),
50.  *  and the current options setting display function (doset()),
51.  *  and also the Guidebooks.
52.  *
53.  *  The order matters.  If an option is a an initial substring of another
54.  *  option (e.g. time and timed_delay) the shorter one must come first.
55.  */
56. 
57. static struct Bool_Opt {
58.     const char *name;
59.     boolean *addr, initvalue;
60.     int optflags;
61. } boolopt[] = {
62.     { "acoustics", &flags.acoustics, TRUE, SET_IN_GAME },
63. #if defined(SYSFLAGS) && defined(AMIGA)
64.     /* Amiga altmeta causes Alt+key to be converted into Meta+key by
65.        low level nethack code; on by default, can be toggled off if
66.        Alt+key is needed for some ASCII chars on non-ASCII keyboard */
67.     { "altmeta", &sysflags.altmeta, TRUE, DISP_IN_GAME },
68. #else
69. #ifdef ALTMETA
70.     /* non-Amiga altmeta causes nethack's top level command loop to treat
71.        two character sequence "ESC c" as M-c, for terminals or emulators
72.        which send "ESC c" when Alt+c is pressed; off by default, enabling
73.        this can potentially make trouble if user types ESC when nethack
74.        is honoring this conversion request (primarily after starting a
75.        count prefix prior to a command and then deciding to cancel it) */
76.     { "altmeta", &iflags.altmeta, FALSE, SET_IN_GAME },
77. #else
78.     { "altmeta", (boolean *) 0, TRUE, DISP_IN_GAME },
79. #endif
80. #endif
81.     { "ascii_map", &iflags.wc_ascii_map, !PREFER_TILED, SET_IN_GAME }, /*WC*/
82. #if defined(SYSFLAGS) && defined(MFLOPPY)
83.     { "asksavedisk", &sysflags.asksavedisk, FALSE, SET_IN_GAME },
84. #else
85.     { "asksavedisk", (boolean *) 0, FALSE, SET_IN_FILE },
86. #endif
87.     { "autodescribe", &iflags.autodescribe, TRUE, SET_IN_GAME },
88.     { "autodig", &flags.autodig, FALSE, SET_IN_GAME },
89.     { "autoopen", &flags.autoopen, TRUE, SET_IN_GAME },
90.     { "autopickup", &flags.pickup, TRUE, SET_IN_GAME },
91.     { "autoquiver", &flags.autoquiver, FALSE, SET_IN_GAME },
92. #if defined(MICRO) && !defined(AMIGA)
93.     { "BIOS", &iflags.BIOS, FALSE, SET_IN_FILE },
94. #else
95.     { "BIOS", (boolean *) 0, FALSE, SET_IN_FILE },
96. #endif
97.     { "blind", &u.uroleplay.blind, FALSE, DISP_IN_GAME },
98.     { "bones", &flags.bones, TRUE, SET_IN_FILE },
99. #ifdef INSURANCE
100.     { "checkpoint", &flags.ins_chkpt, TRUE, SET_IN_GAME },
101. #else
102.     { "checkpoint", (boolean *) 0, FALSE, SET_IN_FILE },
103. #endif
104. #ifdef MFLOPPY
105.     { "checkspace", &iflags.checkspace, TRUE, SET_IN_GAME },
106. #else
107.     { "checkspace", (boolean *) 0, FALSE, SET_IN_FILE },
108. #endif
109.     { "clicklook", &iflags.clicklook, FALSE, SET_IN_GAME },
110.     { "cmdassist", &iflags.cmdassist, TRUE, SET_IN_GAME },
111. #if defined(MICRO) || defined(WIN32) || defined(CURSES_GRAPHICS)
112.     { "color", &iflags.wc_color, TRUE, SET_IN_GAME }, /* on/off: use WC or not */
113. #else /* systems that support multiple terminals, many monochrome */
114.     { "color", &iflags.wc_color, FALSE, SET_IN_GAME },
115. #endif
116.     { "confirm", &flags.confirm, TRUE, SET_IN_GAME },
117.     { "dark_room", &flags.dark_room, TRUE, SET_IN_GAME },
118.     { "eight_bit_tty", &iflags.wc_eight_bit_input, FALSE, SET_IN_GAME }, /*WC*/
119. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS) || defined(X11_GRAPHICS)
120.     { "extmenu", &iflags.extmenu, FALSE, SET_IN_GAME },
121. #else
122.     { "extmenu", (boolean *) 0, FALSE, SET_IN_FILE },
123. #endif
124. #ifdef OPT_DISPMAP
125.     { "fast_map", &flags.fast_map, TRUE, SET_IN_GAME },
126. #else
127.     { "fast_map", (boolean *) 0, TRUE, SET_IN_FILE },
128. #endif
129.     { "female", &flags.female, FALSE, DISP_IN_GAME },
130.     { "fixinv", &flags.invlet_constant, TRUE, SET_IN_GAME },
131. #if defined(SYSFLAGS) && defined(AMIFLUSH)
132.     { "flush", &sysflags.amiflush, FALSE, SET_IN_GAME },
133. #else
134.     { "flush", (boolean *) 0, FALSE, SET_IN_FILE },
135. #endif
136.     { "force_invmenu", &iflags.force_invmenu, FALSE, SET_IN_GAME },
137.     { "fullscreen", &iflags.wc2_fullscreen, FALSE, SET_IN_FILE }, /*WC2*/
138.     { "goldX", &iflags.goldX, FALSE, SET_IN_GAME },
139.     { "guicolor", &iflags.wc2_guicolor, TRUE, SET_IN_GAME}, /*WC2*/
140.     { "help", &flags.help, TRUE, SET_IN_GAME },
141.     { "herecmd_menu", &iflags.herecmd_menu, FALSE, SET_IN_GAME },
142.     { "hilite_pet", &iflags.wc_hilite_pet, FALSE, SET_IN_GAME }, /*WC*/
143.     { "hilite_pile", &iflags.hilite_pile, FALSE, SET_IN_GAME },
144.     { "hitpointbar", &iflags.wc2_hitpointbar, FALSE, SET_IN_GAME }, /*WC2*/
145. #ifndef MAC
146.     { "ignintr", &flags.ignintr, FALSE, SET_IN_GAME },
147. #else
148.     { "ignintr", (boolean *) 0, FALSE, SET_IN_FILE },
149. #endif
150.     { "implicit_uncursed", &iflags.implicit_uncursed, TRUE, SET_IN_GAME },
151.     { "large_font", &iflags.obsolete, FALSE, SET_IN_FILE }, /* OBSOLETE */
152.     { "legacy", &flags.legacy, TRUE, DISP_IN_GAME },
153.     { "lit_corridor", &flags.lit_corridor, FALSE, SET_IN_GAME },
154.     { "lootabc", &flags.lootabc, FALSE, SET_IN_GAME },
155. #ifdef MAIL
156.     { "mail", &flags.biff, TRUE, SET_IN_GAME },
157. #else
158.     { "mail", (boolean *) 0, TRUE, SET_IN_FILE },
159. #endif
160.     { "mention_walls", &iflags.mention_walls, FALSE, SET_IN_GAME },
161.     { "menucolors", &iflags.use_menu_color, FALSE, SET_IN_GAME },
162.     /* for menu debugging only*/
163.     { "menu_tab_sep", &iflags.menu_tab_sep, FALSE, SET_IN_WIZGAME },
164.     { "menu_objsyms", &iflags.menu_head_objsym, FALSE, SET_IN_GAME },
165. #ifdef TTY_GRAPHICS
166.     { "menu_overlay", &iflags.menu_overlay, TRUE, SET_IN_GAME },
167. #else
168.     { "menu_overlay", (boolean *) 0, FALSE, SET_IN_FILE },
169. #endif
170.     { "monpolycontrol", &iflags.mon_polycontrol, FALSE, SET_IN_WIZGAME },
171. #ifdef NEWS
172.     { "news", &iflags.news, TRUE, DISP_IN_GAME },
173. #else
174.     { "news", (boolean *) 0, FALSE, SET_IN_FILE },
175. #endif
176.     { "nudist", &u.uroleplay.nudist, FALSE, DISP_IN_GAME },
177.     { "null", &flags.null, TRUE, SET_IN_GAME },
178. #if defined(SYSFLAGS) && defined(MAC)
179.     { "page_wait", &sysflags.page_wait, TRUE, SET_IN_GAME },
180. #else
181.     { "page_wait", (boolean *) 0, FALSE, SET_IN_FILE },
182. #endif
183.     /* moved perm_invent from flags to iflags and out of save file in 3.6.2 */
184.     { "perm_invent", &iflags.perm_invent, FALSE, SET_IN_GAME },
185.     { "pickup_thrown", &flags.pickup_thrown, TRUE, SET_IN_GAME },
186.     { "popup_dialog", &iflags.wc_popup_dialog, FALSE, SET_IN_GAME },   /*WC*/
187.     { "preload_tiles", &iflags.wc_preload_tiles, TRUE, DISP_IN_GAME }, /*WC*/
188.     { "pushweapon", &flags.pushweapon, FALSE, SET_IN_GAME },
189. #if defined(MICRO) && !defined(AMIGA)
190.     { "rawio", &iflags.rawio, FALSE, DISP_IN_GAME },
191. #else
192.     { "rawio", (boolean *) 0, FALSE, SET_IN_FILE },
193. #endif
194.     { "rest_on_space", &flags.rest_on_space, FALSE, SET_IN_GAME },
195. #ifdef RLECOMP
196.     { "rlecomp", &iflags.rlecomp,
197. #if defined(COMPRESS) || defined(ZLIB_COMP)
198.       FALSE,
199. #else
200.       TRUE,
201. #endif
202.       DISP_IN_GAME },
203. #endif
204.     { "safe_pet", &flags.safe_dog, TRUE, SET_IN_GAME },
205.     { "sanity_check", &iflags.sanity_check, FALSE, SET_IN_WIZGAME },
206.     { "selectsaved", &iflags.wc2_selectsaved, TRUE, DISP_IN_GAME }, /*WC*/
207.     { "showexp", &flags.showexp, FALSE, SET_IN_GAME },
208.     { "showrace", &flags.showrace, FALSE, SET_IN_GAME },
209. #ifdef SCORE_ON_BOTL
210.     { "showscore", &flags.showscore, FALSE, SET_IN_GAME },
211. #else
212.     { "showscore", (boolean *) 0, FALSE, SET_IN_FILE },
213. #endif
214.     { "silent", &flags.silent, TRUE, SET_IN_GAME },
215.     { "softkeyboard", &iflags.wc2_softkeyboard, FALSE, SET_IN_FILE }, /*WC2*/
216.     { "sortpack", &flags.sortpack, TRUE, SET_IN_GAME },
217.     { "sparkle", &flags.sparkle, TRUE, SET_IN_GAME },
218.     { "splash_screen", &iflags.wc_splash_screen, TRUE, DISP_IN_GAME }, /*WC*/
219.     { "standout", &flags.standout, FALSE, SET_IN_GAME },
220.     { "status_updates", &iflags.status_updates, TRUE, DISP_IN_GAME },
221.     { "tiled_map", &iflags.wc_tiled_map, PREFER_TILED, DISP_IN_GAME }, /*WC*/
222.     { "time", &flags.time, FALSE, SET_IN_GAME },
223. #ifdef TIMED_DELAY
224.     { "timed_delay", &flags.nap, TRUE, SET_IN_GAME },
225. #else
226.     { "timed_delay", (boolean *) 0, FALSE, SET_IN_GAME },
227. #endif
228.     { "tombstone", &flags.tombstone, TRUE, SET_IN_GAME },
229.     { "toptenwin", &iflags.toptenwin, FALSE, SET_IN_GAME },
230.     { "travel", &flags.travelcmd, TRUE, SET_IN_GAME },
231. #ifdef DEBUG
232.     { "travel_debug", &iflags.trav_debug, FALSE, SET_IN_WIZGAME }, /*hack.c*/
233. #endif
234.     { "use_darkgray", &iflags.wc2_darkgray, TRUE, SET_IN_FILE }, /*WC2*/
235. #ifdef WIN32
236.     { "use_inverse", &iflags.wc_inverse, TRUE, SET_IN_GAME }, /*WC*/
237. #else
238.     { "use_inverse", &iflags.wc_inverse, FALSE, SET_IN_GAME }, /*WC*/
239. #endif
240.     { "verbose", &flags.verbose, TRUE, SET_IN_GAME },
241. #ifdef TTY_TILES_ESCCODES
242.     { "vt_tiledata", &iflags.vt_tiledata, FALSE, SET_IN_FILE },
243. #else
244.     { "vt_tiledata", (boolean *) 0, FALSE, SET_IN_FILE },
245. #endif
246.     { "whatis_menu", &iflags.getloc_usemenu, FALSE, SET_IN_GAME },
247.     { "whatis_moveskip", &iflags.getloc_moveskip, FALSE, SET_IN_GAME },
248.     { "wizweight", &iflags.wizweight, FALSE, SET_IN_WIZGAME },
249.     { "wraptext", &iflags.wc2_wraptext, FALSE, SET_IN_GAME }, /*WC2*/
250. #ifdef ZEROCOMP
251.     { "zerocomp", &iflags.zerocomp,
252. #if defined(COMPRESS) || defined(ZLIB_COMP)
253.       FALSE,
254. #else
255.       TRUE,
256. #endif
257.       DISP_IN_GAME },
258. #endif
259.     { (char *) 0, (boolean *) 0, FALSE, 0 }
260. };
261. 
262. /* compound options, for option_help() and external programs like Amiga
263.  * frontend */
264. static struct Comp_Opt {
265.     const char *name, *descr;
266.     int size; /* for frontends and such allocating space --
267.                * usually allowed size of data in game, but
268.                * occasionally maximum reasonable size for
269.                * typing when game maintains information in
270.                * a different format */
271.     int optflags;
272. } compopt[] = {
273.     { "align", "your starting alignment (lawful, neutral, or chaotic)", 8,
274.       DISP_IN_GAME },
275.     { "align_message", "message window alignment", 20, DISP_IN_GAME }, /*WC*/
276.     { "align_status", "status window alignment", 20, DISP_IN_GAME },   /*WC*/
277.     { "altkeyhandler", "alternate key handler", 20, SET_IN_GAME },
278. #ifdef BACKWARD_COMPAT
279.     { "boulder", "deprecated (use S_boulder in sym file instead)", 1,
280.       SET_IN_GAME },
281. #endif
282.     { "catname", "the name of your (first) cat (e.g., catname:Tabby)",
283.       PL_PSIZ, DISP_IN_GAME },
284.     { "disclose", "the kinds of information to disclose at end of game",
285.       sizeof flags.end_disclose * 2, SET_IN_GAME },
286.     { "dogname", "the name of your (first) dog (e.g., dogname:Fang)", PL_PSIZ,
287.       DISP_IN_GAME },
288.     { "dungeon", "the symbols to use in drawing the dungeon map",
289.       MAXDCHARS + 1, SET_IN_FILE },
290.     { "effects", "the symbols to use in drawing special effects",
291.       MAXECHARS + 1, SET_IN_FILE },
292.     { "font_map", "the font to use in the map window", 40,
293.       DISP_IN_GAME },                                              /*WC*/
294.     { "font_menu", "the font to use in menus", 40, DISP_IN_GAME }, /*WC*/
295.     { "font_message", "the font to use in the message window", 40,
296.       DISP_IN_GAME },                                                  /*WC*/
297.     { "font_size_map", "the size of the map font", 20, DISP_IN_GAME }, /*WC*/
298.     { "font_size_menu", "the size of the menu font", 20,
299.       DISP_IN_GAME }, /*WC*/
300.     { "font_size_message", "the size of the message font", 20,
301.       DISP_IN_GAME }, /*WC*/
302.     { "font_size_status", "the size of the status font", 20,
303.       DISP_IN_GAME }, /*WC*/
304.     { "font_size_text", "the size of the text font", 20,
305.       DISP_IN_GAME }, /*WC*/
306.     { "font_status", "the font to use in status window", 40,
307.       DISP_IN_GAME }, /*WC*/
308.     { "font_text", "the font to use in text windows", 40,
309.       DISP_IN_GAME }, /*WC*/
310.     { "fruit", "the name of a fruit you enjoy eating", PL_FSIZ, SET_IN_GAME },
311.     { "gender", "your starting gender (male or female)", 8, DISP_IN_GAME },
312.     { "horsename", "the name of your (first) horse (e.g., horsename:Silver)",
313.       PL_PSIZ, DISP_IN_GAME },
314.     { "map_mode", "map display mode under Windows", 20, DISP_IN_GAME }, /*WC*/
315.     { "menustyle", "user interface for object selection", MENUTYPELEN,
316.       SET_IN_GAME },
317.     { "menu_deselect_all", "deselect all items in a menu", 4, SET_IN_FILE },
318.     { "menu_deselect_page", "deselect all items on this page of a menu", 4,
319.       SET_IN_FILE },
320.     { "menu_first_page", "jump to the first page in a menu", 4, SET_IN_FILE },
321.     { "menu_headings", "text attribute for menu headings", 9, SET_IN_GAME },
322.     { "menu_invert_all", "invert all items in a menu", 4, SET_IN_FILE },
323.     { "menu_invert_page", "invert all items on this page of a menu", 4,
324.       SET_IN_FILE },
325.     { "menu_last_page", "jump to the last page in a menu", 4, SET_IN_FILE },
326.     { "menu_next_page", "goto the next menu page", 4, SET_IN_FILE },
327.     { "menu_previous_page", "goto the previous menu page", 4, SET_IN_FILE },
328.     { "menu_search", "search for a menu item", 4, SET_IN_FILE },
329.     { "menu_select_all", "select all items in a menu", 4, SET_IN_FILE },
330.     { "menu_select_page", "select all items on this page of a menu", 4,
331.       SET_IN_FILE },
332.     { "monsters", "the symbols to use for monsters", MAXMCLASSES,
333.       SET_IN_FILE },
334.     { "msghistory", "number of top line messages to save", 5, DISP_IN_GAME },
335. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS)
336.     { "msg_window", "the type of message window required", 1, SET_IN_GAME },
337. #else
338.     { "msg_window", "the type of message window required", 1, SET_IN_FILE },
339. #endif
340.     { "name", "your character's name (e.g., name:Merlin-W)", PL_NSIZ,
341.       DISP_IN_GAME },
342.     { "mouse_support", "game receives click info from mouse", 0, SET_IN_GAME },
343.     { "number_pad", "use the number pad for movement", 1, SET_IN_GAME },
344.     { "objects", "the symbols to use for objects", MAXOCLASSES, SET_IN_FILE },
345.     { "packorder", "the inventory order of the items in your pack",
346.       MAXOCLASSES, SET_IN_GAME },
347. #ifdef CHANGE_COLOR
348.     { "palette",
349. #ifndef WIN32
350.       "palette (00c/880/-fff is blue/yellow/reverse white)", 15, SET_IN_GAME
351. #else
352.       "palette (adjust an RGB color in palette (color-R-G-B)", 15, SET_IN_FILE
353. #endif
354.     },
355. #if defined(MAC)
356.     { "hicolor", "same as palette, only order is reversed", 15, SET_IN_FILE },
357. #endif
358. #endif
359.     { "paranoid_confirmation", "extra prompting in certain situations", 28,
360.       SET_IN_GAME },
361.     { "petattr",  "attributes for highlighting pets", 88, SET_IN_GAME },
362.     { "pettype", "your preferred initial pet type", 4, DISP_IN_GAME },
363.     { "pickup_burden", "maximum burden picked up before prompt", 20,
364.       SET_IN_GAME },
365.     { "pickup_types", "types of objects to pick up automatically",
366.       MAXOCLASSES, SET_IN_GAME },
367.     { "pile_limit", "threshold for \"there are many objects here\"", 24,
368.       SET_IN_GAME },
369.     { "playmode", "normal play, non-scoring explore mode, or debug mode", 8,
370.       DISP_IN_GAME },
371.     { "player_selection", "choose character via dialog or prompts", 12,
372.       DISP_IN_GAME },
373.     { "race", "your starting race (e.g., Human, Elf)", PL_CSIZ,
374.       DISP_IN_GAME },
375.     { "role", "your starting role (e.g., Barbarian, Valkyrie)", PL_CSIZ,
376.       DISP_IN_GAME },
377.     { "runmode", "display frequency when `running' or `travelling'",
378.       sizeof "teleport", SET_IN_GAME },
379.     { "scores", "the parts of the score list you wish to see", 32,
380.       SET_IN_GAME },
381.     { "scroll_amount", "amount to scroll map when scroll_margin is reached",
382.       20, DISP_IN_GAME }, /*WC*/
383.     { "scroll_margin", "scroll map when this far from the edge", 20,
384.       DISP_IN_GAME }, /*WC*/
385.     { "sortloot", "sort object selection lists by description", 4,
386.       SET_IN_GAME },
387. #ifdef MSDOS
388.     { "soundcard", "type of sound card to use", 20, SET_IN_FILE },
389. #endif
390.     { "statushilites",
391. #ifdef STATUS_HILITES
392.       "0=no status highlighting, N=show highlights for N turns",
393.       20, SET_IN_GAME
394. #else
395.     "highlight control", 20, SET_IN_FILE
396. #endif
397.     },
398.     { "statuslines",
399. #ifdef CURSES_GRAPHICS
400.       "2 or 3 lines for horizontal (bottom or top) status display",
401.       20, SET_IN_GAME
402. #else
403.       "2 or 3 lines for status display",
404.       20, SET_IN_FILE
405. #endif
406.     }, /*WC2*/
407.     { "symset", "load a set of display symbols from the symbols file", 70,
408.       SET_IN_GAME },
409.     { "roguesymset",
410.       "load a set of rogue display symbols from the symbols file", 70,
411.       SET_IN_GAME },
412. #ifdef WIN32
413.     { "subkeyvalue", "override keystroke value", 7, SET_IN_FILE },
414. #endif
415.     { "suppress_alert", "suppress alerts about version-specific features", 8,
416.       SET_IN_GAME },
417.     /* term_cols,term_rows -> WC2_TERM_SIZE (6: room to format 1..32767) */
418.     { "term_cols", "number of columns", 6, SET_IN_FILE }, /*WC2*/
419.     { "term_rows", "number of rows", 6, SET_IN_FILE }, /*WC2*/
420.     { "tile_width", "width of tiles", 20, DISP_IN_GAME },   /*WC*/
421.     { "tile_height", "height of tiles", 20, DISP_IN_GAME }, /*WC*/
422.     { "tile_file", "name of tile file", 70, DISP_IN_GAME }, /*WC*/
423.     { "traps", "the symbols to use in drawing traps", MAXTCHARS + 1,
424.       SET_IN_FILE },
425.     { "vary_msgcount", "show more old messages at a time", 20,
426.       DISP_IN_GAME }, /*WC*/
427. #ifdef MSDOS
428.     { "video", "method of video updating", 20, SET_IN_FILE },
429. #endif
430. #ifdef VIDEOSHADES
431.     { "videocolors", "color mappings for internal screen routines", 40,
432.       DISP_IN_GAME },
433.     { "videoshades", "gray shades to map to black/gray/white", 32,
434.       DISP_IN_GAME },
435. #endif
436.     { "whatis_coord", "show coordinates when auto-describing cursor position",
437.       1, SET_IN_GAME },
438.     { "whatis_filter",
439.       "filter coordinate locations when targeting next or previous",
440.       1, SET_IN_GAME },
441.     { "windowborders", "0 (off), 1 (on), 2 (auto)", 9, SET_IN_GAME }, /*WC2*/
442.     { "windowcolors", "the foreground/background colors of windows", /*WC*/
443.       80, DISP_IN_GAME },
444.     { "windowtype", "windowing system to use", WINTYPELEN, DISP_IN_GAME },
445. #ifdef WINCHAIN
446.     { "windowchain", "window processor to use", WINTYPELEN, SET_IN_SYS },
447. #endif
448. #ifdef BACKWARD_COMPAT
449.     { "DECgraphics", "load DECGraphics display symbols", 70, SET_IN_FILE },
450.     { "IBMgraphics", "load IBMGraphics display symbols", 70, SET_IN_FILE },
451. #ifdef CURSES_GRAPHICS
452.     { "cursesgraphics", "load curses display symbols", 70, SET_IN_FILE },
453. #endif
454. #ifdef MAC_GRAPHICS_ENV
455.     { "Macgraphics", "load MACGraphics display symbols", 70, SET_IN_FILE },
456. #endif
457. #endif
458.     { (char *) 0, (char *) 0, 0, 0 }
459. };
460. 
461. #ifdef OPTION_LISTS_ONLY
462. #undef static
463. 
464. #else /* use rest of file */
465. 
466. extern char configfile[]; /* for messages */
467. 
468. extern struct symparse loadsyms[];
469. static boolean need_redraw; /* for doset() */
470. 
471. #if defined(TOS) && defined(TEXTCOLOR)
472. extern boolean colors_changed;  /* in tos.c */
473. #endif
474. 
475. #ifdef VIDEOSHADES
476. extern char *shade[3];          /* in sys/msdos/video.c */
477. extern char ttycolors[CLR_MAX]; /* in sys/msdos/video.c */
478. #endif
479. 
480. static char def_inv_order[MAXOCLASSES] = {
481.     COIN_CLASS, AMULET_CLASS, WEAPON_CLASS, ARMOR_CLASS, FOOD_CLASS,
482.     SCROLL_CLASS, SPBOOK_CLASS, POTION_CLASS, RING_CLASS, WAND_CLASS,
483.     TOOL_CLASS, GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, 0,
484. };
485. 
486. /*
487.  * Default menu manipulation command accelerators.  These may _not_ be:
488.  *
489.  *      + a number - reserved for counts
490.  *      + an upper or lower case US ASCII letter - used for accelerators
491.  *      + ESC - reserved for escaping the menu
492.  *      + NULL, CR or LF - reserved for commiting the selection(s).  NULL
493.  *        is kind of odd, but the tty's xwaitforspace() will return it if
494.  *        someone hits a <ret>.
495.  *      + a default object class symbol - used for object class accelerators
496.  *
497.  * Standard letters (for now) are:
498.  *
499.  *              <  back 1 page
500.  *              >  forward 1 page
501.  *              ^  first page
502.  *              |  last page
503.  *              :  search
504.  *
505.  *              page            all
506.  *               ,    select     .
507.  *               \    deselect   -
508.  *               ~    invert     @
509.  *
510.  * The command name list is duplicated in the compopt array.
511.  */
512. typedef struct {
513.     const char *name;
514.     char cmd;
515.     const char *desc;
516. } menu_cmd_t;
517. 
518. static const menu_cmd_t default_menu_cmd_info[] = {
519.  { "menu_first_page", MENU_FIRST_PAGE, "Go to first page" },
520.  { "menu_last_page", MENU_LAST_PAGE, "Go to last page" },
521.  { "menu_next_page", MENU_NEXT_PAGE, "Go to next page" },
522.  { "menu_previous_page", MENU_PREVIOUS_PAGE, "Go to previous page" },
523.  { "menu_select_all", MENU_SELECT_ALL, "Select all items" },
524.  { "menu_deselect_all", MENU_UNSELECT_ALL, "Unselect all items" },
525.  { "menu_invert_all", MENU_INVERT_ALL, "Invert selection" },
526.  { "menu_select_page", MENU_SELECT_PAGE, "Select items in current page" },
527.  { "menu_deselect_page", MENU_UNSELECT_PAGE,
528.    "Unselect items in current page" },
529.  { "menu_invert_page", MENU_INVERT_PAGE, "Invert current page selection" },
530.  { "menu_search", MENU_SEARCH, "Search and toggle matching items" },
531. };
532. 
533. /*
534.  * Allow the user to map incoming characters to various menu commands.
535.  * The accelerator list must be a valid C string.
536.  */
537. #define MAX_MENU_MAPPED_CMDS 32 /* some number */
538. char mapped_menu_cmds[MAX_MENU_MAPPED_CMDS + 1]; /* exported */
539. static char mapped_menu_op[MAX_MENU_MAPPED_CMDS + 1];
540. static short n_menu_mapped = 0;
541. 
542. static boolean initial, from_file;
543. 
544. STATIC_DCL void FDECL(nmcpy, (char *, const char *, int));
545. STATIC_DCL void FDECL(escapes, (const char *, char *));
546. STATIC_DCL void FDECL(rejectoption, (const char *));
547. STATIC_DCL char *FDECL(string_for_opt, (char *, BOOLEAN_P));
548. STATIC_DCL char *FDECL(string_for_env_opt, (const char *, char *, BOOLEAN_P));
549. STATIC_DCL void FDECL(bad_negation, (const char *, BOOLEAN_P));
550. STATIC_DCL int FDECL(change_inv_order, (char *));
551. STATIC_DCL boolean FDECL(warning_opts, (char *, const char *));
552. STATIC_DCL int FDECL(feature_alert_opts, (char *, const char *));
553. STATIC_DCL boolean FDECL(duplicate_opt_detection, (const char *, int));
554. STATIC_DCL void FDECL(complain_about_duplicate, (const char *, int));
555. 
556. STATIC_DCL const char *FDECL(attr2attrname, (int));
557. STATIC_DCL const char * FDECL(msgtype2name, (int));
558. STATIC_DCL int NDECL(query_msgtype);
559. STATIC_DCL boolean FDECL(msgtype_add, (int, char *));
560. STATIC_DCL void FDECL(free_one_msgtype, (int));
561. STATIC_DCL int NDECL(msgtype_count);
562. STATIC_DCL boolean FDECL(test_regex_pattern, (const char *, const char *));
563. STATIC_DCL boolean FDECL(add_menu_coloring_parsed, (char *, int, int));
564. STATIC_DCL void FDECL(free_one_menu_coloring, (int));
565. STATIC_DCL int NDECL(count_menucolors);
566. STATIC_DCL boolean FDECL(parse_role_opts, (BOOLEAN_P, const char *,
567.                                            char *, char **));
568. 
569. STATIC_DCL void FDECL(doset_add_menu, (winid, const char *, int));
570. STATIC_DCL void FDECL(opts_add_others, (winid, const char *, int,
571.                                         char *, int));
572. STATIC_DCL int FDECL(handle_add_list_remove, (const char *, int));
573. STATIC_DCL boolean FDECL(special_handling, (const char *,
574.                                             BOOLEAN_P, BOOLEAN_P));
575. STATIC_DCL const char *FDECL(get_compopt_value, (const char *, char *));
576. STATIC_DCL void FDECL(remove_autopickup_exception,
577.                       (struct autopickup_exception *));
578. 
579. STATIC_DCL boolean FDECL(is_wc_option, (const char *));
580. STATIC_DCL boolean FDECL(wc_supported, (const char *));
581. STATIC_DCL boolean FDECL(is_wc2_option, (const char *));
582. STATIC_DCL boolean FDECL(wc2_supported, (const char *));
583. STATIC_DCL void FDECL(wc_set_font_name, (int, char *));
584. STATIC_DCL int FDECL(wc_set_window_colors, (char *));
585. 
586. void
587. reglyph_darkroom()
588. {
589.     xchar x, y;
590. 
591.     for (x = 0; x < COLNO; x++)
592.         for (y = 0; y < ROWNO; y++) {
593.             struct rm *lev = &levl[x][y];
594. 
595.             if (!flags.dark_room || !iflags.use_color
596.                 || Is_rogue_level(&u.uz)) {
597.                 if (lev->glyph == cmap_to_glyph(S_darkroom))
598.                     lev->glyph = lev->waslit ? cmap_to_glyph(S_room)
599.                                              : cmap_to_glyph(S_stone);
600.             } else {
601.                 if (lev->glyph == cmap_to_glyph(S_room) && lev->seenv
602.                     && lev->waslit && !cansee(x, y))
603.                     lev->glyph = cmap_to_glyph(S_darkroom);
604.                 else if (lev->glyph == cmap_to_glyph(S_stone)
605.                          && lev->typ == ROOM && lev->seenv && !cansee(x, y))
606.                     lev->glyph = cmap_to_glyph(S_darkroom);
607.             }
608.         }
609.     if (flags.dark_room && iflags.use_color)
610.         showsyms[S_darkroom] = showsyms[S_room];
611.     else
612.         showsyms[S_darkroom] = showsyms[S_stone];
613. }
614. 
615. /* check whether a user-supplied option string is a proper leading
616.    substring of a particular option name; option string might have
617.    a colon or equals sign and arbitrary value appended to it */
618. boolean
619. match_optname(user_string, opt_name, min_length, val_allowed)
620. const char *user_string, *opt_name;
621. int min_length;
622. boolean val_allowed;
623. {
624.     int len = (int) strlen(user_string);
625. 
626.     if (val_allowed) {
627.         const char *p = index(user_string, ':'),
628.                    *q = index(user_string, '=');
629. 
630.         if (!p || (q && q < p))
631.             p = q;
632.         if (p) {
633.             /* 'user_string' hasn't necessarily been through mungspaces()
634.                so might have tabs or consecutive spaces */
635.             while (p > user_string && isspace((uchar) *(p - 1)))
636.                 p--;
637.             len = (int) (p - user_string);
638.         }
639.     }
640. 
641.     return (boolean) (len >= min_length
642.                       && !strncmpi(opt_name, user_string, len));
643. }
644. 
645. /* most environment variables will eventually be printed in an error
646.  * message if they don't work, and most error message paths go through
647.  * BUFSZ buffers, which could be overflowed by a maliciously long
648.  * environment variable.  If a variable can legitimately be long, or
649.  * if it's put in a smaller buffer, the responsible code will have to
650.  * bounds-check itself.
651.  */
652. char *
653. nh_getenv(ev)
654. const char *ev;
655. {
656.     char *getev = getenv(ev);
657. 
658.     if (getev && strlen(getev) <= (BUFSZ / 2))
659.         return getev;
660.     else
661.         return (char *) 0;
662. }
663. 
664. /* process options, possibly including SYSCF */
665. void
666. initoptions()
667. {
668.     initoptions_init();
669. #ifdef SYSCF
670. /* someday there may be other SYSCF alternatives besides text file */
671. #ifdef SYSCF_FILE
672.     /* If SYSCF_FILE is specified, it _must_ exist... */
673.     assure_syscf_file();
674.     config_error_init(TRUE, SYSCF_FILE, FALSE);
675. 
676.     /* ... and _must_ parse correctly. */
677.     if (!read_config_file(SYSCF_FILE, SET_IN_SYS)) {
678.         if (config_error_done() && !iflags.initoptions_noterminate)
679.             nh_terminate(EXIT_FAILURE);
680.     }
681.     config_error_done();
682.     /*
683.      * TODO [maybe]: parse the sysopt entries which are space-separated
684.      * lists of usernames into arrays with one name per element.
685.      */
686. #endif
687. #endif /* SYSCF */
688.     initoptions_finish();
689. }
690. 
691. void
692. initoptions_init()
693. {
694. #if (defined(UNIX) || defined(VMS)) && defined(TTY_GRAPHICS)
695.     char *opts;
696. #endif
697.     int i;
698. 
699.     /* set up the command parsing */
700.     reset_commands(TRUE); /* init */
701. 
702.     /* initialize the random number generator(s) */
703.     init_random(rn2);
704.     init_random(rn2_on_display_rng);
705. 
706.     /* for detection of configfile options specified multiple times */
707.     iflags.opt_booldup = iflags.opt_compdup = (int *) 0;
708. 
709.     for (i = 0; boolopt[i].name; i++) {
710.         if (boolopt[i].addr)
711.             *(boolopt[i].addr) = boolopt[i].initvalue;
712.     }
713. #if defined(COMPRESS) || defined(ZLIB_COMP)
714.     set_savepref("externalcomp");
715.     set_restpref("externalcomp");
716. #ifdef RLECOMP
717.     set_savepref("!rlecomp");
718.     set_restpref("!rlecomp");
719. #endif
720. #else
721. #ifdef ZEROCOMP
722.     set_savepref("zerocomp");
723.     set_restpref("zerocomp");
724. #endif
725. #ifdef RLECOMP
726.     set_savepref("rlecomp");
727.     set_restpref("rlecomp");
728. #endif
729. #endif
730. #ifdef SYSFLAGS
731.     Strcpy(sysflags.sysflagsid, "sysflags");
732.     sysflags.sysflagsid[9] = (char) sizeof (struct sysflag);
733. #endif
734.     flags.end_own = FALSE;
735.     flags.end_top = 3;
736.     flags.end_around = 2;
737.     flags.paranoia_bits = PARANOID_PRAY; /* old prayconfirm=TRUE */
738.     flags.pile_limit = PILE_LIMIT_DFLT;  /* 5 */
739.     flags.runmode = RUN_LEAP;
740.     iflags.msg_history = 20;
741.     /* msg_window has conflicting defaults for multi-interface binary */
742. #ifdef TTY_GRAPHICS
743.     iflags.prevmsg_window = 's';
744. #else
745. #ifdef CURSES_GRAPHICS
746.     iflags.prevmsg_window = 'r';
747. #endif
748. #endif
749.     iflags.menu_headings = ATR_INVERSE;
750.     iflags.getpos_coords = GPCOORDS_NONE;
751. 
752.     /* hero's role, race, &c haven't been chosen yet */
753.     flags.initrole = flags.initrace = flags.initgend = flags.initalign
754.         = ROLE_NONE;
755. 
756.     init_ov_primary_symbols();
757.     init_ov_rogue_symbols();
758.     /* Set the default monster and object class symbols. */
759.     init_symbols();
760.     for (i = 0; i < WARNCOUNT; i++)
761.         warnsyms[i] = def_warnsyms[i].sym;
762. 
763.     /* for "special achievement" tracking (see obj.h,
764.        create_object(sp_lev.c), addinv_core1(invent.c) */
765.     iflags.mines_prize_type = LUCKSTONE;
766.     iflags.soko_prize_type1 = BAG_OF_HOLDING;
767.     iflags.soko_prize_type2 = AMULET_OF_REFLECTION;
768. 
769.     /* assert( sizeof flags.inv_order == sizeof def_inv_order ); */
770.     (void) memcpy((genericptr_t) flags.inv_order,
771.                   (genericptr_t) def_inv_order, sizeof flags.inv_order);
772.     flags.pickup_types[0] = '\0';
773.     flags.pickup_burden = MOD_ENCUMBER;
774.     flags.sortloot = 'l'; /* sort only loot by default */
775. 
776.     for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++)
777.         flags.end_disclose[i] = DISCLOSE_PROMPT_DEFAULT_NO;
778.     switch_symbols(FALSE); /* set default characters */
779.     init_rogue_symbols();
780. #if defined(UNIX) && defined(TTY_GRAPHICS)
781.     /*
782.      * Set defaults for some options depending on what we can
783.      * detect about the environment's capabilities.
784.      * This has to be done after the global initialization above
785.      * and before reading user-specific initialization via
786.      * config file/environment variable below.
787.      */
788.     /* this detects the IBM-compatible console on most 386 boxes */
789.     if ((opts = nh_getenv("TERM")) && !strncmp(opts, "AT", 2)) {
790.         if (!symset[PRIMARY].explicitly)
791.             load_symset("IBMGraphics", PRIMARY);
792.         if (!symset[ROGUESET].explicitly)
793.             load_symset("RogueIBM", ROGUESET);
794.         switch_symbols(TRUE);
795. #ifdef TEXTCOLOR
796.         iflags.use_color = TRUE;
797. #endif
798.     }
799. #endif /* UNIX && TTY_GRAPHICS */
800. #if defined(UNIX) || defined(VMS)
801. #ifdef TTY_GRAPHICS
802.     /* detect whether a "vt" terminal can handle alternate charsets */
803.     if ((opts = nh_getenv("TERM"))
804.         /* [could also check "xterm" which emulates vtXXX by default] */
805.         && !strncmpi(opts, "vt", 2)
806.         && AS && AE && index(AS, '\016') && index(AE, '\017')) {
807.         if (!symset[PRIMARY].explicitly)
808.             load_symset("DECGraphics", PRIMARY);
809.         switch_symbols(TRUE);
810.     }
811. #endif
812. #endif /* UNIX || VMS */
813. 
814. #if defined(MSDOS) || defined(WIN32)
815.     /* Use IBM defaults. Can be overridden via config file */
816.     if (!symset[PRIMARY].explicitly)
817.         load_symset("IBMGraphics_2", PRIMARY);
818.     if (!symset[ROGUESET].explicitly)
819.         load_symset("RogueEpyx", ROGUESET);
820. #endif
821. #ifdef MAC_GRAPHICS_ENV
822.     if (!symset[PRIMARY].explicitly)
823.         load_symset("MACGraphics", PRIMARY);
824.     switch_symbols(TRUE);
825. #endif /* MAC_GRAPHICS_ENV */
826.     flags.menu_style = MENU_FULL;
827. 
828.     iflags.wc_align_message = ALIGN_TOP;
829.     iflags.wc_align_status = ALIGN_BOTTOM;
830.     /* used by tty and curses */
831.     iflags.wc2_statuslines = 2;
832.     /* only used by curses */
833.     iflags.wc2_windowborders = 2; /* 'Auto' */
834. 
835.     /* since this is done before init_objects(), do partial init here */
836.     objects[SLIME_MOLD].oc_name_idx = SLIME_MOLD;
837.     nmcpy(pl_fruit, OBJ_NAME(objects[SLIME_MOLD]), PL_FSIZ);
838. }
839. 
840. void
841. initoptions_finish()
842. {
843.     nhsym sym = 0;
844. #ifndef MAC
845.     char *opts = getenv("NETHACKOPTIONS");
846. 
847.     if (!opts)
848.         opts = getenv("HACKOPTIONS");
849.     if (opts) {
850.         if (*opts == '/' || *opts == '\\' || *opts == '@') {
851.             if (*opts == '@')
852.                 opts++; /* @filename */
853.             /* looks like a filename */
854.             if (strlen(opts) < BUFSZ / 2) {
855.                 config_error_init(TRUE, opts, CONFIG_ERROR_SECURE);
856.                 read_config_file(opts, SET_IN_FILE);
857.                 config_error_done();
858.             }
859.         } else {
860.             config_error_init(TRUE, (char *) 0, FALSE);
861.             read_config_file((char *) 0, SET_IN_FILE);
862.             config_error_done();
863.             /* let the total length of options be long;
864.              * parseoptions() will check each individually
865.              */
866.             config_error_init(FALSE, "NETHACKOPTIONS", FALSE);
867.             (void) parseoptions(opts, TRUE, FALSE);
868.             config_error_done();
869.         }
870.     } else
871. #endif /* !MAC */
872.     /*else*/ {
873.         config_error_init(TRUE, (char *) 0, FALSE);
874.         read_config_file((char *) 0, SET_IN_FILE);
875.         config_error_done();
876.     }
877. 
878.     (void) fruitadd(pl_fruit, (struct fruit *) 0);
879.     /*
880.      * Remove "slime mold" from list of object names.  This will
881.      * prevent it from being wished unless it's actually present
882.      * as a named (or default) fruit.  Wishing for "fruit" will
883.      * result in the player's preferred fruit [better than "\033"].
884.      */
885.     obj_descr[SLIME_MOLD].oc_name = "fruit";
886. 
887.     sym = get_othersym(SYM_BOULDER,
888.                 Is_rogue_level(&u.uz) ? ROGUESET : PRIMARY);
889.     if (sym)
890.         showsyms[SYM_BOULDER + SYM_OFF_X] = sym;
891.     reglyph_darkroom();
892. 
893. #ifdef STATUS_HILITES
894.     /*
895.      * A multi-interface binary might only support status highlighting
896.      * for some of the interfaces; check whether we asked for it but are
897.      * using one which doesn't.
898.      *
899.      * Option processing can take place before a user-decided WindowPort
900.      * is even initialized, so check for that too.
901.      */
902.     if (!WINDOWPORT("safe-startup")) {
903.         if (iflags.hilite_delta && !wc2_supported("statushilites")) {
904.             raw_printf("Status highlighting not supported for %s interface.",
905.                        windowprocs.name);
906.             iflags.hilite_delta = 0;
907.         }
908.     }
909. #endif
910.     return;
911. }
912. 
913. /* copy up to maxlen-1 characters; 'dest' must be able to hold maxlen;
914.    treat comma as alternate end of 'src' */
915. STATIC_OVL void
916. nmcpy(dest, src, maxlen)
917. char *dest;
918. const char *src;
919. int maxlen;
920. {
921.     int count;
922. 
923.     for (count = 1; count < maxlen; count++) {
924.         if (*src == ',' || *src == '\0')
925.             break; /*exit on \0 terminator*/
926.         *dest++ = *src++;
927.     }
928.     *dest = '\0';
929. }
930. 
931. /*
932.  * escapes(): escape expansion for showsyms.  C-style escapes understood
933.  * include \n, \b, \t, \r, \xnnn (hex), \onnn (octal), \nnn (decimal).
934.  * (Note: unlike in C, leading digit 0 is not used to indicate octal;
935.  * the letter o (either upper or lower case) is used for that.
936.  * The ^-prefix for control characters is also understood, and \[mM]
937.  * has the effect of 'meta'-ing the value which follows (so that the
938.  * alternate character set will be enabled).
939.  *
940.  * X     normal key X
941.  * ^X    control-X
942.  * \mX   meta-X
943.  *
944.  * For 3.4.3 and earlier, input ending with "\M", backslash, or caret
945.  * prior to terminating '\0' would pull that '\0' into the output and then
946.  * keep processing past it, potentially overflowing the output buffer.
947.  * Now, trailing \ or ^ will act like \\ or \^ and add '\\' or '^' to the
948.  * output and stop there; trailing \M will fall through to \<other> and
949.  * yield 'M', then stop.  Any \X or \O followed by something other than
950.  * an appropriate digit will also fall through to \<other> and yield 'X'
951.  * or 'O', plus stop if the non-digit is end-of-string.
952.  */
953. STATIC_OVL void
954. escapes(cp, tp)
955. const char *cp; /* might be 'tp', updating in place */
956. char *tp; /* result is never longer than 'cp' */
957. {
958.     static NEARDATA const char oct[] = "01234567", dec[] = "0123456789",
959.                                hex[] = "00112233445566778899aAbBcCdDeEfF";
960.     const char *dp;
961.     int cval, meta, dcount;
962. 
963.     while (*cp) {
964.         /* \M has to be followed by something to do meta conversion,
965.            otherwise it will just be \M which ultimately yields 'M' */
966.         meta = (*cp == '\\' && (cp[1] == 'm' || cp[1] == 'M') && cp[2]);
967.         if (meta)
968.             cp += 2;
969. 
970.         cval = dcount = 0; /* for decimal, octal, hexadecimal cases */
971.         if ((*cp != '\\' && *cp != '^') || !cp[1]) {
972.             /* simple character, or nothing left for \ or ^ to escape */
973.             cval = *cp++;
974.         } else if (*cp == '^') { /* expand control-character syntax */
975.             cval = (*++cp & 0x1f);
976.             ++cp;
977. 
978.         /* remaining cases are all for backslash; we know cp[1] is not \0 */
979.         } else if (index(dec, cp[1])) {
980.             ++cp; /* move past backslash to first digit */
981.             do {
982.                 cval = (cval * 10) + (*cp - '0');
983.             } while (*++cp && index(dec, *cp) && ++dcount < 3);
984.         } else if ((cp[1] == 'o' || cp[1] == 'O') && cp[2]
985.                    && index(oct, cp[2])) {
986.             cp += 2; /* move past backslash and 'O' */
987.             do {
988.                 cval = (cval * 8) + (*cp - '0');
989.             } while (*++cp && index(oct, *cp) && ++dcount < 3);
990.         } else if ((cp[1] == 'x' || cp[1] == 'X') && cp[2]
991.                    && (dp = index(hex, cp[2])) != 0) {
992.             cp += 2; /* move past backslash and 'X' */
993.             do {
994.                 cval = (cval * 16) + ((int) (dp - hex) / 2);
995.             } while (*++cp && (dp = index(hex, *cp)) != 0 && ++dcount < 2);
996.         } else { /* C-style character escapes */
997.             switch (*++cp) {
998.             case '\\':
999.                 cval = '\\';
1000.                 break;
1001.             case 'n':
1002.                 cval = '\n';
1003.                 break;
1004.             case 't':
1005.                 cval = '\t';
1006.                 break;
1007.             case 'b':
1008.                 cval = '\b';
1009.                 break;
1010.             case 'r':
1011.                 cval = '\r';
1012.                 break;
1013.             default:
1014.                 cval = *cp;
1015.             }
1016.             ++cp;
1017.         }
1018. 
1019.         if (meta)
1020.             cval |= 0x80;
1021.         *tp++ = (char) cval;
1022.     }
1023.     *tp = '\0';
1024. }
1025. 
1026. STATIC_OVL void
1027. rejectoption(optname)
1028. const char *optname;
1029. {
1030. #ifdef MICRO
1031.     pline("\"%s\" settable only from %s.", optname, configfile);
1032. #else
1033.     pline("%s can be set only from NETHACKOPTIONS or %s.", optname,
1034.           configfile);
1035. #endif
1036. }
1037. 
1038. /*
1039. 
1040. # errors:
1041. OPTIONS=aaaaaaaaaa[ more than 247 (255 - 8 for 'OPTIONS=') total ]aaaaaaaaaa
1042. OPTIONS
1043. OPTIONS=
1044. MSGTYPE=stop"You swap places with "
1045. MSGTYPE=st.op "You swap places with "
1046. MSGTYPE=stop "You swap places with \"
1047. MENUCOLOR=" blessed "green&none
1048. MENUCOLOR=" holy " = green&reverse
1049. MENUCOLOR=" cursed " = red&uline
1050. MENUCOLOR=" unholy " = reed
1051. OPTIONS=!legacy:true,fooo
1052. OPTIONS=align:!pin
1053. OPTIONS=gender
1054. 
1055. */
1056. 
1057. STATIC_OVL char *
1058. string_for_opt(opts, val_optional)
1059. char *opts;
1060. boolean val_optional;
1061. {
1062.     char *colon, *equals;
1063. 
1064.     colon = index(opts, ':');
1065.     equals = index(opts, '=');
1066.     if (!colon || (equals && equals < colon))
1067.         colon = equals;
1068. 
1069.     if (!colon || !*++colon) {
1070.         if (!val_optional)
1071.             config_error_add("Missing parameter for '%s'", opts);
1072.         return empty_optstr;
1073.     }
1074.     return colon;
1075. }
1076. 
1077. STATIC_OVL char *
1078. string_for_env_opt(optname, opts, val_optional)
1079. const char *optname;
1080. char *opts;
1081. boolean val_optional;
1082. {
1083.     if (!initial) {
1084.         rejectoption(optname);
1085.         return empty_optstr;
1086.     }
1087.     return string_for_opt(opts, val_optional);
1088. }
1089. 
1090. STATIC_OVL void
1091. bad_negation(optname, with_parameter)
1092. const char *optname;
1093. boolean with_parameter;
1094. {
1095.     pline_The("%s option may not %sbe negated.", optname,
1096.               with_parameter ? "both have a value and " : "");
1097. }
1098. 
1099. /*
1100.  * Change the inventory order, using the given string as the new order.
1101.  * Missing characters in the new order are filled in at the end from
1102.  * the current inv_order, except for gold, which is forced to be first
1103.  * if not explicitly present.
1104.  *
1105.  * This routine returns 1 unless there is a duplicate or bad char in
1106.  * the string.
1107.  */
1108. STATIC_OVL int
1109. change_inv_order(op)
1110. char *op;
1111. {
1112.     int oc_sym, num;
1113.     char *sp, buf[QBUFSZ];
1114.     int retval = 1;
1115. 
1116.     num = 0;
1117.     if (!index(op, GOLD_SYM))
1118.         buf[num++] = COIN_CLASS;
1119. 
1120.     for (sp = op; *sp; sp++) {
1121.         boolean fail = FALSE;
1122.         oc_sym = def_char_to_objclass(*sp);
1123.         /* reject bad or duplicate entries */
1124.         if (oc_sym == MAXOCLASSES) { /* not an object class char */
1125.             config_error_add("Not an object class '%c'", *sp);
1126.             retval = 0;
1127.             fail = TRUE;
1128.         } else if (!index(flags.inv_order, oc_sym)) {
1129.             /* VENOM_CLASS, RANDOM_CLASS, and ILLOBJ_CLASS are excluded
1130.                because they aren't in def_inv_order[] so don't make it
1131.                into flags.inv_order, hence always fail this index() test */
1132.             config_error_add("Object class '%c' not allowed", *sp);
1133.             retval = 0;
1134.             fail = TRUE;
1135.         } else if (index(sp + 1, *sp)) {
1136.             config_error_add("Duplicate object class '%c'", *sp);
1137.             retval = 0;
1138.             fail = TRUE;
1139.         }
1140.         /* retain good ones */
1141.         if (!fail)
1142.             buf[num++] = (char) oc_sym;
1143.     }
1144.     buf[num] = '\0';
1145. 
1146.     /* fill in any omitted classes, using previous ordering */
1147.     for (sp = flags.inv_order; *sp; sp++)
1148.         if (!index(buf, *sp))
1149.             (void) strkitten(&buf[num++], *sp);
1150.     buf[MAXOCLASSES - 1] = '\0';
1151. 
1152.     Strcpy(flags.inv_order, buf);
1153.     return retval;
1154. }
1155. 
1156. STATIC_OVL boolean
1157. warning_opts(opts, optype)
1158. register char *opts;
1159. const char *optype;
1160. {
1161.     uchar translate[WARNCOUNT];
1162.     int length, i;
1163. 
1164.     if ((opts = string_for_env_opt(optype, opts, FALSE)) == empty_optstr)
1165.         return FALSE;
1166.     escapes(opts, opts);
1167. 
1168.     length = (int) strlen(opts);
1169.     /* match the form obtained from PC configuration files */
1170.     for (i = 0; i < WARNCOUNT; i++)
1171.         translate[i] = (i >= length) ? 0
1172.                                      : opts[i] ? (uchar) opts[i]
1173.                                                : def_warnsyms[i].sym;
1174.     assign_warnings(translate);
1175.     return TRUE;
1176. }
1177. 
1178. void
1179. assign_warnings(graph_chars)
1180. register uchar *graph_chars;
1181. {
1182.     int i;
1183. 
1184.     for (i = 0; i < WARNCOUNT; i++)
1185.         if (graph_chars[i])
1186.             warnsyms[i] = graph_chars[i];
1187. }
1188. 
1189. STATIC_OVL int
1190. feature_alert_opts(op, optn)
1191. char *op;
1192. const char *optn;
1193. {
1194.     char buf[BUFSZ];
1195.     unsigned long fnv = get_feature_notice_ver(op); /* version.c */
1196. 
1197.     if (fnv == 0L)
1198.         return 0;
1199.     if (fnv > get_current_feature_ver()) {
1200.         if (!initial) {
1201.             You_cant("disable new feature alerts for future versions.");
1202.         } else {
1203.             config_error_add(
1204.                         "%s=%s Invalid reference to a future version ignored",
1205.                              optn, op);
1206.         }
1207.         return 0;
1208.     }
1209. 
1210.     flags.suppress_alert = fnv;
1211.     if (!initial) {
1212.         Sprintf(buf, "%lu.%lu.%lu", FEATURE_NOTICE_VER_MAJ,
1213.                 FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH);
1214.         pline(
1215.           "Feature change alerts disabled for NetHack %s features and prior.",
1216.               buf);
1217.     }
1218.     return 1;
1219. }
1220. 
1221. void
1222. set_duplicate_opt_detection(on_or_off)
1223. int on_or_off;
1224. {
1225.     int k, *optptr;
1226. 
1227.     if (on_or_off != 0) {
1228.         /*-- ON --*/
1229.         if (iflags.opt_booldup)
1230.             impossible("iflags.opt_booldup already on (memory leak)");
1231.         iflags.opt_booldup = (int *) alloc(SIZE(boolopt) * sizeof (int));
1232.         optptr = iflags.opt_booldup;
1233.         for (k = 0; k < SIZE(boolopt); ++k)
1234.             *optptr++ = 0;
1235. 
1236.         if (iflags.opt_compdup)
1237.             impossible("iflags.opt_compdup already on (memory leak)");
1238.         iflags.opt_compdup = (int *) alloc(SIZE(compopt) * sizeof (int));
1239.         optptr = iflags.opt_compdup;
1240.         for (k = 0; k < SIZE(compopt); ++k)
1241.             *optptr++ = 0;
1242.     } else {
1243.         /*-- OFF --*/
1244.         if (iflags.opt_booldup)
1245.             free((genericptr_t) iflags.opt_booldup);
1246.         iflags.opt_booldup = (int *) 0;
1247.         if (iflags.opt_compdup)
1248.             free((genericptr_t) iflags.opt_compdup);
1249.         iflags.opt_compdup = (int *) 0;
1250.     }
1251. }
1252. 
1253. STATIC_OVL boolean
1254. duplicate_opt_detection(opts, iscompound)
1255. const char *opts;
1256. int iscompound; /* 0 == boolean option, 1 == compound */
1257. {
1258.     int i, *optptr;
1259. 
1260.     if (!iscompound && iflags.opt_booldup && initial && from_file) {
1261.         for (i = 0; boolopt[i].name; i++) {
1262.             if (match_optname(opts, boolopt[i].name, 3, FALSE)) {
1263.                 optptr = iflags.opt_booldup + i;
1264.                 *optptr += 1;
1265.                 if (*optptr > 1)
1266.                     return TRUE;
1267.                 else
1268.                     return FALSE;
1269.             }
1270.         }
1271.     } else if (iscompound && iflags.opt_compdup && initial && from_file) {
1272.         for (i = 0; compopt[i].name; i++) {
1273.             if (match_optname(opts, compopt[i].name, strlen(compopt[i].name),
1274.                               TRUE)) {
1275.                 optptr = iflags.opt_compdup + i;
1276.                 *optptr += 1;
1277.                 if (*optptr > 1)
1278.                     return TRUE;
1279.                 else
1280.                     return FALSE;
1281.             }
1282.         }
1283.     }
1284.     return FALSE;
1285. }
1286. 
1287. STATIC_OVL void
1288. complain_about_duplicate(opts, iscompound)
1289. const char *opts;
1290. int iscompound; /* 0 == boolean option, 1 == compound */
1291. {
1292. #ifdef MAC
1293.     /* the Mac has trouble dealing with the output of messages while
1294.      * processing the config file.  That should get fixed one day.
1295.      * For now just return.
1296.      */
1297. #else /* !MAC */
1298.     config_error_add("%s option specified multiple times: %s",
1299.                      iscompound ? "compound" : "boolean", opts);
1300. #endif /* ?MAC */
1301.     return;
1302. }
1303. 
1304. /* paranoia[] - used by parseoptions() and special_handling() */
1305. STATIC_VAR const struct paranoia_opts {
1306.     int flagmask;        /* which paranoid option */
1307.     const char *argname; /* primary name */
1308.     int argMinLen;       /* minimum number of letters to match */
1309.     const char *synonym; /* alternate name (optional) */
1310.     int synMinLen;
1311.     const char *explain; /* for interactive menu */
1312. } paranoia[] = {
1313.     /* there are some initial-letter conflicts: "a"ttack vs "a"ll, "attack"
1314.        takes precedence and "all" isn't present in the interactive menu,
1315.        and "d"ie vs "d"eath, synonyms for each other so doesn't matter;
1316.        (also "p"ray vs "P"aranoia, "pray" takes precedence since "Paranoia"
1317.        is just a synonym for "Confirm"); "b"ones vs "br"eak-wand, the
1318.        latter requires at least two letters; "e"at vs "ex"plore,
1319.        "cont"inue eating vs "C"onfirm; "wand"-break vs "Were"-change,
1320.        both require at least two letters during config processing and use
1321.        case-senstivity for 'O's interactive menu */
1322.     { PARANOID_CONFIRM, "Confirm", 1, "Paranoia", 2,
1323.       "for \"yes\" confirmations, require \"no\" to reject" },
1324.     { PARANOID_QUIT, "quit", 1, "explore", 2,
1325.       "yes vs y to quit or to enter explore mode" },
1326.     { PARANOID_DIE, "die", 1, "death", 2,
1327.       "yes vs y to die (explore mode or debug mode)" },
1328.     { PARANOID_BONES, "bones", 1, 0, 0,
1329.       "yes vs y to save bones data when dying in debug mode" },
1330.     { PARANOID_HIT, "attack", 1, "hit", 1,
1331.       "yes vs y to attack a peaceful monster" },
1332.     { PARANOID_BREAKWAND, "wand-break", 2, "break-wand", 2,
1333.       "yes vs y to break a wand via (a)pply" },
1334.     { PARANOID_EATING, "eat", 1, "continue", 4,
1335.       "yes vs y to continue eating after first bite when satiated" },
1336.     { PARANOID_WERECHANGE, "Were-change", 2, (const char *) 0, 0,
1337.       "yes vs y to change form when lycanthropy is controllable" },
1338.     { PARANOID_PRAY, "pray", 1, 0, 0,
1339.       "y to pray (supersedes old \"prayconfirm\" option)" },
1340.     { PARANOID_REMOVE, "Remove", 1, "Takeoff", 1,
1341.       "always pick from inventory for Remove and Takeoff" },
1342.     /* for config file parsing; interactive menu skips these */
1343.     { 0, "none", 4, 0, 0, 0 }, /* require full word match */
1344.     { ~0, "all", 3, 0, 0, 0 }, /* ditto */
1345. };
1346. 
1347. extern struct menucoloring *menu_colorings;
1348. 
1349. static const struct {
1350.     const char *name;
1351.     const int color;
1352. } colornames[] = {
1353.     { "black", CLR_BLACK },
1354.     { "red", CLR_RED },
1355.     { "green", CLR_GREEN },
1356.     { "brown", CLR_BROWN },
1357.     { "blue", CLR_BLUE },
1358.     { "magenta", CLR_MAGENTA },
1359.     { "cyan", CLR_CYAN },
1360.     { "gray", CLR_GRAY },
1361.     { "orange", CLR_ORANGE },
1362.     { "light green", CLR_BRIGHT_GREEN },
1363.     { "yellow", CLR_YELLOW },
1364.     { "light blue", CLR_BRIGHT_BLUE },
1365.     { "light magenta", CLR_BRIGHT_MAGENTA },
1366.     { "light cyan", CLR_BRIGHT_CYAN },
1367.     { "white", CLR_WHITE },
1368.     { "no color", NO_COLOR },
1369.     { NULL, CLR_BLACK }, /* everything after this is an alias */
1370.     { "transparent", NO_COLOR },
1371.     { "purple", CLR_MAGENTA },
1372.     { "light purple", CLR_BRIGHT_MAGENTA },
1373.     { "bright purple", CLR_BRIGHT_MAGENTA },
1374.     { "grey", CLR_GRAY },
1375.     { "bright red", CLR_ORANGE },
1376.     { "bright green", CLR_BRIGHT_GREEN },
1377.     { "bright blue", CLR_BRIGHT_BLUE },
1378.     { "bright magenta", CLR_BRIGHT_MAGENTA },
1379.     { "bright cyan", CLR_BRIGHT_CYAN }
1380. };
1381. 
1382. static const struct {
1383.     const char *name;
1384.     const int attr;
1385. } attrnames[] = {
1386.     { "none", ATR_NONE },
1387.     { "bold", ATR_BOLD },
1388.     { "dim", ATR_DIM },
1389.     { "underline", ATR_ULINE },
1390.     { "blink", ATR_BLINK },
1391.     { "inverse", ATR_INVERSE },
1392.     { NULL, ATR_NONE }, /* everything after this is an alias */
1393.     { "normal", ATR_NONE },
1394.     { "uline", ATR_ULINE },
1395.     { "reverse", ATR_INVERSE },
1396. };
1397. 
1398. const char *
1399. clr2colorname(clr)
1400. int clr;
1401. {
1402.     int i;
1403. 
1404.     for (i = 0; i < SIZE(colornames); i++)
1405.         if (colornames[i].name && colornames[i].color == clr)
1406.             return colornames[i].name;
1407.     return (char *) 0;
1408. }
1409. 
1410. int
1411. match_str2clr(str)
1412. char *str;
1413. {
1414.     int i, c = CLR_MAX;
1415. 
1416.     /* allow "lightblue", "light blue", and "light-blue" to match "light blue"
1417.        (also junk like "_l i-gh_t---b l u e" but we won't worry about that);
1418.        also copes with trailing space; caller has removed any leading space */
1419.     for (i = 0; i < SIZE(colornames); i++)
1420.         if (colornames[i].name
1421.             && fuzzymatch(str, colornames[i].name, " -_", TRUE)) {
1422.             c = colornames[i].color;
1423.             break;
1424.         }
1425.     if (i == SIZE(colornames) && (*str >= '0' && *str <= '9'))
1426.         c = atoi(str);
1427. 
1428.     if (c == CLR_MAX)
1429.         config_error_add("Unknown color '%s'", str);
1430. 
1431.     return c;
1432. }
1433. 
1434. STATIC_OVL const char *
1435. attr2attrname(attr)
1436. int attr;
1437. {
1438.     int i;
1439. 
1440.     for (i = 0; i < SIZE(attrnames); i++)
1441.         if (attrnames[i].attr == attr)
1442.             return attrnames[i].name;
1443.     return (char *) 0;
1444. }
1445. 
1446. int
1447. match_str2attr(str, complain)
1448. const char *str;
1449. boolean complain;
1450. {
1451.     int i, a = -1;
1452. 
1453.     for (i = 0; i < SIZE(attrnames); i++)
1454.         if (attrnames[i].name
1455.             && fuzzymatch(str, attrnames[i].name, " -_", TRUE)) {
1456.             a = attrnames[i].attr;
1457.             break;
1458.         }
1459. 
1460.     if (a == -1 && complain)
1461.         config_error_add("Unknown text attribute '%s'", str);
1462. 
1463.     return a;
1464. }
1465. 
1466. int
1467. query_color(prompt)
1468. const char *prompt;
1469. {
1470.     winid tmpwin;
1471.     anything any;
1472.     int i, pick_cnt;
1473.     menu_item *picks = (menu_item *) 0;
1474. 
1475.     tmpwin = create_nhwindow(NHW_MENU);
1476.     start_menu(tmpwin);
1477.     any = zeroany;
1478.     for (i = 0; i < SIZE(colornames); i++) {
1479.         if (!colornames[i].name)
1480.             break;
1481.         any.a_int = i + 1;
1482.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, colornames[i].name,
1483.                  (colornames[i].color == NO_COLOR) ? MENU_SELECTED
1484.                                                    : MENU_UNSELECTED);
1485.     }
1486.     end_menu(tmpwin, (prompt && *prompt) ? prompt : "Pick a color");
1487.     pick_cnt = select_menu(tmpwin, PICK_ONE, &picks);
1488.     destroy_nhwindow(tmpwin);
1489.     if (pick_cnt > 0) {
1490.         i = colornames[picks[0].item.a_int - 1].color;
1491.         /* pick_cnt==2: explicitly picked something other than the
1492.            preselected entry */
1493.         if (pick_cnt == 2 && i == NO_COLOR)
1494.             i = colornames[picks[1].item.a_int - 1].color;
1495.         free((genericptr_t) picks);
1496.         return i;
1497.     } else if (pick_cnt == 0) {
1498.         /* pick_cnt==0: explicitly picking preselected entry toggled it off */
1499.         return NO_COLOR;
1500.     }
1501.     return -1;
1502. }
1503. 
1504. /* ask about highlighting attribute; for menu headers and menu
1505.    coloring patterns, only one attribute at a time is allowed;
1506.    for status highlighting, multiple attributes are allowed [overkill;
1507.    life would be much simpler if that were restricted to one also...] */
1508. int
1509. query_attr(prompt)
1510. const char *prompt;
1511. {
1512.     winid tmpwin;
1513.     anything any;
1514.     int i, pick_cnt;
1515.     menu_item *picks = (menu_item *) 0;
1516.     boolean allow_many = (prompt && !strncmpi(prompt, "Choose", 6));
1517.     int default_attr = ATR_NONE;
1518. 
1519.     if (prompt && strstri(prompt, "menu headings"))
1520.         default_attr = iflags.menu_headings;
1521.     tmpwin = create_nhwindow(NHW_MENU);
1522.     start_menu(tmpwin);
1523.     any = zeroany;
1524.     for (i = 0; i < SIZE(attrnames); i++) {
1525.         if (!attrnames[i].name)
1526.             break;
1527.         any.a_int = i + 1;
1528.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, attrnames[i].attr,
1529.                  attrnames[i].name,
1530.                  (attrnames[i].attr == default_attr) ? MENU_SELECTED
1531.                                                      : MENU_UNSELECTED);
1532.     }
1533.     end_menu(tmpwin, (prompt && *prompt) ? prompt : "Pick an attribute");
1534.     pick_cnt = select_menu(tmpwin, allow_many ? PICK_ANY : PICK_ONE, &picks);
1535.     destroy_nhwindow(tmpwin);
1536.     if (pick_cnt > 0) {
1537.         int j, k = 0;
1538. 
1539.         if (allow_many) {
1540.             /* PICK_ANY, with one preselected entry (ATR_NONE) which
1541.                should be excluded if any other choices were picked */
1542.             for (i = 0; i < pick_cnt; ++i) {
1543.                 j = picks[i].item.a_int - 1;
1544.                 if (attrnames[j].attr != ATR_NONE || pick_cnt == 1) {
1545.                     switch (attrnames[j].attr) {
1546.                     case ATR_DIM:
1547.                         k |= HL_DIM;
1548.                         break;
1549.                     case ATR_BLINK:
1550.                         k |= HL_BLINK;
1551.                         break;
1552.                     case ATR_ULINE:
1553.                         k |= HL_ULINE;
1554.                         break;
1555.                     case ATR_INVERSE:
1556.                         k |= HL_INVERSE;
1557.                         break;
1558.                     case ATR_BOLD:
1559.                         k |= HL_BOLD;
1560.                         break;
1561.                     case ATR_NONE:
1562.                         k = HL_NONE;
1563.                         break;
1564.                     }
1565.                 }
1566.             }
1567.         } else {
1568.             /* PICK_ONE, but might get 0 or 2 due to preselected entry */
1569.             j = picks[0].item.a_int - 1;
1570.             /* pick_cnt==2: explicitly picked something other than the
1571.                preselected entry */
1572.             if (pick_cnt == 2 && attrnames[j].attr == default_attr)
1573.                 j = picks[1].item.a_int - 1;
1574.             k = attrnames[j].attr;
1575.         }
1576.         free((genericptr_t) picks);
1577.         return k;
1578.     } else if (pick_cnt == 0 && !allow_many) {
1579.         /* PICK_ONE, preselected entry explicitly chosen */
1580.         return default_attr;
1581.     }
1582.     /* either ESC to explicitly cancel (pick_cnt==-1) or
1583.        PICK_ANY with preselected entry toggled off and nothing chosen */
1584.     return -1;
1585. }
1586. 
1587. static const struct {
1588.     const char *name;
1589.     xchar msgtyp;
1590.     const char *descr;
1591. } msgtype_names[] = {
1592.     { "show", MSGTYP_NORMAL, "Show message normally" },
1593.     { "hide", MSGTYP_NOSHOW, "Hide message" },
1594.     { "noshow", MSGTYP_NOSHOW, NULL },
1595.     { "stop", MSGTYP_STOP, "Prompt for more after the message" },
1596.     { "more", MSGTYP_STOP, NULL },
1597.     { "norep", MSGTYP_NOREP, "Do not repeat the message" }
1598. };
1599. 
1600. STATIC_OVL const char *
1601. msgtype2name(typ)
1602. int typ;
1603. {
1604.     int i;
1605. 
1606.     for (i = 0; i < SIZE(msgtype_names); i++)
1607.         if (msgtype_names[i].descr && msgtype_names[i].msgtyp == typ)
1608.             return msgtype_names[i].name;
1609.     return (char *) 0;
1610. }
1611. 
1612. STATIC_OVL int
1613. query_msgtype()
1614. {
1615.     winid tmpwin;
1616.     anything any;
1617.     int i, pick_cnt;
1618.     menu_item *picks = (menu_item *) 0;
1619. 
1620.     tmpwin = create_nhwindow(NHW_MENU);
1621.     start_menu(tmpwin);
1622.     any = zeroany;
1623.     for (i = 0; i < SIZE(msgtype_names); i++)
1624.         if (msgtype_names[i].descr) {
1625.             any.a_int = msgtype_names[i].msgtyp + 1;
1626.             add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
1627.                  msgtype_names[i].descr, MENU_UNSELECTED);
1628.         }
1629.     end_menu(tmpwin, "How to show the message");
1630.     pick_cnt = select_menu(tmpwin, PICK_ONE, &picks);
1631.     destroy_nhwindow(tmpwin);
1632.     if (pick_cnt > 0) {
1633.         i = picks->item.a_int - 1;
1634.         free((genericptr_t) picks);
1635.         return i;
1636.     }
1637.     return -1;
1638. }
1639. 
1640. STATIC_OVL boolean
1641. msgtype_add(typ, pattern)
1642. int typ;
1643. char *pattern;
1644. {
1645.     struct plinemsg_type *tmp = (struct plinemsg_type *) alloc(sizeof *tmp);
1646. 
1647.     tmp->msgtype = typ;
1648.     tmp->regex = regex_init();
1649.     if (!regex_compile(pattern, tmp->regex)) {
1650.         static const char *re_error = "MSGTYPE regex error";
1651. 
1652.         config_error_add("%s: %s", re_error, regex_error_desc(tmp->regex));
1653.         regex_free(tmp->regex);
1654.         free((genericptr_t) tmp);
1655.         return FALSE;
1656.     }
1657.     tmp->pattern = dupstr(pattern);
1658.     tmp->next = plinemsg_types;
1659.     plinemsg_types = tmp;
1660.     return TRUE;
1661. }
1662. 
1663. void
1664. msgtype_free()
1665. {
1666.     struct plinemsg_type *tmp, *tmp2 = 0;
1667. 
1668.     for (tmp = plinemsg_types; tmp; tmp = tmp2) {
1669.         tmp2 = tmp->next;
1670.         free((genericptr_t) tmp->pattern);
1671.         regex_free(tmp->regex);
1672.         free((genericptr_t) tmp);
1673.     }
1674.     plinemsg_types = (struct plinemsg_type *) 0;
1675. }
1676. 
1677. STATIC_OVL void
1678. free_one_msgtype(idx)
1679. int idx; /* 0 .. */
1680. {
1681.     struct plinemsg_type *tmp = plinemsg_types;
1682.     struct plinemsg_type *prev = NULL;
1683. 
1684.     while (tmp) {
1685.         if (idx == 0) {
1686.             struct plinemsg_type *next = tmp->next;
1687. 
1688.             regex_free(tmp->regex);
1689.             free((genericptr_t) tmp->pattern);
1690.             free((genericptr_t) tmp);
1691.             if (prev)
1692.                 prev->next = next;
1693.             else
1694.                 plinemsg_types = next;
1695.             return;
1696.         }
1697.         idx--;
1698.         prev = tmp;
1699.         tmp = tmp->next;
1700.     }
1701. }
1702. 
1703. int
1704. msgtype_type(msg, norepeat)
1705. const char *msg;
1706. boolean norepeat; /* called from Norep(via pline) */
1707. {
1708.     struct plinemsg_type *tmp = plinemsg_types;
1709. 
1710.     while (tmp) {
1711.         /* we don't exclude entries with negative msgtype values
1712.            because then the msg might end up matching a later pattern */
1713.         if (regex_match(msg, tmp->regex))
1714.             return tmp->msgtype;
1715.         tmp = tmp->next;
1716.     }
1717.     return norepeat ? MSGTYP_NOREP : MSGTYP_NORMAL;
1718. }
1719. 
1720. /* negate one or more types of messages so that their type handling will
1721.    be disabled or re-enabled; MSGTYPE_NORMAL (value 0) is not affected */
1722. void
1723. hide_unhide_msgtypes(hide, hide_mask)
1724. boolean hide;
1725. int hide_mask;
1726. {
1727.     struct plinemsg_type *tmp;
1728.     int mt;
1729. 
1730.     /* negative msgtype value won't be recognized by pline, so does nothing */
1731.     for (tmp = plinemsg_types; tmp; tmp = tmp->next) {
1732.         mt = tmp->msgtype;
1733.         if (!hide)
1734.             mt = -mt; /* unhide: negate negative, yielding positive */
1735.         if (mt > 0 && ((1 << mt) & hide_mask))
1736.             tmp->msgtype = -tmp->msgtype;
1737.     }
1738. }
1739. 
1740. STATIC_OVL int
1741. msgtype_count(VOID_ARGS)
1742. {
1743.     int c = 0;
1744.     struct plinemsg_type *tmp = plinemsg_types;
1745. 
1746.     while (tmp) {
1747.         c++;
1748.         tmp = tmp->next;
1749.     }
1750.     return c;
1751. }
1752. 
1753. boolean
1754. msgtype_parse_add(str)
1755. char *str;
1756. {
1757.     char pattern[256];
1758.     char msgtype[11];
1759. 
1760.     if (sscanf(str, "%10s \"%255[^\"]\"", msgtype, pattern) == 2) {
1761.         int typ = -1;
1762.         int i;
1763. 
1764.         for (i = 0; i < SIZE(msgtype_names); i++)
1765.             if (!strncmpi(msgtype_names[i].name, msgtype, strlen(msgtype))) {
1766.                 typ = msgtype_names[i].msgtyp;
1767.                 break;
1768.             }
1769.         if (typ != -1)
1770.             return msgtype_add(typ, pattern);
1771.         else
1772.             config_error_add("Unknown message type '%s'", msgtype);
1773.     } else {
1774.         config_error_add("Malformed MSGTYPE");
1775.     }
1776.     return FALSE;
1777. }
1778. 
1779. STATIC_OVL boolean
1780. test_regex_pattern(str, errmsg)
1781. const char *str;
1782. const char *errmsg;
1783. {
1784.     static const char re_error[] = "Regex error";
1785.     struct nhregex *match;
1786.     boolean retval = TRUE;
1787. 
1788.     if (!str)
1789.         return FALSE;
1790. 
1791.     match = regex_init();
1792.     if (!match) {
1793.         config_error_add("NHregex error");
1794.         return FALSE;
1795.     }
1796. 
1797.     if (!regex_compile(str, match)) {
1798.         config_error_add("%s: %s", errmsg ? errmsg : re_error,
1799.                          regex_error_desc(match));
1800.         retval = FALSE;
1801.     }
1802.     regex_free(match);
1803.     return retval;
1804. }
1805. 
1806. STATIC_OVL boolean
1807. add_menu_coloring_parsed(str, c, a)
1808. char *str;
1809. int c, a;
1810. {
1811.     static const char re_error[] = "Menucolor regex error";
1812.     struct menucoloring *tmp;
1813. 
1814.     if (!str)
1815.         return FALSE;
1816.     tmp = (struct menucoloring *) alloc(sizeof *tmp);
1817.     tmp->match = regex_init();
1818.     if (!regex_compile(str, tmp->match)) {
1819.         config_error_add("%s: %s", re_error, regex_error_desc(tmp->match));
1820.         regex_free(tmp->match);
1821.         free(tmp);
1822.         return FALSE;
1823.     } else {
1824.         tmp->next = menu_colorings;
1825.         tmp->origstr = dupstr(str);
1826.         tmp->color = c;
1827.         tmp->attr = a;
1828.         menu_colorings = tmp;
1829.         return TRUE;
1830.     }
1831. }
1832. 
1833. /* parse '"regex_string"=color&attr' and add it to menucoloring */
1834. boolean
1835. add_menu_coloring(tmpstr)
1836. char *tmpstr; /* never Null but could be empty */
1837. {
1838.     int c = NO_COLOR, a = ATR_NONE;
1839.     char *tmps, *cs, *amp;
1840.     char str[BUFSZ];
1841. 
1842.     (void) strncpy(str, tmpstr, sizeof str - 1);
1843.     str[sizeof str - 1] = '\0';
1844. 
1845.     if ((cs = index(str, '=')) == 0) {
1846.         config_error_add("Malformed MENUCOLOR");
1847.         return FALSE;
1848.     }
1849. 
1850.     tmps = cs + 1; /* advance past '=' */
1851.     mungspaces(tmps);
1852.     if ((amp = index(tmps, '&')) != 0)
1853.         *amp = '\0';
1854. 
1855.     c = match_str2clr(tmps);
1856.     if (c >= CLR_MAX)
1857.         return FALSE;
1858. 
1859.     if (amp) {
1860.         tmps = amp + 1; /* advance past '&' */
1861.         a = match_str2attr(tmps, TRUE);
1862.         if (a == -1)
1863.             return FALSE;
1864.     }
1865. 
1866.     /* the regexp portion here has not been condensed by mungspaces() */
1867.     *cs = '\0';
1868.     tmps = str;
1869.     if (*tmps == '"' || *tmps == '\) {
1870.         cs--;
1871.         while (isspace((uchar) *cs))
1872.             cs--;
1873.         if (*cs == *tmps) {
1874.             *cs = '\0';
1875.             tmps++;
1876.         }
1877.     }
1878.     return add_menu_coloring_parsed(tmps, c, a);
1879. }
1880. 
1881. boolean
1882. get_menu_coloring(str, color, attr)
1883. const char *str;
1884. int *color, *attr;
1885. {
1886.     struct menucoloring *tmpmc;
1887. 
1888.     if (iflags.use_menu_color)
1889.         for (tmpmc = menu_colorings; tmpmc; tmpmc = tmpmc->next)
1890.             if (regex_match(str, tmpmc->match)) {
1891.                 *color = tmpmc->color;
1892.                 *attr = tmpmc->attr;
1893.                 return TRUE;
1894.             }
1895.     return FALSE;
1896. }
1897. 
1898. void
1899. free_menu_coloring()
1900. {
1901.     struct menucoloring *tmp, *tmp2;
1902. 
1903.     for (tmp = menu_colorings; tmp; tmp = tmp2) {
1904.         tmp2 = tmp->next;
1905.         regex_free(tmp->match);
1906.         free((genericptr_t) tmp->origstr);
1907.         free((genericptr_t) tmp);
1908.     }
1909. }
1910. 
1911. STATIC_OVL void
1912. free_one_menu_coloring(idx)
1913. int idx; /* 0 .. */
1914. {
1915.     struct menucoloring *tmp = menu_colorings;
1916.     struct menucoloring *prev = NULL;
1917. 
1918.     while (tmp) {
1919.         if (idx == 0) {
1920.             struct menucoloring *next = tmp->next;
1921. 
1922.             regex_free(tmp->match);
1923.             free((genericptr_t) tmp->origstr);
1924.             free((genericptr_t) tmp);
1925.             if (prev)
1926.                 prev->next = next;
1927.             else
1928.                 menu_colorings = next;
1929.             return;
1930.         }
1931.         idx--;
1932.         prev = tmp;
1933.         tmp = tmp->next;
1934.     }
1935. }
1936. 
1937. STATIC_OVL int
1938. count_menucolors(VOID_ARGS)
1939. {
1940.     struct menucoloring *tmp;
1941.     int count = 0;
1942. 
1943.     for (tmp = menu_colorings; tmp; tmp = tmp->next)
1944.         count++;
1945.     return count;
1946. }
1947. 
1948. STATIC_OVL boolean
1949. parse_role_opts(negated, fullname, opts, opp)
1950. boolean negated;
1951. const char *fullname;
1952. char *opts;
1953. char **opp;
1954. {
1955.     char *op = *opp;
1956. 
1957.     if (negated) {
1958.         bad_negation(fullname, FALSE);
1959.     } else if ((op = string_for_env_opt(fullname, opts, FALSE))
1960.                                         != empty_optstr) {
1961.         boolean val_negated = FALSE;
1962. 
1963.         while ((*op == '!') || !strncmpi(op, "no", 2)) {
1964.             if (*op == '!')
1965.                 op++;
1966.             else
1967.                 op += 2;
1968.             val_negated = !val_negated;
1969.         }
1970.         if (val_negated) {
1971.             if (!setrolefilter(op)) {
1972.                 config_error_add("Unknown negated parameter '%s'", op);
1973.                 return FALSE;
1974.             }
1975.         } else {
1976.             if (duplicate_opt_detection(opts, 1))
1977.                 complain_about_duplicate(opts, 1);
1978.             *opp = op;
1979.             return TRUE;
1980.         }
1981.     }
1982.     return FALSE;
1983. }
1984. 
1985. /* Check if character c is illegal as a menu command key */
1986. boolean
1987. illegal_menu_cmd_key(c)
1988. char c;
1989. {
1990.     if (c == 0 || c == '\r' || c == '\n' || c == '\033'
1991.         || c == ' ' || digit(c) || (letter(c) && c != '@')) {
1992.         config_error_add("Reserved menu command key '%s'", visctrl(c));
1993.         return TRUE;
1994.     } else { /* reject default object class symbols */
1995.         int j;
1996.         for (j = 1; j < MAXOCLASSES; j++)
1997.             if (c == def_oc_syms[j].sym) {
1998.                 config_error_add("Menu command key '%s' is an object class",
1999.                                  visctrl(c));
2000.                 return TRUE;
2001.             }
2002.     }
2003.     return FALSE;
2004. }
2005. 
2006. boolean
2007. parseoptions(opts, tinitial, tfrom_file)
2008. register char *opts;
2009. boolean tinitial, tfrom_file;
2010. {
2011.     char *op;
2012.     unsigned num;
2013.     boolean negated, duplicate;
2014.     int i;
2015.     const char *fullname;
2016.     boolean retval = TRUE;
2017. 
2018.     initial = tinitial;
2019.     from_file = tfrom_file;
2020.     if ((op = index(opts, ',')) != 0) {
2021.         *op++ = 0;
2022.         if (!parseoptions(op, initial, from_file))
2023.             retval = FALSE;
2024.     }
2025.     if (strlen(opts) > BUFSZ / 2) {
2026.         config_error_add("Option too long, max length is %i characters",
2027.                          (BUFSZ / 2));
2028.         return FALSE;
2029.     }
2030. 
2031.     /* strip leading and trailing white space */
2032.     while (isspace((uchar) *opts))
2033.         opts++;
2034.     op = eos(opts);
2035.     while (--op >= opts && isspace((uchar) *op))
2036.         *op = '\0';
2037. 
2038.     if (!*opts) {
2039.         config_error_add("Empty statement");
2040.         return FALSE;
2041.     }
2042.     negated = FALSE;
2043.     while ((*opts == '!') || !strncmpi(opts, "no", 2)) {
2044.         if (*opts == '!')
2045.             opts++;
2046.         else
2047.             opts += 2;
2048.         negated = !negated;
2049.     }
2050. 
2051.     /* variant spelling */
2052. 
2053.     if (match_optname(opts, "colour", 5, FALSE))
2054.         Strcpy(opts, "color"); /* fortunately this isn't longer */
2055. 
2056.     /* special boolean options */
2057. 
2058.     if (match_optname(opts, "female", 3, FALSE)) {
2059.         if (duplicate_opt_detection(opts, 0))
2060.             complain_about_duplicate(opts, 0);
2061.         if (!initial && flags.female == negated) {
2062.             config_error_add("That is not anatomically possible.");
2063.             return FALSE;
2064.         } else
2065.             flags.initgend = flags.female = !negated;
2066.         return retval;
2067.     }
2068. 
2069.     if (match_optname(opts, "male", 4, FALSE)) {
2070.         if (duplicate_opt_detection(opts, 0))
2071.             complain_about_duplicate(opts, 0);
2072.         if (!initial && flags.female != negated) {
2073.             config_error_add("That is not anatomically possible.");
2074.             return FALSE;
2075.         } else
2076.             flags.initgend = flags.female = negated;
2077.         return retval;
2078.     }
2079. 
2080. #if defined(MICRO) && !defined(AMIGA)
2081.     /* included for compatibility with old NetHack.cnf files */
2082.     if (match_optname(opts, "IBM_", 4, FALSE)) {
2083.         iflags.BIOS = !negated;
2084.         return retval;
2085.     }
2086. #endif /* MICRO */
2087. 
2088.     /* compound options */
2089. 
2090.     /* This first batch can be duplicated if their values are negated */
2091. 
2092.     /* align:string */
2093.     fullname = "align";
2094.     if (match_optname(opts, fullname, sizeof "align" - 1, TRUE)) {
2095.         if (parse_role_opts(negated, fullname, opts, &op)) {
2096.             if ((flags.initalign = str2align(op)) == ROLE_NONE) {
2097.                 config_error_add("Unknown %s '%s'", fullname, op);
2098.                 return FALSE;
2099.             }
2100.         } else
2101.             return FALSE;
2102.         return retval;
2103.     }
2104. 
2105.     /* role:string or character:string */
2106.     fullname = "role";
2107.     if (match_optname(opts, fullname, 4, TRUE)
2108.         || match_optname(opts, (fullname = "character"), 4, TRUE)) {
2109.         if (parse_role_opts(negated, fullname, opts, &op)) {
2110.             if ((flags.initrole = str2role(op)) == ROLE_NONE) {
2111.                 config_error_add("Unknown %s '%s'", fullname, op);
2112.                 return FALSE;
2113.             } else /* Backwards compatibility */
2114.                 nmcpy(pl_character, op, PL_NSIZ);
2115.         } else
2116.             return FALSE;
2117.         return retval;
2118.     }
2119. 
2120.     /* race:string */
2121.     fullname = "race";
2122.     if (match_optname(opts, fullname, 4, TRUE)) {
2123.         if (parse_role_opts(negated, fullname, opts, &op)) {
2124.             if ((flags.initrace = str2race(op)) == ROLE_NONE) {
2125.                 config_error_add("Unknown %s '%s'", fullname, op);
2126.                 return FALSE;
2127.             } else /* Backwards compatibility */
2128.                 pl_race = *op;
2129.         } else
2130.             return FALSE;
2131.         return retval;
2132.     }
2133. 
2134.     /* gender:string */
2135.     fullname = "gender";
2136.     if (match_optname(opts, fullname, 4, TRUE)) {
2137.         if (parse_role_opts(negated, fullname, opts, &op)) {
2138.             if ((flags.initgend = str2gend(op)) == ROLE_NONE) {
2139.                 config_error_add("Unknown %s '%s'", fullname, op);
2140.                 return FALSE;
2141.             } else
2142.                 flags.female = flags.initgend;
2143.         } else
2144.             return FALSE;
2145.         return retval;
2146.     }
2147. 
2148.     /* We always check for duplicates on the remaining compound options,
2149.        although individual option processing can choose to complain or not */
2150. 
2151.     duplicate = duplicate_opt_detection(opts, 1); /* 1: check compounds */
2152. 
2153.     fullname = "pettype";
2154.     if (match_optname(opts, fullname, 3, TRUE)) {
2155.         if (duplicate)
2156.             complain_about_duplicate(opts, 1);
2157.         if ((op = string_for_env_opt(fullname, opts, negated))
2158.                                      != empty_optstr) {
2159.             if (negated) {
2160.                 bad_negation(fullname, TRUE);
2161.                 return FALSE;
2162.             } else
2163.                 switch (lowc(*op)) {
2164.                 case 'd': /* dog */
2165.                     preferred_pet = 'd';
2166.                     break;
2167.                 case 'c': /* cat */
2168.                 case 'f': /* feline */
2169.                     preferred_pet = 'c';
2170.                     break;
2171.                 case 'h': /* horse */
2172.                 case 'q': /* quadruped */
2173.                     /* avoids giving "unrecognized type of pet" but
2174.                        pet_type(dog.c) won't actually honor this */
2175.                     preferred_pet = 'h';
2176.                     break;
2177.                 case 'n': /* no pet */
2178.                     preferred_pet = 'n';
2179.                     break;
2180.                 case '*': /* random */
2181.                     preferred_pet = '\0';
2182.                     break;
2183.                 default:
2184.                     config_error_add("Unrecognized pet type '%s'.", op);
2185.                     return FALSE;
2186.                     break;
2187.                 }
2188.         } else if (negated)
2189.             preferred_pet = 'n';
2190.         return retval;
2191.     }
2192. 
2193.     fullname = "catname";
2194.     if (match_optname(opts, fullname, 3, TRUE)) {
2195.         if (duplicate)
2196.             complain_about_duplicate(opts, 1);
2197.         if (negated) {
2198.             bad_negation(fullname, FALSE);
2199.             return FALSE;
2200.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2201.                                             != empty_optstr) {
2202.             nmcpy(catname, op, PL_PSIZ);
2203.         } else
2204.             return FALSE;
2205.         sanitize_name(catname);
2206.         return retval;
2207.     }
2208. 
2209.     fullname = "dogname";
2210.     if (match_optname(opts, fullname, 3, TRUE)) {
2211.         if (duplicate)
2212.             complain_about_duplicate(opts, 1);
2213.         if (negated) {
2214.             bad_negation(fullname, FALSE);
2215.             return FALSE;
2216.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2217.                                             != empty_optstr) {
2218.             nmcpy(dogname, op, PL_PSIZ);
2219.         } else
2220.             return FALSE;
2221.         sanitize_name(dogname);
2222.         return retval;
2223.     }
2224. 
2225.     fullname = "horsename";
2226.     if (match_optname(opts, fullname, 5, TRUE)) {
2227.         if (duplicate)
2228.             complain_about_duplicate(opts, 1);
2229.         if (negated) {
2230.             bad_negation(fullname, FALSE);
2231.             return FALSE;
2232.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2233.                                             != empty_optstr) {
2234.             nmcpy(horsename, op, PL_PSIZ);
2235.         } else
2236.             return FALSE;
2237.         sanitize_name(horsename);
2238.         return retval;
2239.     }
2240. 
2241.     fullname = "mouse_support";
2242.     if (match_optname(opts, fullname, 13, TRUE)) {
2243.         boolean compat = (strlen(opts) <= 13);
2244. 
2245.         if (duplicate)
2246.             complain_about_duplicate(opts, 1);
2247.         op = string_for_opt(opts, (compat || !initial));
2248.         if (op == empty_optstr) {
2249.             if (compat || negated || initial) {
2250.                 /* for backwards compatibility, "mouse_support" without a
2251.                    value is a synonym for mouse_support:1 */
2252.                 iflags.wc_mouse_support = !negated;
2253.             }
2254.         } else if (negated) {
2255.             bad_negation(fullname, TRUE);
2256.             return FALSE;
2257.         } else {
2258.             int mode = atoi(op);
2259. 
2260.             if (mode < 0 || mode > 2 || (mode == 0 && *op != '0')) {
2261.                 config_error_add("Illegal %s parameter '%s'", fullname, op);
2262.                 return FALSE;
2263.             } else { /* mode >= 0 */
2264.                 iflags.wc_mouse_support = mode;
2265.             }
2266.         }
2267.         return retval;
2268.     }
2269. 
2270.     fullname = "number_pad";
2271.     if (match_optname(opts, fullname, 10, TRUE)) {
2272.         boolean compat = (strlen(opts) <= 10);
2273. 
2274.         if (duplicate)
2275.             complain_about_duplicate(opts, 1);
2276.         op = string_for_opt(opts, (compat || !initial));
2277.         if (op == empty_optstr) {
2278.             if (compat || negated || initial) {
2279.                 /* for backwards compatibility, "number_pad" without a
2280.                    value is a synonym for number_pad:1 */
2281.                 iflags.num_pad = !negated;
2282.                 iflags.num_pad_mode = 0;
2283.             }
2284.         } else if (negated) {
2285.             bad_negation(fullname, TRUE);
2286.             return FALSE;
2287.         } else {
2288.             int mode = atoi(op);
2289. 
2290.             if (mode < -1 || mode > 4 || (mode == 0 && *op != '0')) {
2291.                 config_error_add("Illegal %s parameter '%s'", fullname, op);
2292.                 return FALSE;
2293.             } else if (mode <= 0) {
2294.                 iflags.num_pad = FALSE;
2295.                 /* German keyboard; y and z keys swapped */
2296.                 iflags.num_pad_mode = (mode < 0); /* 0 or 1 */
2297.             } else {                              /* mode > 0 */
2298.                 iflags.num_pad = TRUE;
2299.                 iflags.num_pad_mode = 0;
2300.                 /* PC Hack / MSDOS compatibility */
2301.                 if (mode == 2 || mode == 4)
2302.                     iflags.num_pad_mode |= 1;
2303.                 /* phone keypad layout */
2304.                 if (mode == 3 || mode == 4)
2305.                     iflags.num_pad_mode |= 2;
2306.             }
2307.         }
2308.         reset_commands(FALSE);
2309.         number_pad(iflags.num_pad ? 1 : 0);
2310.         return retval;
2311.     }
2312. 
2313.     fullname = "roguesymset";
2314.     if (match_optname(opts, fullname, 7, TRUE)) {
2315.         if (duplicate)
2316.             complain_about_duplicate(opts, 1);
2317.         if (negated) {
2318.             bad_negation(fullname, FALSE);
2319.             return FALSE;
2320.         } else if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
2321.             symset[ROGUESET].name = dupstr(op);
2322.             if (!read_sym_file(ROGUESET)) {
2323.                 clear_symsetentry(ROGUESET, TRUE);
2324.                 config_error_add(
2325.                                "Unable to load symbol set \"%s\" from \"%s\"",
2326.                                  op, SYMBOLS);
2327.                 return FALSE;
2328.             } else {
2329.                 if (!initial && Is_rogue_level(&u.uz))
2330.                     assign_graphics(ROGUESET);
2331.                 need_redraw = TRUE;
2332.             }
2333.         } else
2334.             return FALSE;
2335.         return retval;
2336.     }
2337. 
2338.     fullname = "symset";
2339.     if (match_optname(opts, fullname, 6, TRUE)) {
2340.         if (duplicate)
2341.             complain_about_duplicate(opts, 1);
2342.         if (negated) {
2343.             bad_negation(fullname, FALSE);
2344.             return FALSE;
2345.         } else if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
2346.             symset[PRIMARY].name = dupstr(op);
2347.             if (!read_sym_file(PRIMARY)) {
2348.                 clear_symsetentry(PRIMARY, TRUE);
2349.                 config_error_add(
2350.                                "Unable to load symbol set \"%s\" from \"%s\"",
2351.                                  op, SYMBOLS);
2352.                 return FALSE;
2353.             } else {
2354.                 switch_symbols(symset[PRIMARY].name != (char *) 0);
2355.                 need_redraw = TRUE;
2356.             }
2357.         } else
2358.             return FALSE;
2359.         return retval;
2360.     }
2361. 
2362.     fullname = "runmode";
2363.     if (match_optname(opts, fullname, 4, TRUE)) {
2364.         if (duplicate)
2365.             complain_about_duplicate(opts, 1);
2366.         if (negated) {
2367.             flags.runmode = RUN_TPORT;
2368.         } else if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
2369.             if (!strncmpi(op, "teleport", strlen(op)))
2370.                 flags.runmode = RUN_TPORT;
2371.             else if (!strncmpi(op, "run", strlen(op)))
2372.                 flags.runmode = RUN_LEAP;
2373.             else if (!strncmpi(op, "walk", strlen(op)))
2374.                 flags.runmode = RUN_STEP;
2375.             else if (!strncmpi(op, "crawl", strlen(op)))
2376.                 flags.runmode = RUN_CRAWL;
2377.             else {
2378.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
2379.                 return FALSE;
2380.             }
2381.         } else
2382.             return FALSE;
2383.         return retval;
2384.     }
2385. 
2386.     /* menucolor:"regex_string"=color */
2387.     fullname = "menucolor";
2388.     if (match_optname(opts, fullname, 9, TRUE)) {
2389.         if (negated) {
2390.             bad_negation(fullname, FALSE);
2391.             return FALSE;
2392.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2393.                                             != empty_optstr) {
2394.             if (!add_menu_coloring(op))
2395.                 return FALSE;
2396.         } else
2397.             return FALSE;
2398.         return retval;
2399.     }
2400. 
2401.     fullname = "msghistory";
2402.     if (match_optname(opts, fullname, 3, TRUE)) {
2403.         if (duplicate)
2404.             complain_about_duplicate(opts, 1);
2405.         op = string_for_env_opt(fullname, opts, negated);
2406.         if ((negated && op == empty_optstr)
2407.             || (!negated && op != empty_optstr)) {
2408.             iflags.msg_history = negated ? 0 : atoi(op);
2409.         } else if (negated) {
2410.             bad_negation(fullname, TRUE);
2411.             return FALSE;
2412.         }
2413.         return retval;
2414.     }
2415. 
2416.     fullname = "msg_window";
2417.     /* msg_window:single, combo, full or reversed */
2418.     if (match_optname(opts, fullname, 4, TRUE)) {
2419. /* allow option to be silently ignored by non-tty ports */
2420. #ifdef TTY_GRAPHICS
2421.         int tmp;
2422. 
2423.         if (duplicate)
2424.             complain_about_duplicate(opts, 1);
2425.         if ((op = string_for_opt(opts, TRUE)) == empty_optstr) {
2426.             tmp = negated ? 's' : 'f';
2427.         } else {
2428.             if (negated) {
2429.                 bad_negation(fullname, TRUE);
2430.                 return FALSE;
2431.             }
2432.             tmp = lowc(*op);
2433.         }
2434.         switch (tmp) {
2435.         case 's': /* single message history cycle (default if negated) */
2436.             iflags.prevmsg_window = 's';
2437.             break;
2438.         case 'c': /* combination: two singles, then full page */
2439.             iflags.prevmsg_window = 'c';
2440.             break;
2441.         case 'f': /* full page (default if specified without argument) */
2442.             iflags.prevmsg_window = 'f';
2443.             break;
2444.         case 'r': /* full page (reversed) */
2445.             iflags.prevmsg_window = 'r';
2446.             break;
2447.         default:
2448.             config_error_add("Unknown %s parameter '%s'", fullname, op);
2449.             retval = FALSE;
2450.         }
2451. #endif
2452.         return retval;
2453.     }
2454. 
2455.     /* WINCAP
2456.      * setting font options  */
2457.     fullname = "font";
2458.     if (!strncmpi(opts, fullname, 4)) {
2459.         int opttype = -1;
2460.         char *fontopts = opts + 4;
2461. 
2462.         if (!strncmpi(fontopts, "map", 3) || !strncmpi(fontopts, "_map", 4))
2463.             opttype = MAP_OPTION;
2464.         else if (!strncmpi(fontopts, "message", 7)
2465.                  || !strncmpi(fontopts, "_message", 8))
2466.             opttype = MESSAGE_OPTION;
2467.         else if (!strncmpi(fontopts, "text", 4)
2468.                  || !strncmpi(fontopts, "_text", 5))
2469.             opttype = TEXT_OPTION;
2470.         else if (!strncmpi(fontopts, "menu", 4)
2471.                  || !strncmpi(fontopts, "_menu", 5))
2472.             opttype = MENU_OPTION;
2473.         else if (!strncmpi(fontopts, "status", 6)
2474.                  || !strncmpi(fontopts, "_status", 7))
2475.             opttype = STATUS_OPTION;
2476.         else if (!strncmpi(fontopts, "_size", 5)) {
2477.             if (!strncmpi(fontopts, "_size_map", 8))
2478.                 opttype = MAP_OPTION;
2479.             else if (!strncmpi(fontopts, "_size_message", 12))
2480.                 opttype = MESSAGE_OPTION;
2481.             else if (!strncmpi(fontopts, "_size_text", 9))
2482.                 opttype = TEXT_OPTION;
2483.             else if (!strncmpi(fontopts, "_size_menu", 9))
2484.                 opttype = MENU_OPTION;
2485.             else if (!strncmpi(fontopts, "_size_status", 11))
2486.                 opttype = STATUS_OPTION;
2487.             else {
2488.                 config_error_add("Unknown %s parameter '%s'", fullname, opts);
2489.                 return FALSE;
2490.             }
2491.             if (duplicate)
2492.                 complain_about_duplicate(opts, 1);
2493.             if (opttype > 0 && !negated
2494.                 && (op = string_for_opt(opts, FALSE)) != empty_optstr) {
2495.                 switch (opttype) {
2496.                 case MAP_OPTION:
2497.                     iflags.wc_fontsiz_map = atoi(op);
2498.                     break;
2499.                 case MESSAGE_OPTION:
2500.                     iflags.wc_fontsiz_message = atoi(op);
2501.                     break;
2502.                 case TEXT_OPTION:
2503.                     iflags.wc_fontsiz_text = atoi(op);
2504.                     break;
2505.                 case MENU_OPTION:
2506.                     iflags.wc_fontsiz_menu = atoi(op);
2507.                     break;
2508.                 case STATUS_OPTION:
2509.                     iflags.wc_fontsiz_status = atoi(op);
2510.                     break;
2511.                 }
2512.             }
2513.             return retval;
2514.         } else {
2515.             config_error_add("Unknown %s parameter '%s'", fullname, opts);
2516.             return FALSE;
2517.         }
2518.         if (opttype > 0
2519.             && (op = string_for_opt(opts, FALSE)) != empty_optstr) {
2520.             wc_set_font_name(opttype, op);
2521. #ifdef MAC
2522.             set_font_name(opttype, op);
2523. #endif
2524.             return retval;
2525.         } else if (negated) {
2526.             bad_negation(fullname, TRUE);
2527.             return FALSE;
2528.         }
2529.         return retval;
2530.     }
2531. 
2532. #ifdef CHANGE_COLOR
2533.     if (match_optname(opts, "palette", 3, TRUE)
2534. #ifdef MAC
2535.         || match_optname(opts, "hicolor", 3, TRUE)
2536. #endif
2537.         ) {
2538.         int color_number, color_incr;
2539. 
2540. #ifndef WIN32
2541.         if (duplicate)
2542.             complain_about_duplicate(opts, 1);
2543. #endif
2544. #ifdef MAC
2545.         if (match_optname(opts, "hicolor", 3, TRUE)) {
2546.             if (negated) {
2547.                 bad_negation("hicolor", FALSE);
2548.                 return FALSE;
2549.             }
2550.             color_number = CLR_MAX + 4; /* HARDCODED inverse number */
2551.             color_incr = -1;
2552.         } else
2553. #endif
2554.         {
2555.             if (negated) {
2556.                 bad_negation("palette", FALSE);
2557.                 return FALSE;
2558.             }
2559.             color_number = 0;
2560.             color_incr = 1;
2561.         }
2562. #ifdef WIN32
2563.         op = string_for_opt(opts, TRUE);
2564.         if (op == empty_optstr || !alternative_palette(op)) {
2565.             config_error_add("Error in palette parameter '%s'", op);
2566.             return FALSE;
2567.         }
2568. #else
2569.         if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
2570.             char *pt = op;
2571.             int cnt, tmp, reverse;
2572.             long rgb;
2573. 
2574.             while (*pt && color_number >= 0) {
2575.                 cnt = 3;
2576.                 rgb = 0L;
2577.                 if (*pt == '-') {
2578.                     reverse = 1;
2579.                     pt++;
2580.                 } else {
2581.                     reverse = 0;
2582.                 }
2583.                 while (cnt-- > 0) {
2584.                     if (*pt && *pt != '/') {
2585. #ifdef AMIGA
2586.                         rgb <<= 4;
2587. #else
2588.                         rgb <<= 8;
2589. #endif
2590.                         tmp = *pt++;
2591.                         if (isalpha((uchar) tmp)) {
2592.                             tmp = (tmp + 9) & 0xf; /* Assumes ASCII... */
2593.                         } else {
2594.                             tmp &= 0xf; /* Digits in ASCII too... */
2595.                         }
2596. #ifndef AMIGA
2597.                         /* Add an extra so we fill f -> ff and 0 -> 00 */
2598.                         rgb += tmp << 4;
2599. #endif
2600.                         rgb += tmp;
2601.                     }
2602.                 }
2603.                 if (*pt == '/')
2604.                     pt++;
2605.                 change_color(color_number, rgb, reverse);
2606.                 color_number += color_incr;
2607.             }
2608.         }
2609. #endif /* !WIN32 */
2610.         if (!initial) {
2611.             need_redraw = TRUE;
2612.         }
2613.         return retval;
2614.     }
2615. #endif /* CHANGE_COLOR */
2616. 
2617.     if (match_optname(opts, "fruit", 2, TRUE)) {
2618.         struct fruit *forig = 0;
2619. 
2620.         if (duplicate)
2621.             complain_about_duplicate(opts, 1);
2622.         op = string_for_opt(opts, negated || !initial);
2623.         if (negated) {
2624.             if (op != empty_optstr) {
2625.                 bad_negation("fruit", TRUE);
2626.                 return FALSE;
2627.             }
2628.             op = empty_optstr;
2629.             goto goodfruit;
2630.         }
2631.         if (op == empty_optstr)
2632.             return FALSE;
2633.         /* strip leading/trailing spaces, condense internal ones (3.6.2) */
2634.         mungspaces(op);
2635.         if (!initial) {
2636.             struct fruit *f;
2637.             int fnum = 0;
2638. 
2639.             /* count number of named fruits; if 'op' is found among them,
2640.                then the count doesn't matter because we won't be adding it */
2641.             f = fruit_from_name(op, FALSE, &fnum);
2642.             if (!f) {
2643.                 if (!flags.made_fruit)
2644.                     forig = fruit_from_name(pl_fruit, FALSE, (int *) 0);
2645. 
2646.                 if (!forig && fnum >= 100) {
2647.                     config_error_add(
2648.                              "Doing that so many times isn't very fruitful.");
2649.                     return retval;
2650.                 }
2651.             }
2652.         }
2653.  goodfruit:
2654.         nmcpy(pl_fruit, op, PL_FSIZ);
2655.         sanitize_name(pl_fruit);
2656.         /* OBJ_NAME(objects[SLIME_MOLD]) won't work for this after
2657.            initialization; it gets changed to generic "fruit" */
2658.         if (!*pl_fruit)
2659.             nmcpy(pl_fruit, "slime mold", PL_FSIZ);
2660.         if (!initial) {
2661.             /* if 'forig' is nonNull, we replace it rather than add
2662.                a new fruit; it can only be nonNull if no fruits have
2663.                been created since the previous name was put in place */
2664.             (void) fruitadd(pl_fruit, forig);
2665.             pline("Fruit is now \"%s\".", pl_fruit);
2666.         }
2667.         /* If initial, then initoptions is allowed to do it instead
2668.          * of here (initoptions always has to do it even if there's
2669.          * no fruit option at all.  Also, we don't want people
2670.          * setting multiple fruits in their options.)
2671.          */
2672.         return retval;
2673.     }
2674. 
2675.     fullname = "whatis_coord";
2676.     if (match_optname(opts, fullname, 8, TRUE)) {
2677.         if (duplicate)
2678.             complain_about_duplicate(opts, 1);
2679.         if (negated) {
2680.             iflags.getpos_coords = GPCOORDS_NONE;
2681.             return retval;
2682.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2683.                                             != empty_optstr) {
2684.             static char gpcoords[] = { GPCOORDS_NONE, GPCOORDS_COMPASS,
2685.                                        GPCOORDS_COMFULL, GPCOORDS_MAP,
2686.                                        GPCOORDS_SCREEN, '\0' };
2687.             char c = lowc(*op);
2688. 
2689.             if (c && index(gpcoords, c))
2690.                 iflags.getpos_coords = c;
2691.             else {
2692.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
2693.                 return FALSE;
2694.             }
2695.         } else
2696.             return FALSE;
2697.         return retval;
2698.     }
2699. 
2700.     fullname = "whatis_filter";
2701.     if (match_optname(opts, fullname, 8, TRUE)) {
2702.         if (duplicate)
2703.             complain_about_duplicate(opts, 1);
2704.         if (negated) {
2705.             iflags.getloc_filter = GFILTER_NONE;
2706.             return retval;
2707.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2708.                                             != empty_optstr) {
2709.             char c = lowc(*op);
2710. 
2711.             switch (c) {
2712.             case 'n':
2713.                 iflags.getloc_filter = GFILTER_NONE;
2714.                 break;
2715.             case 'v':
2716.                 iflags.getloc_filter = GFILTER_VIEW;
2717.                 break;
2718.             case 'a':
2719.                 iflags.getloc_filter = GFILTER_AREA;
2720.                 break;
2721.             default: {
2722.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
2723.                 return FALSE;
2724.             }
2725.             }
2726.         } else
2727.             return FALSE;
2728.         return retval;
2729.     }
2730. 
2731.     fullname = "warnings";
2732.     if (match_optname(opts, fullname, 5, TRUE)) {
2733.         if (duplicate)
2734.             complain_about_duplicate(opts, 1);
2735.         if (negated) {
2736.             bad_negation(fullname, FALSE);
2737.             return FALSE;
2738.         }
2739.         return warning_opts(opts, fullname);
2740.     }
2741. 
2742.     /* boulder:symbol */
2743.     fullname = "boulder";
2744.     if (match_optname(opts, fullname, 7, TRUE)) {
2745. #ifdef BACKWARD_COMPAT
2746.         int clash = 0;
2747. 
2748.         if (duplicate)
2749.             complain_about_duplicate(opts, 1);
2750.         if (negated) {
2751.             bad_negation(fullname, FALSE);
2752.             return FALSE;
2753.         }
2754.         /* if ((opts = string_for_env_opt(fullname, opts, FALSE))
2755.                                           == empty_optstr)
2756.          */
2757.         if ((opts = string_for_opt(opts, FALSE)) == empty_optstr)
2758.             return FALSE;
2759.         escapes(opts, opts);
2760.         /* note: dummy monclass #0 has symbol value '\0'; we allow that--
2761.            attempting to set bouldersym to '^@'/'\0' will reset to default */
2762.         if (def_char_to_monclass(opts[0]) != MAXMCLASSES)
2763.             clash = opts[0] ? 1 : 0;
2764.         else if (opts[0] >= '1' && opts[0] < WARNCOUNT + '0')
2765.             clash = 2;
2766.         if (clash) {
2767.             /* symbol chosen matches a used monster or warning
2768.                symbol which is not good - reject it */
2769.             config_error_add(
2770.             "Badoption - boulder symbol '%s' would conflict with a %s symbol",
2771.                              visctrl(opts[0]),
2772.                              (clash == 1) ? "monster" : "warning");
2773.         } else {
2774.             /*
2775.              * Override the default boulder symbol.
2776.              */
2777.             ov_primary_syms[SYM_BOULDER + SYM_OFF_X] = (nhsym) opts[0];
2778.             ov_rogue_syms[SYM_BOULDER + SYM_OFF_X] = (nhsym) opts[0];
2779.             /* for 'initial', update of BOULDER symbol is done in
2780.                initoptions_finish(), after all symset options
2781.                have been processed */
2782.             if (!initial) {
2783.                 nhsym sym = get_othersym(SYM_BOULDER,
2784.                                 Is_rogue_level(&u.uz) ? ROGUESET : PRIMARY);
2785.                 if (sym)
2786.                     showsyms[SYM_BOULDER + SYM_OFF_X] = sym;
2787.                 need_redraw = TRUE;
2788.             }
2789.         }
2790.         return retval;
2791. #else
2792.         config_error_add("'%s' no longer supported; use S_boulder:c instead",
2793.                          fullname);
2794.         return FALSE;
2795. #endif
2796.     }
2797. 
2798.     /* name:string */
2799.     fullname = "name";
2800.     if (match_optname(opts, fullname, 4, TRUE)) {
2801.         if (duplicate)
2802.             complain_about_duplicate(opts, 1);
2803.         if (negated) {
2804.             bad_negation(fullname, FALSE);
2805.             return FALSE;
2806.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2807.                                             != empty_optstr) {
2808.             nmcpy(plname, op, PL_NSIZ);
2809.         } else
2810.             return FALSE;
2811.         return retval;
2812.     }
2813. 
2814.     /* altkeyhandler:string */
2815.     fullname = "altkeyhandler";
2816.     if (match_optname(opts, fullname, 4, TRUE)) {
2817.         if (duplicate)
2818.             complain_about_duplicate(opts, 1);
2819.         if (negated) {
2820.             bad_negation(fullname, FALSE);
2821.             return FALSE;
2822.         } else if ((op = string_for_opt(opts, negated)) != empty_optstr) {
2823. #if defined(WIN32) && defined(TTY_GRAPHICS)
2824.             set_altkeyhandler(op);
2825. #endif
2826.         } else
2827.             return FALSE;
2828.         return retval;
2829.     }
2830. 
2831.     /* WINCAP
2832.      * align_status:[left|top|right|bottom] */
2833.     fullname = "align_status";
2834.     if (match_optname(opts, fullname, sizeof "align_status" - 1, TRUE)) {
2835.         op = string_for_opt(opts, negated);
2836.         if ((op != empty_optstr) && !negated) {
2837.             if (!strncmpi(op, "left", sizeof "left" - 1))
2838.                 iflags.wc_align_status = ALIGN_LEFT;
2839.             else if (!strncmpi(op, "top", sizeof "top" - 1))
2840.                 iflags.wc_align_status = ALIGN_TOP;
2841.             else if (!strncmpi(op, "right", sizeof "right" - 1))
2842.                 iflags.wc_align_status = ALIGN_RIGHT;
2843.             else if (!strncmpi(op, "bottom", sizeof "bottom" - 1))
2844.                 iflags.wc_align_status = ALIGN_BOTTOM;
2845.             else {
2846.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
2847.                 return FALSE;
2848.             }
2849.         } else if (negated) {
2850.             bad_negation(fullname, TRUE);
2851.             return FALSE;
2852.         }
2853.         return retval;
2854.     }
2855. 
2856.     /* WINCAP
2857.      * align_message:[left|top|right|bottom] */
2858.     fullname = "align_message";
2859.     if (match_optname(opts, fullname, sizeof "align_message" - 1, TRUE)) {
2860.         if (duplicate)
2861.             complain_about_duplicate(opts, 1);
2862.         op = string_for_opt(opts, negated);
2863.         if ((op != empty_optstr) && !negated) {
2864.             if (!strncmpi(op, "left", sizeof "left" - 1))
2865.                 iflags.wc_align_message = ALIGN_LEFT;
2866.             else if (!strncmpi(op, "top", sizeof "top" - 1))
2867.                 iflags.wc_align_message = ALIGN_TOP;
2868.             else if (!strncmpi(op, "right", sizeof "right" - 1))
2869.                 iflags.wc_align_message = ALIGN_RIGHT;
2870.             else if (!strncmpi(op, "bottom", sizeof "bottom" - 1))
2871.                 iflags.wc_align_message = ALIGN_BOTTOM;
2872.             else {
2873.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
2874.                 return FALSE;
2875.             }
2876.         } else if (negated) {
2877.             bad_negation(fullname, TRUE);
2878.             return FALSE;
2879.         }
2880.         return retval;
2881.     }
2882. 
2883.     /* the order to list inventory */
2884.     fullname = "packorder";
2885.     if (match_optname(opts, fullname, 4, TRUE)) {
2886.         if (duplicate)
2887.             complain_about_duplicate(opts, 1);
2888.         if (negated) {
2889.             bad_negation(fullname, FALSE);
2890.             return FALSE;
2891.         } else if ((op = string_for_opt(opts, FALSE)) == empty_optstr)
2892.             return FALSE;
2893. 
2894.         if (!change_inv_order(op))
2895.             return FALSE;
2896.         return retval;
2897.     }
2898. 
2899.     /* user can change required response for some prompts (quit, die, hit),
2900.        or add an extra prompt (pray, Remove) that isn't ordinarily there */
2901.     fullname = "paranoid_confirmation";
2902.     if (match_optname(opts, fullname, 8, TRUE)) {
2903.         /* at present we don't complain about duplicates for this
2904.            option, but we do throw away the old settings whenever
2905.            we process a new one [clearing old flags is essential
2906.            for handling default paranoid_confirm:pray sanely] */
2907.         flags.paranoia_bits = 0; /* clear all */
2908.         if (negated) {
2909.             flags.paranoia_bits = 0; /* [now redundant...] */
2910.         } else if ((op = string_for_opt(opts, TRUE)) != empty_optstr) {
2911.             char *pp, buf[BUFSZ];
2912. 
2913.             strncpy(buf, op, sizeof buf - 1);
2914.             buf[sizeof buf - 1] = '\0';
2915.             op = mungspaces(buf);
2916.             for (;;) {
2917.                 /* We're looking to parse
2918.                    "paranoid_confirm:whichone wheretwo whothree"
2919.                    and "paranoid_confirm:" prefix has already
2920.                    been stripped off by the time we get here */
2921.                 pp = index(op, ' ');
2922.                 if (pp)
2923.                     *pp = '\0';
2924.                 /* we aren't matching option names but match_optname()
2925.                    does what we want once we've broken the space
2926.                    delimited aggregate into separate tokens */
2927.                 for (i = 0; i < SIZE(paranoia); ++i) {
2928.                     if (match_optname(op, paranoia[i].argname,
2929.                                       paranoia[i].argMinLen, FALSE)
2930.                         || (paranoia[i].synonym
2931.                             && match_optname(op, paranoia[i].synonym,
2932.                                              paranoia[i].synMinLen, FALSE))) {
2933.                         if (paranoia[i].flagmask)
2934.                             flags.paranoia_bits |= paranoia[i].flagmask;
2935.                         else /* 0 == "none", so clear all */
2936.                             flags.paranoia_bits = 0;
2937.                         break;
2938.                     }
2939.                 }
2940.                 if (i == SIZE(paranoia)) {
2941.                     /* didn't match anything, so arg is bad;
2942.                        any flags already set will stay set */
2943.                     config_error_add("Unknown %s parameter '%s'",
2944.                                      fullname, op);
2945.                     return FALSE;
2946.                 }
2947.                 /* move on to next token */
2948.                 if (pp)
2949.                     op = pp + 1;
2950.                 else
2951.                     break; /* no next token */
2952.             } /* for(;;) */
2953.         } else
2954.             return FALSE;
2955.         return retval;
2956.     }
2957. 
2958.     /* accept deprecated boolean; superseded by paranoid_confirm:pray */
2959.     fullname = "prayconfirm";
2960.     if (match_optname(opts, fullname, 4, FALSE)) {
2961.         if (negated)
2962.             flags.paranoia_bits &= ~PARANOID_PRAY;
2963.         else
2964.             flags.paranoia_bits |= PARANOID_PRAY;
2965.         return retval;
2966.     }
2967. 
2968.     /* maximum burden picked up before prompt (Warren Cheung) */
2969.     fullname = "pickup_burden";
2970.     if (match_optname(opts, fullname, 8, TRUE)) {
2971.         if (duplicate)
2972.             complain_about_duplicate(opts, 1);
2973.         if (negated) {
2974.             bad_negation(fullname, FALSE);
2975.             return FALSE;
2976.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
2977.                                             != empty_optstr) {
2978.             switch (lowc(*op)) {
2979.             case 'u': /* Unencumbered */
2980.                 flags.pickup_burden = UNENCUMBERED;
2981.                 break;
2982.             case 'b': /* Burdened (slight encumbrance) */
2983.                 flags.pickup_burden = SLT_ENCUMBER;
2984.                 break;
2985.             case 's': /* streSsed (moderate encumbrance) */
2986.                 flags.pickup_burden = MOD_ENCUMBER;
2987.                 break;
2988.             case 'n': /* straiNed (heavy encumbrance) */
2989.                 flags.pickup_burden = HVY_ENCUMBER;
2990.                 break;
2991.             case 'o': /* OverTaxed (extreme encumbrance) */
2992.             case 't':
2993.                 flags.pickup_burden = EXT_ENCUMBER;
2994.                 break;
2995.             case 'l': /* overLoaded */
2996.                 flags.pickup_burden = OVERLOADED;
2997.                 break;
2998.             default:
2999.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
3000.                 return FALSE;
3001.             }
3002.         } else
3003.             return FALSE;
3004.         return retval;
3005.     }
3006. 
3007.     /* types of objects to pick up automatically */
3008.     fullname = "pickup_types";
3009.     if (match_optname(opts, fullname, 8, TRUE)) {
3010.         char ocl[MAXOCLASSES + 1], tbuf[MAXOCLASSES + 1],
3011.              qbuf[QBUFSZ], abuf[BUFSZ];
3012.         int oc_sym;
3013.         boolean badopt = FALSE, compat = (strlen(opts) <= 6), use_menu;
3014. 
3015.         if (duplicate)
3016.             complain_about_duplicate(opts, 1);
3017.         oc_to_str(flags.pickup_types, tbuf);
3018.         flags.pickup_types[0] = '\0'; /* all */
3019.         op = string_for_opt(opts, (compat || !initial));
3020.         if (op == empty_optstr) {
3021.             if (compat || negated || initial) {
3022.                 /* for backwards compatibility, "pickup" without a
3023.                    value is a synonym for autopickup of all types
3024.                    (and during initialization, we can't prompt yet) */
3025.                 flags.pickup = !negated;
3026.                 return retval;
3027.             }
3028.             oc_to_str(flags.inv_order, ocl);
3029.             use_menu = TRUE;
3030.             if (flags.menu_style == MENU_TRADITIONAL
3031.                 || flags.menu_style == MENU_COMBINATION) {
3032.                 boolean wasspace;
3033. 
3034.                 use_menu = FALSE;
3035.                 Sprintf(qbuf, "New %s: [%s am] (%s)", fullname, ocl,
3036.                         *tbuf ? tbuf : "all");
3037.                 abuf[0] = '\0';
3038.                 getlin(qbuf, abuf);
3039.                 wasspace = (abuf[0] == ' '); /* before mungspaces */
3040.                 op = mungspaces(abuf);
3041.                 if (wasspace && !abuf[0])
3042.                     ; /* one or more spaces will remove old value */
3043.                 else if (!abuf[0] || abuf[0] == '\033')
3044.                     op = tbuf; /* restore */
3045.                 else if (abuf[0] == 'm')
3046.                     use_menu = TRUE;
3047.                 /* note: abuf[0]=='a' is already handled via clearing the
3048.                    the old value (above) as a default action */
3049.             }
3050.             if (use_menu) {
3051.                 if (wizard && !index(ocl, VENOM_SYM))
3052.                     strkitten(ocl, VENOM_SYM);
3053.                 (void) choose_classes_menu("Autopickup what?", 1, TRUE, ocl,
3054.                                            tbuf);
3055.                 op = tbuf;
3056.             }
3057.         }
3058.         if (negated) {
3059.             bad_negation(fullname, TRUE);
3060.             return FALSE;
3061.         }
3062.         while (*op == ' ')
3063.             op++;
3064.         if (*op != 'a' && *op != 'A') {
3065.             num = 0;
3066.             while (*op) {
3067.                 oc_sym = def_char_to_objclass(*op);
3068.                 /* make sure all are valid obj symbols occurring once */
3069.                 if (oc_sym != MAXOCLASSES
3070.                     && !index(flags.pickup_types, oc_sym)) {
3071.                     flags.pickup_types[num] = (char) oc_sym;
3072.                     flags.pickup_types[++num] = '\0';
3073.                 } else
3074.                     badopt = TRUE;
3075.                 op++;
3076.             }
3077.             if (badopt) {
3078.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
3079.                 return FALSE;
3080.             }
3081.         }
3082.         return retval;
3083.     }
3084. 
3085.     /* pile limit: when walking over objects, number which triggers
3086.        "there are several/many objects here" instead of listing them */
3087.     fullname = "pile_limit";
3088.     if (match_optname(opts, fullname, 4, TRUE)) {
3089.         if (duplicate)
3090.             complain_about_duplicate(opts, 1);
3091.         op = string_for_opt(opts, negated);
3092.         if ((negated && op == empty_optstr)
3093.             || (!negated && op != empty_optstr))
3094.             flags.pile_limit = negated ? 0 : atoi(op);
3095.         else if (negated) {
3096.             bad_negation(fullname, TRUE);
3097.             return FALSE;
3098.         } else /* op == empty_optstr */
3099.             flags.pile_limit = PILE_LIMIT_DFLT;
3100.         /* sanity check */
3101.         if (flags.pile_limit < 0)
3102.             flags.pile_limit = PILE_LIMIT_DFLT;
3103.         return retval;
3104.     }
3105. 
3106.     /* play mode: normal, explore/discovery, or debug/wizard */
3107.     fullname = "playmode";
3108.     if (match_optname(opts, fullname, 4, TRUE)) {
3109.         if (duplicate)
3110.             complain_about_duplicate(opts, 1);
3111.         if (negated)
3112.             bad_negation(fullname, FALSE);
3113.         if (duplicate || negated)
3114.             return FALSE;
3115.         op = string_for_opt(opts, FALSE);
3116.         if (op == empty_optstr)
3117.             return FALSE;
3118.         if (!strncmpi(op, "normal", 6) || !strcmpi(op, "play")) {
3119.             wizard = discover = FALSE;
3120.         } else if (!strncmpi(op, "explore", 6)
3121.                    || !strncmpi(op, "discovery", 6)) {
3122.             wizard = FALSE, discover = TRUE;
3123.         } else if (!strncmpi(op, "debug", 5) || !strncmpi(op, "wizard", 6)) {
3124.             wizard = TRUE, discover = FALSE;
3125.         } else {
3126.             config_error_add("Invalid value for \"%s\":%s", fullname, op);
3127.             return FALSE;
3128.         }
3129.         return retval;
3130.     }
3131. 
3132.     /* WINCAP
3133.      * player_selection: dialog | prompt/prompts/prompting */
3134.     fullname = "player_selection";
3135.     if (match_optname(opts, fullname, sizeof "player_selection" - 1, TRUE)) {
3136.         if (duplicate)
3137.             complain_about_duplicate(opts, 1);
3138.         op = string_for_opt(opts, negated);
3139.         if (op != empty_optstr && !negated) {
3140.             if (!strncmpi(op, "dialog", sizeof "dialog" - 1)) {
3141.                 iflags.wc_player_selection = VIA_DIALOG;
3142.             } else if (!strncmpi(op, "prompt", sizeof "prompt" - 1)) {
3143.                 iflags.wc_player_selection = VIA_PROMPTS;
3144.             } else {
3145.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
3146.                 return FALSE;
3147.             }
3148.         } else if (negated) {
3149.             bad_negation(fullname, TRUE);
3150.             return FALSE;
3151.         }
3152.         return retval;
3153.     }
3154. 
3155.     /* things to disclose at end of game */
3156.     fullname = "disclose";
3157.     if (match_optname(opts, fullname, 7, TRUE)) {
3158.         /*
3159.          * The order that the end_disclose options are stored:
3160.          *      inventory, attribs, vanquished, genocided,
3161.          *      conduct, overview.
3162.          * There is an array in flags:
3163.          *      end_disclose[NUM_DISCLOSURE_OPT];
3164.          * with option settings for the each of the following:
3165.          * iagvc [see disclosure_options in decl.c]:
3166.          * Allowed setting values in that array are:
3167.          *      DISCLOSE_PROMPT_DEFAULT_YES  ask with default answer yes
3168.          *      DISCLOSE_PROMPT_DEFAULT_NO   ask with default answer no
3169.          *      DISCLOSE_YES_WITHOUT_PROMPT  always disclose and don't ask
3170.          *      DISCLOSE_NO_WITHOUT_PROMPT   never disclose and don't ask
3171.          *      DISCLOSE_PROMPT_DEFAULT_SPECIAL  for 'vanquished' only...
3172.          *      DISCLOSE_SPECIAL_WITHOUT_PROMPT  ...to set up sort order.
3173.          *
3174.          * Those setting values can be used in the option
3175.          * string as a prefix to get the desired behaviour.
3176.          *
3177.          * For backward compatibility, no prefix is required,
3178.          * and the presence of a i,a,g,v, or c without a prefix
3179.          * sets the corresponding value to DISCLOSE_YES_WITHOUT_PROMPT.
3180.          */
3181.         int idx, prefix_val;
3182. 
3183.         if (duplicate)
3184.             complain_about_duplicate(opts, 1);
3185.         op = string_for_opt(opts, TRUE);
3186.         if (op != empty_optstr && negated) {
3187.             bad_negation(fullname, TRUE);
3188.             return FALSE;
3189.         }
3190.         /* "disclose" without a value means "all with prompting"
3191.            and negated means "none without prompting" */
3192.         if (op == empty_optstr
3193.             || !strcmpi(op, "all") || !strcmpi(op, "none")) {
3194.             if (op != empty_optstr && !strcmpi(op, "none"))
3195.                 negated = TRUE;
3196.             for (num = 0; num < NUM_DISCLOSURE_OPTIONS; num++)
3197.                 flags.end_disclose[num] = negated
3198.                                               ? DISCLOSE_NO_WITHOUT_PROMPT
3199.                                               : DISCLOSE_PROMPT_DEFAULT_YES;
3200.             return retval;
3201.         }
3202. 
3203.         num = 0;
3204.         prefix_val = -1;
3205.         while (*op && num < sizeof flags.end_disclose - 1) {
3206.             static char valid_settings[] = {
3207.                 DISCLOSE_PROMPT_DEFAULT_YES, DISCLOSE_PROMPT_DEFAULT_NO,
3208.                 DISCLOSE_PROMPT_DEFAULT_SPECIAL,
3209.                 DISCLOSE_YES_WITHOUT_PROMPT, DISCLOSE_NO_WITHOUT_PROMPT,
3210.                 DISCLOSE_SPECIAL_WITHOUT_PROMPT, '\0'
3211.             };
3212.             register char c, *dop;
3213. 
3214.             c = lowc(*op);
3215.             if (c == 'k')
3216.                 c = 'v'; /* killed -> vanquished */
3217.             if (c == 'd')
3218.                 c = 'o'; /* dungeon -> overview */
3219.             dop = index(disclosure_options, c);
3220.             if (dop) {
3221.                 idx = (int) (dop - disclosure_options);
3222.                 if (idx < 0 || idx > NUM_DISCLOSURE_OPTIONS - 1) {
3223.                     impossible("bad disclosure index %d %c", idx, c);
3224.                     continue;
3225.                 }
3226.                 if (prefix_val != -1) {
3227.                     if (*dop != 'v') {
3228.                         if (prefix_val == DISCLOSE_PROMPT_DEFAULT_SPECIAL)
3229.                             prefix_val = DISCLOSE_PROMPT_DEFAULT_YES;
3230.                         if (prefix_val == DISCLOSE_SPECIAL_WITHOUT_PROMPT)
3231.                             prefix_val = DISCLOSE_YES_WITHOUT_PROMPT;
3232.                     }
3233.                     flags.end_disclose[idx] = prefix_val;
3234.                     prefix_val = -1;
3235.                 } else
3236.                     flags.end_disclose[idx] = DISCLOSE_YES_WITHOUT_PROMPT;
3237.             } else if (index(valid_settings, c)) {
3238.                 prefix_val = c;
3239.             } else if (c == ' ') {
3240.                 ; /* do nothing */
3241.             } else {
3242.                 config_error_add("Unknown %s parameter '%c'", fullname, *op);
3243.                 return FALSE;
3244.             }
3245.             op++;
3246.         }
3247.         return retval;
3248.     }
3249. 
3250.     /* scores:5t[op] 5a[round] o[wn] */
3251.     fullname = "scores";
3252.     if (match_optname(opts, fullname, 4, TRUE)) {
3253.         if (duplicate)
3254.             complain_about_duplicate(opts, 1);
3255.         if (negated) {
3256.             bad_negation(fullname, FALSE);
3257.             return FALSE;
3258.         }
3259.         if ((op = string_for_opt(opts, FALSE)) == empty_optstr)
3260.             return FALSE;
3261. 
3262.         while (*op) {
3263.             int inum = 1;
3264. 
3265.             if (digit(*op)) {
3266.                 inum = atoi(op);
3267.                 while (digit(*op))
3268.                     op++;
3269.             } else if (*op == '!') {
3270.                 negated = !negated;
3271.                 op++;
3272.             }
3273.             while (*op == ' ')
3274.                 op++;
3275. 
3276.             switch (*op) {
3277.             case 't':
3278.             case 'T':
3279.                 flags.end_top = inum;
3280.                 break;
3281.             case 'a':
3282.             case 'A':
3283.                 flags.end_around = inum;
3284.                 break;
3285.             case 'o':
3286.             case 'O':
3287.                 flags.end_own = !negated;
3288.                 break;
3289.             default:
3290.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
3291.                 return FALSE;
3292.             }
3293.             /* "3a" is sufficient but accept "3around" (or "3abracadabra") */
3294.             while (letter(*op))
3295.                 op++;
3296.             /* t, a, and o can be separated by space(s) or slash or both */
3297.             while (*op == ' ')
3298.                 op++;
3299.             if (*op == '/')
3300.                 op++;
3301.         }
3302.         return retval;
3303.     }
3304. 
3305.     fullname = "sortloot";
3306.     if (match_optname(opts, fullname, 4, TRUE)) {
3307.         op = string_for_env_opt(fullname, opts, FALSE);
3308.         if (op != empty_optstr) {
3309.             char c = lowc(*op);
3310. 
3311.             switch (c) {
3312.             case 'n': /* none */
3313.             case 'l': /* loot (pickup) */
3314.             case 'f': /* full (pickup + invent) */
3315.                 flags.sortloot = c;
3316.                 break;
3317.             default:
3318.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
3319.                 return FALSE;
3320.             }
3321.         } else
3322.             return FALSE;
3323.         return retval;
3324.     }
3325. 
3326.     fullname = "suppress_alert";
3327.     if (match_optname(opts, fullname, 4, TRUE)) {
3328.         if (duplicate)
3329.             complain_about_duplicate(opts, 1);
3330.         op = string_for_opt(opts, negated);
3331.         if (negated) {
3332.             bad_negation(fullname, FALSE);
3333.             return FALSE;
3334.         } else if (op != empty_optstr)
3335.             (void) feature_alert_opts(op, fullname);
3336.         return retval;
3337.     }
3338. 
3339. #ifdef VIDEOSHADES
3340.     /* videocolors:string */
3341.     fullname = "videocolors";
3342.     if (match_optname(opts, fullname, 6, TRUE)
3343.         || match_optname(opts, "videocolours", 10, TRUE)) {
3344.         if (duplicate)
3345.             complain_about_duplicate(opts, 1);
3346.         if (negated) {
3347.             bad_negation(fullname, FALSE);
3348.             return FALSE;
3349.         } else if ((opts = string_for_env_opt(fullname, opts, FALSE))
3350.                                               == empty_optstr) {
3351.             return FALSE;
3352.         }
3353.         if (!assign_videocolors(opts)) {
3354.             config_error_add("Unknown error handling '%s'", fullname);
3355.             return FALSE;
3356.         }
3357.         return retval;
3358.     }
3359.     /* videoshades:string */
3360.     fullname = "videoshades";
3361.     if (match_optname(opts, fullname, 6, TRUE)) {
3362.         if (duplicate)
3363.             complain_about_duplicate(opts, 1);
3364.         if (negated) {
3365.             bad_negation(fullname, FALSE);
3366.             return FALSE;
3367.         } else if ((opts = string_for_env_opt(fullname, opts, FALSE))
3368.                                               == empty_optstr) {
3369.             return FALSE;
3370.         }
3371.         if (!assign_videoshades(opts)) {
3372.             config_error_add("Unknown error handling '%s'", fullname);
3373.             return FALSE;
3374.         }
3375.         return retval;
3376.     }
3377. #endif /* VIDEOSHADES */
3378. 
3379. #ifdef MSDOS
3380. #ifdef NO_TERMS
3381.     /* video:string -- must be after longer tests */
3382.     fullname = "video";
3383.     if (match_optname(opts, fullname, 5, TRUE)) {
3384.         if (duplicate)
3385.             complain_about_duplicate(opts, 1);
3386.         if (negated) {
3387.             bad_negation(fullname, FALSE);
3388.             return FALSE;
3389.         } else if ((opts = string_for_env_opt(fullname, opts, FALSE))
3390.                                               == empty_optstr) {
3391.             return FALSE;
3392.         }
3393.         if (!assign_video(opts)) {
3394.             config_error_add("Unknown error handling '%s'", fullname);
3395.             return FALSE;
3396.         }
3397.         return retval;
3398.     }
3399. #endif /* NO_TERMS */
3400.     /* soundcard:string -- careful not to match boolean 'sound' */
3401.     fullname = "soundcard";
3402.     if (match_optname(opts, fullname, 6, TRUE)) {
3403.         if (duplicate)
3404.             complain_about_duplicate(opts, 1);
3405.         if (negated) {
3406.             bad_negation(fullname, FALSE);
3407.             return FALSE;
3408.         } else if ((opts = string_for_env_opt(fullname, opts, FALSE))
3409.                                               == empty_optstr) {
3410.             return FALSE;
3411.         }
3412.         if (!assign_soundcard(opts)) {
3413.             config_error_add("Unknown error handling '%s'", fullname);
3414.             return FALSE;
3415.         }
3416.         return retval;
3417.     }
3418. #endif /* MSDOS */
3419. 
3420.     /* WINCAP
3421.      *
3422.      *  map_mode:[tiles|ascii4x6|ascii6x8|ascii8x8|ascii16x8|ascii7x12
3423.      *            |ascii8x12|ascii16x12|ascii12x16|ascii10x18|fit_to_screen
3424.      *            |ascii_fit_to_screen|tiles_fit_to_screen]
3425.      */
3426.     fullname = "map_mode";
3427.     if (match_optname(opts, fullname, sizeof "map_mode" - 1, TRUE)) {
3428.         if (duplicate)
3429.             complain_about_duplicate(opts, 1);
3430.         op = string_for_opt(opts, negated);
3431.         if (op != empty_optstr && !negated) {
3432.             if (!strcmpi(op, "tiles"))
3433.                 iflags.wc_map_mode = MAP_MODE_TILES;
3434.             else if (!strncmpi(op, "ascii4x6", sizeof "ascii4x6" - 1))
3435.                 iflags.wc_map_mode = MAP_MODE_ASCII4x6;
3436.             else if (!strncmpi(op, "ascii6x8", sizeof "ascii6x8" - 1))
3437.                 iflags.wc_map_mode = MAP_MODE_ASCII6x8;
3438.             else if (!strncmpi(op, "ascii8x8", sizeof "ascii8x8" - 1))
3439.                 iflags.wc_map_mode = MAP_MODE_ASCII8x8;
3440.             else if (!strncmpi(op, "ascii16x8", sizeof "ascii16x8" - 1))
3441.                 iflags.wc_map_mode = MAP_MODE_ASCII16x8;
3442.             else if (!strncmpi(op, "ascii7x12", sizeof "ascii7x12" - 1))
3443.                 iflags.wc_map_mode = MAP_MODE_ASCII7x12;
3444.             else if (!strncmpi(op, "ascii8x12", sizeof "ascii8x12" - 1))
3445.                 iflags.wc_map_mode = MAP_MODE_ASCII8x12;
3446.             else if (!strncmpi(op, "ascii16x12", sizeof "ascii16x12" - 1))
3447.                 iflags.wc_map_mode = MAP_MODE_ASCII16x12;
3448.             else if (!strncmpi(op, "ascii12x16", sizeof "ascii12x16" - 1))
3449.                 iflags.wc_map_mode = MAP_MODE_ASCII12x16;
3450.             else if (!strncmpi(op, "ascii10x18", sizeof "ascii10x18" - 1))
3451.                 iflags.wc_map_mode = MAP_MODE_ASCII10x18;
3452.             else if (!strncmpi(op, "fit_to_screen",
3453.                                sizeof "fit_to_screen" - 1))
3454.                 iflags.wc_map_mode = MAP_MODE_ASCII_FIT_TO_SCREEN;
3455.             else if (!strncmpi(op, "ascii_fit_to_screen",
3456.                                sizeof "ascii_fit_to_screen" - 1))
3457.                 iflags.wc_map_mode = MAP_MODE_ASCII_FIT_TO_SCREEN;
3458.             else if (!strncmpi(op, "tiles_fit_to_screen",
3459.                                sizeof "tiles_fit_to_screen" - 1))
3460.                 iflags.wc_map_mode = MAP_MODE_TILES_FIT_TO_SCREEN;
3461.             else {
3462.                 config_error_add("Unknown %s parameter '%s'", fullname, op);
3463.                 return FALSE;
3464.             }
3465.         } else if (negated) {
3466.             bad_negation(fullname, TRUE);
3467.             return FALSE;
3468.         }
3469.         return retval;
3470.     }
3471. 
3472.     /* WINCAP
3473.      * scroll_amount:nn */
3474.     fullname = "scroll_amount";
3475.     if (match_optname(opts, fullname, sizeof "scroll_amount" - 1, TRUE)) {
3476.         if (duplicate)
3477.             complain_about_duplicate(opts, 1);
3478.         op = string_for_opt(opts, negated);
3479.         if ((negated && op == empty_optstr)
3480.             || (!negated && op != empty_optstr)) {
3481.             iflags.wc_scroll_amount = negated ? 1 : atoi(op);
3482.         } else if (negated) {
3483.             bad_negation(fullname, TRUE);
3484.             return FALSE;
3485.         }
3486.         return retval;
3487.     }
3488. 
3489.     /* WINCAP
3490.      * scroll_margin:nn */
3491.     fullname = "scroll_margin";
3492.     if (match_optname(opts, fullname, sizeof "scroll_margin" - 1, TRUE)) {
3493.         if (duplicate)
3494.             complain_about_duplicate(opts, 1);
3495.         op = string_for_opt(opts, negated);
3496.         if ((negated && op == empty_optstr)
3497.             || (!negated && op != empty_optstr)) {
3498.             iflags.wc_scroll_margin = negated ? 5 : atoi(op);
3499.         } else if (negated) {
3500.             bad_negation(fullname, TRUE);
3501.             return FALSE;
3502.         }
3503.         return retval;
3504.     }
3505. 
3506.     fullname = "subkeyvalue";
3507.     if (match_optname(opts, fullname, 5, TRUE)) {
3508.         /* no duplicate complaint here */
3509.         if (negated) {
3510.             bad_negation(fullname, FALSE);
3511.             return FALSE;
3512. #if defined(WIN32)
3513.         } else {
3514.             op = string_for_opt(opts, 0);
3515.             if (op == empty_optstr)
3516.                 return FALSE;
3517. #ifdef TTY_GRAPHICS
3518.             map_subkeyvalue(op);
3519. #endif
3520. #endif
3521.         }
3522.         return retval;
3523.     }
3524. 
3525.     /* WINCAP
3526.      * tile_width:nn */
3527.     fullname = "tile_width";
3528.     if (match_optname(opts, fullname, sizeof "tile_width" - 1, TRUE)) {
3529.         if (duplicate)
3530.             complain_about_duplicate(opts, 1);
3531.         op = string_for_opt(opts, negated);
3532.         if ((negated && op == empty_optstr)
3533.             || (!negated && op != empty_optstr)) {
3534.             iflags.wc_tile_width = negated ? 0 : atoi(op);
3535.         } else if (negated) {
3536.             bad_negation(fullname, TRUE);
3537.             return FALSE;
3538.         }
3539.         return retval;
3540.     }
3541.     /* WINCAP
3542.      * tile_file:name */
3543.     fullname = "tile_file";
3544.     if (match_optname(opts, fullname, sizeof "tile_file" - 1, TRUE)) {
3545.         if (duplicate)
3546.             complain_about_duplicate(opts, 1);
3547.         if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
3548.             if (iflags.wc_tile_file)
3549.                 free(iflags.wc_tile_file);
3550.             iflags.wc_tile_file = dupstr(op);
3551.         } else
3552.             return FALSE;
3553.         return retval;
3554.     }
3555.     /* WINCAP
3556.      * tile_height:nn */
3557.     fullname = "tile_height";
3558.     if (match_optname(opts, fullname, sizeof "tile_height" - 1, TRUE)) {
3559.         if (duplicate)
3560.             complain_about_duplicate(opts, 1);
3561.         op = string_for_opt(opts, negated);
3562.         if ((negated && op == empty_optstr)
3563.             || (!negated && op != empty_optstr)) {
3564.             iflags.wc_tile_height = negated ? 0 : atoi(op);
3565.         } else if (negated) {
3566.             bad_negation(fullname, TRUE);
3567.             return FALSE;
3568.         }
3569.         return retval;
3570.     }
3571. 
3572.     /* WINCAP
3573.      * vary_msgcount:nn */
3574.     fullname = "vary_msgcount";
3575.     if (match_optname(opts, fullname, sizeof "vary_msgcount" - 1, TRUE)) {
3576.         if (duplicate)
3577.             complain_about_duplicate(opts, 1);
3578.         op = string_for_opt(opts, negated);
3579.         if ((negated && op == empty_optstr)
3580.             || (!negated && op != empty_optstr)) {
3581.             iflags.wc_vary_msgcount = negated ? 0 : atoi(op);
3582.         } else if (negated) {
3583.             bad_negation(fullname, TRUE);
3584.             return FALSE;
3585.         }
3586.         return retval;
3587.     }
3588. 
3589.     /*
3590.      * windowtype:  option to choose the interface for binaries built
3591.      * with support for more than one interface (tty + X11, for instance).
3592.      *
3593.      * Ideally, 'windowtype' should be processed first, because it
3594.      * causes the wc_ and wc2_ flags to be set up.
3595.      * For user, making it be first in a config file is trivial, use
3596.      * OPTIONS=windowtype:Foo
3597.      * as the first non-comment line of the file.
3598.      * Making it first in NETHACKOPTIONS requires it to be at the _end_
3599.      * because comma-separated option strings are processed from right
3600.      * to left.
3601.      */
3602.     fullname = "windowtype";
3603.     if (match_optname(opts, fullname, 3, TRUE)) {
3604.         if (iflags.windowtype_locked)
3605.             return retval;
3606.         if (duplicate)
3607.             complain_about_duplicate(opts, 1);
3608.         if (negated) {
3609.             bad_negation(fullname, FALSE);
3610.             return FALSE;
3611.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
3612.                                             != empty_optstr) {
3613.             if (!iflags.windowtype_deferred) {
3614.                 char buf[WINTYPELEN];
3615. 
3616.                 nmcpy(buf, op, WINTYPELEN);
3617.                 choose_windows(buf);
3618.             } else {
3619.                 nmcpy(chosen_windowtype, op, WINTYPELEN);
3620.             }
3621.         } else
3622.             return FALSE;
3623.         return retval;
3624.     }
3625. 
3626. #ifdef WINCHAIN
3627.     fullname = "windowchain";
3628.     if (match_optname(opts, fullname, 3, TRUE)) {
3629.         if (negated) {
3630.             bad_negation(fullname, FALSE);
3631.             return FALSE;
3632.         } else if ((op = string_for_env_opt(fullname, opts, FALSE))
3633.                                             != empty_optstr) {
3634.             char buf[WINTYPELEN];
3635. 
3636.             nmcpy(buf, op, WINTYPELEN);
3637.             addto_windowchain(buf);
3638.         } else
3639.             return FALSE;
3640.         return retval;
3641.     }
3642. #endif
3643. 
3644.     /* WINCAP
3645.      * setting window colors
3646.      * syntax: windowcolors=menu foregrnd/backgrnd text foregrnd/backgrnd
3647.      */
3648.     fullname = "windowcolors";
3649.     if (match_optname(opts, fullname, 7, TRUE)) {
3650.         if (duplicate)
3651.             complain_about_duplicate(opts, 1);
3652.         if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
3653.             if (!wc_set_window_colors(op)) {
3654.                 config_error_add("Could not set %s '%s'", fullname, op);
3655.                 return FALSE;
3656.             }
3657.         } else if (negated) {
3658.             bad_negation(fullname, TRUE);
3659.             return FALSE;
3660.         }
3661.         return retval;
3662.     }
3663. 
3664. #ifdef CURSES_GRAPHICS
3665.     /* WINCAP2
3666.      * term_cols:amount or term_rows:amount */
3667.     fullname = "term_cols";
3668.     if (match_optname(opts, fullname, 8, TRUE)
3669.         /* alternate spelling */
3670.         || match_optname(opts, "term_columns", 9, TRUE)
3671.         /* different option but identical handlng */
3672.         || (fullname = "term_rows", match_optname(opts, fullname, 8, TRUE))) {
3673.         long ltmp;
3674. 
3675.         if ((op = string_for_opt(opts, negated)) != empty_optstr) {
3676.             ltmp = atol(op);
3677.             if (negated) {
3678.                 bad_negation(fullname, FALSE);
3679.                 retval = FALSE;
3680. 
3681.             /* just checks atol() sanity, not logical window size sanity */
3682.             } else if (ltmp <= 0L || ltmp >= (long) LARGEST_INT) {
3683.                 config_error_add("Invalid %s: %ld", fullname, ltmp);
3684.                 retval = FALSE;
3685. 
3686.             } else {
3687.                 if (!strcmp(fullname, "term_rows"))
3688.                     iflags.wc2_term_rows = (int) ltmp;
3689.                 else /* !strcmp(fullname, "term_cols") */
3690.                     iflags.wc2_term_cols = (int) ltmp;
3691.             }
3692.         }
3693.         return retval;
3694.     }
3695. 
3696.     /* WINCAP2
3697.      * petattr:string */
3698.     fullname = "petattr";
3699.     if (match_optname(opts, fullname, sizeof "petattr" - 1, TRUE)) {
3700.         op = string_for_opt(opts, negated);
3701.         if (op != empty_optstr && negated) {
3702.             bad_negation(fullname, TRUE);
3703.             retval = FALSE;
3704.         } else if (op != empty_optstr) {
3705. #ifdef CURSES_GRAPHICS
3706.             int itmp = curses_read_attrs(op);
3707. 
3708.             if (itmp == -1) {
3709.                 config_error_add("Unknown %s parameter '%s'", fullname, opts);
3710.                 retval = FALSE;
3711.             } else
3712.                 iflags.wc2_petattr = itmp;
3713. #else
3714.             /* non-curses windowports will not use this flag anyway
3715.              * but the above will not compile if we don't have curses.
3716.              * Just set it to a sensible default: */
3717.             iflags.wc2_petattr = ATR_INVERSE;
3718. #endif
3719.         } else if (negated) {
3720.             iflags.wc2_petattr = ATR_NONE;
3721.         }
3722.         if (retval) {
3723.             iflags.hilite_pet = (iflags.wc2_petattr != ATR_NONE);
3724.             if (!initial)
3725.                 need_redraw = TRUE;
3726.         }
3727.         return retval;
3728.     }
3729. 
3730.     /* WINCAP2
3731.      * windowborders:n */
3732.     fullname = "windowborders";
3733.     if (match_optname(opts, fullname, 10, TRUE)) {
3734.         op = string_for_opt(opts, negated);
3735.         if (negated && op != empty_optstr) {
3736.             bad_negation(fullname, TRUE);
3737.             retval = FALSE;
3738.         } else {
3739.             int itmp;
3740. 
3741.             if (negated)
3742.                 itmp = 0; /* Off */
3743.             else if (op == empty_optstr)
3744.                 itmp = 1; /* On */
3745.             else    /* Value supplied; expect 0 (off), 1 (on), or 2 (auto) */
3746.                 itmp = atoi(op);
3747. 
3748.             if (itmp < 0 || itmp > 2) {
3749.                 config_error_add("Invalid %s (should be 0, 1, or 2): %s",
3750.                                  fullname, opts);
3751.                 retval = FALSE;
3752.             } else {
3753.                 iflags.wc2_windowborders = itmp;
3754.             }
3755.         }
3756.         return retval;
3757.     }
3758. #endif /* CURSES_GRAPHICS */
3759. 
3760.     /* WINCAP2
3761.      * statuslines:n */
3762.     fullname = "statuslines";
3763.     if (match_optname(opts, fullname, 11, TRUE)) {
3764.         int itmp = 0;
3765. 
3766.         op = string_for_opt(opts, negated);
3767.         if (negated) {
3768.             bad_negation(fullname, TRUE);
3769.             itmp = 2;
3770.             retval = FALSE;
3771.         } else if (op != empty_optstr) {
3772.             itmp = atoi(op);
3773.         }
3774.         if (itmp < 2 || itmp > 3) {
3775.             config_error_add("'%s' requires a value of 2 or 3", fullname);
3776.             retval = FALSE;
3777.         } else {
3778.             iflags.wc2_statuslines = itmp;
3779.             if (!initial)
3780.                 need_redraw = TRUE;
3781.         }
3782.         return retval;
3783.     }
3784. 
3785.     /* menustyle:traditional or combination or full or partial */
3786.     fullname = "menustyle";
3787.     if (match_optname(opts, fullname, 4, TRUE)) {
3788.         int tmp;
3789.         boolean val_required = (strlen(opts) > 5 && !negated);
3790. 
3791.         if (duplicate)
3792.             complain_about_duplicate(opts, 1);
3793.         if ((op = string_for_opt(opts, !val_required)) == empty_optstr) {
3794.             if (val_required)
3795.                 return FALSE; /* string_for_opt gave feedback */
3796.             tmp = negated ? 'n' : 'f';
3797.         } else {
3798.             tmp = lowc(*op);
3799.         }
3800.         switch (tmp) {
3801.         case 'n': /* none */
3802.         case 't': /* traditional: prompt for class(es) by symbol,
3803.                      prompt for each item within class(es) one at a time */
3804.             flags.menu_style = MENU_TRADITIONAL;
3805.             break;
3806.         case 'c': /* combination: prompt for class(es) by symbol,
3807.                      choose items within selected class(es) by menu */
3808.             flags.menu_style = MENU_COMBINATION;
3809.             break;
3810.         case 'f': /* full: choose class(es) by first menu,
3811.                      choose items within selected class(es) by second menu */
3812.             flags.menu_style = MENU_FULL;
3813.             break;
3814.         case 'p': /* partial: skip class filtering,
3815.                      choose items among all classes by menu */
3816.             flags.menu_style = MENU_PARTIAL;
3817.             break;
3818.         default:
3819.             config_error_add("Unknown %s parameter '%s'", fullname, op);
3820.             return FALSE;
3821.         }
3822.         return retval;
3823.     }
3824. 
3825.     fullname = "menu_headings";
3826.     if (match_optname(opts, fullname, 12, TRUE)) {
3827.         int tmpattr;
3828. 
3829.         if (duplicate)
3830.             complain_about_duplicate(opts, 1);
3831.         if (negated) {
3832.             bad_negation(fullname, FALSE);
3833.             return FALSE;
3834.         } else if ((opts = string_for_env_opt(fullname, opts, FALSE))
3835.                                               == empty_optstr) {
3836.             return FALSE;
3837.         }
3838.         tmpattr = match_str2attr(opts, TRUE);
3839.         if (tmpattr == -1)
3840.             return FALSE;
3841.         else
3842.             iflags.menu_headings = tmpattr;
3843.         return retval;
3844.     }
3845. 
3846.     /* check for menu command mapping */
3847.     for (i = 0; i < SIZE(default_menu_cmd_info); i++) {
3848.         fullname = default_menu_cmd_info[i].name;
3849.         if (duplicate)
3850.             complain_about_duplicate(opts, 1);
3851.         if (match_optname(opts, fullname, (int) strlen(fullname), TRUE)) {
3852.             if (negated) {
3853.                 bad_negation(fullname, FALSE);
3854.                 return FALSE;
3855.             } else if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
3856.                 char c, op_buf[BUFSZ];
3857. 
3858.                 escapes(op, op_buf);
3859.                 c = *op_buf;
3860. 
3861.                 if (illegal_menu_cmd_key(c))
3862.                     return FALSE;
3863. 
3864.                 add_menu_cmd_alias(c, default_menu_cmd_info[i].cmd);
3865.             }
3866.             return retval;
3867.         }
3868.     }
3869. 
3870.     /* hilite fields in status prompt */
3871.     fullname = "hilite_status";
3872.     if (match_optname(opts, fullname, 13, TRUE)) {
3873. #ifdef STATUS_HILITES
3874.         if (duplicate)
3875.             complain_about_duplicate(opts, 1);
3876.         op = string_for_opt(opts, TRUE);
3877.         if (op != empty_optstr && negated) {
3878.             clear_status_hilites();
3879.             return retval;
3880.         } else if (op == empty_optstr) {
3881.             config_error_add("Value is mandatory for hilite_status");
3882.             return FALSE;
3883.         }
3884.         if (!parse_status_hl1(op, tfrom_file))
3885.             return FALSE;
3886.         return retval;
3887. #else
3888.         config_error_add("'%s' is not supported", fullname);
3889.         return FALSE;
3890. #endif
3891.     }
3892. 
3893.     /* control over whether highlights should be displayed, and for how long */
3894.     fullname = "statushilites";
3895.     if (match_optname(opts, fullname, 9, TRUE)) {
3896. #ifdef STATUS_HILITES
3897.         if (negated) {
3898.             iflags.hilite_delta = 0L;
3899.         } else {
3900.             op = string_for_opt(opts, TRUE);
3901.             iflags.hilite_delta = (op == empty_optstr || !*op) ? 3L : atol(op);
3902.             if (iflags.hilite_delta < 0L)
3903.                 iflags.hilite_delta = 1L;
3904.         }
3905.         if (!tfrom_file)
3906.             reset_status_hilites();
3907.         return retval;
3908. #else
3909.         config_error_add("'%s' is not supported", fullname);
3910.         return FALSE;
3911. #endif
3912.     }
3913. 
3914.     fullname = "DECgraphics";
3915.     if (match_optname(opts, fullname, 3, TRUE)) {
3916. #ifdef BACKWARD_COMPAT
3917.         boolean badflag = FALSE;
3918. 
3919.         if (duplicate)
3920.             complain_about_duplicate(opts, 1);
3921.         if (!negated) {
3922.             /* There is no rogue level DECgraphics-specific set */
3923.             if (symset[PRIMARY].name) {
3924.                 badflag = TRUE;
3925.             } else {
3926.                 symset[PRIMARY].name = dupstr(fullname);
3927.                 if (!read_sym_file(PRIMARY)) {
3928.                     badflag = TRUE;
3929.                     clear_symsetentry(PRIMARY, TRUE);
3930.                 } else
3931.                     switch_symbols(TRUE);
3932.             }
3933.             if (badflag) {
3934.                 config_error_add("Failure to load symbol set %s.", fullname);
3935.                 return FALSE;
3936.             }
3937.         }
3938.         return retval;
3939. #else
3940.         config_error_add("'%s' no longer supported; use 'symset:%s' instead",
3941.                          fullname, fullname);
3942.         return FALSE;
3943. #endif
3944.     } /* "DECgraphics" */
3945. 
3946.     fullname = "IBMgraphics";
3947.     if (match_optname(opts, fullname, 3, TRUE)) {
3948. #ifdef BACKWARD_COMPAT
3949.         const char *sym_name = fullname;
3950.         boolean badflag = FALSE;
3951. 
3952.         if (duplicate)
3953.             complain_about_duplicate(opts, 1);
3954.         if (!negated) {
3955.             for (i = 0; i < NUM_GRAPHICS; ++i) {
3956.                 if (symset[i].name) {
3957.                     badflag = TRUE;
3958.                 } else {
3959.                     if (i == ROGUESET)
3960.                         sym_name = "RogueIBM";
3961.                     symset[i].name = dupstr(sym_name);
3962.                     if (!read_sym_file(i)) {
3963.                         badflag = TRUE;
3964.                         clear_symsetentry(i, TRUE);
3965.                         break;
3966.                     }
3967.                 }
3968.             }
3969.             if (badflag) {
3970.                 config_error_add("Failure to load symbol set %s.", sym_name);
3971.                 return FALSE;
3972.             } else {
3973.                 switch_symbols(TRUE);
3974.                 if (!initial && Is_rogue_level(&u.uz))
3975.                     assign_graphics(ROGUESET);
3976.             }
3977.         }
3978.         return retval;
3979. #else
3980.         config_error_add("'%s' no longer supported; use 'symset:%s' instead",
3981.                          fullname, fullname);
3982.         return FALSE;
3983. #endif
3984.     } /* "IBMgraphics" */
3985. 
3986.     fullname = "MACgraphics";
3987.     if (match_optname(opts, fullname, 3, TRUE)) {
3988. #if defined(MAC_GRAPHICS_ENV) && defined(BACKWARD_COMPAT)
3989.         boolean badflag = FALSE;
3990. 
3991.         if (duplicate)
3992.             complain_about_duplicate(opts, 1);
3993.         if (!negated) {
3994.             if (symset[PRIMARY].name) {
3995.                 badflag = TRUE;
3996.             } else {
3997.                 symset[PRIMARY].name = dupstr(fullname);
3998.                 if (!read_sym_file(PRIMARY)) {
3999.                     badflag = TRUE;
4000.                     clear_symsetentry(PRIMARY, TRUE);
4001.                 }
4002.             }
4003.             if (badflag) {
4004.                 config_error_add("Failure to load symbol set %s.", fullname);
4005.                 return FALSE;
4006.             } else {
4007.                 switch_symbols(TRUE);
4008.                 if (!initial && Is_rogue_level(&u.uz))
4009.                     assign_graphics(ROGUESET);
4010.             }
4011.         }
4012.         return retval;
4013. #else   /* !(MAC_GRAPHICS_ENV && BACKWARD_COMPAT) */
4014.         config_error_add("'%s' %s; use 'symset:%s' instead",
4015.                          fullname,
4016. #ifdef MAC_GRAPHICS_ENV /* implies BACKWARD_COMPAT is not defined */
4017.                          "no longer supported",
4018. #else
4019.                          "is not supported",
4020. #endif
4021.                          fullname);
4022.         return FALSE;
4023. #endif  /* ?(MAC_GRAPHICS_ENV && BACKWARD_COMPAT) */
4024.     } /* "MACgraphics" */
4025. 
4026.     /*
4027.      * OK, if we still haven't recognized the option, check the boolean
4028.      * options list.
4029.      */
4030.     for (i = 0; boolopt[i].name; i++) {
4031.         if (match_optname(opts, boolopt[i].name, 3, TRUE)) {
4032.             /* options that don't exist */
4033.             if (!boolopt[i].addr) {
4034.                 if (!initial && !negated)
4035.                     pline_The("\"%s\" option is not available.",
4036.                               boolopt[i].name);
4037.                 return retval;
4038.             }
4039.             /* options that must come from config file */
4040.             if (!initial && (boolopt[i].optflags == SET_IN_FILE)) {
4041.                 rejectoption(boolopt[i].name);
4042.                 return retval;
4043.             }
4044. 
4045.             op = string_for_opt(opts, TRUE);
4046.             if (op != empty_optstr) {
4047.                 if (negated) {
4048.                     config_error_add(
4049.                            "Negated boolean '%s' should not have a parameter",
4050.                                      boolopt[i].name);
4051.                     return FALSE;
4052.                 }
4053.                 if (!strcmp(op, "true") || !strcmp(op, "yes")) {
4054.                     negated = FALSE;
4055.                 } else if (!strcmp(op, "false") || !strcmp(op, "no")) {
4056.                     negated = TRUE;
4057.                 } else {
4058.                     config_error_add("Illegal parameter for a boolean");
4059.                     return FALSE;
4060.                 }
4061.             }
4062.             if (iflags.debug_fuzzer && !initial) {
4063.                 /* don't randomly toggle this/these */
4064.                 if (boolopt[i].addr == &flags.silent)
4065.                     return TRUE;
4066.             }
4067. 
4068.             *(boolopt[i].addr) = !negated;
4069. 
4070.             /* 0 means boolean opts */
4071.             if (duplicate_opt_detection(boolopt[i].name, 0))
4072.                 complain_about_duplicate(boolopt[i].name, 0);
4073. #ifdef RLECOMP
4074.             if (boolopt[i].addr == &iflags.rlecomp)
4075.                 set_savepref(iflags.rlecomp ? "rlecomp" : "!rlecomp");
4076. #endif
4077. #ifdef ZEROCOMP
4078.             if (boolopt[i].addr == &iflags.zerocomp)
4079.                 set_savepref(iflags.zerocomp ? "zerocomp" : "externalcomp");
4080. #endif
4081.             if (boolopt[i].addr == &iflags.wc_ascii_map) {
4082.                 /* toggling ascii_map; set tiled_map to its opposite;
4083.                    what does it mean to turn off ascii map if tiled map
4084.                    isn't supported? -- right now, we do nothing */
4085.                 iflags.wc_tiled_map = negated;
4086.             } else if (boolopt[i].addr == &iflags.wc_tiled_map) {
4087.                 /* toggling tiled_map; set ascii_map to its opposite;
4088.                    as with ascii_map, what does it mean to turn off tiled
4089.                    map if ascii map isn't supported? */
4090.                 iflags.wc_ascii_map = negated;
4091.             }
4092.             /* only do processing below if setting with doset() */
4093.             if (initial)
4094.                 return retval;
4095. 
4096.             if (boolopt[i].addr == &flags.time
4097. #ifdef SCORE_ON_BOTL
4098.                 || boolopt[i].addr == &flags.showscore
4099. #endif
4100.                 || boolopt[i].addr == &flags.showexp) {
4101.                 if (VIA_WINDOWPORT())
4102.                     status_initialize(REASSESS_ONLY);
4103.                 context.botl = TRUE;
4104.             } else if (boolopt[i].addr == &flags.invlet_constant
4105.                        || boolopt[i].addr == &flags.sortpack
4106.                        || boolopt[i].addr == &iflags.implicit_uncursed) {
4107.                 if (!flags.invlet_constant)
4108.                     reassign();
4109.                 update_inventory();
4110.             } else if (boolopt[i].addr == &flags.lit_corridor
4111.                        || boolopt[i].addr == &flags.dark_room) {
4112.                 /*
4113.                  * All corridor squares seen via night vision or
4114.                  * candles & lamps change.  Update them by calling
4115.                  * newsym() on them.  Don't do this if we are
4116.                  * initializing the options --- the vision system
4117.                  * isn't set up yet.
4118.                  */
4119.                 vision_recalc(2);       /* shut down vision */
4120.                 vision_full_recalc = 1; /* delayed recalc */
4121.                 if (iflags.use_color)
4122.                     need_redraw = TRUE; /* darkroom refresh */
4123.             } else if (boolopt[i].addr == &flags.showrace
4124.                        || boolopt[i].addr == &iflags.use_inverse
4125.                        || boolopt[i].addr == &iflags.hilite_pile
4126.                        || boolopt[i].addr == &iflags.perm_invent
4127. #ifdef CURSES_GRAPHICS
4128.                        || boolopt[i].addr == &iflags.cursesgraphics
4129. #endif
4130.                        || boolopt[i].addr == &iflags.wc_ascii_map
4131.                        || boolopt[i].addr == &iflags.wc_tiled_map) {
4132.                 need_redraw = TRUE;
4133.             } else if (boolopt[i].addr == &iflags.hilite_pet) {
4134. #ifdef CURSES_GRAPHICS
4135.                 if (WINDOWPORT("curses")) {
4136.                     /* if we're enabling hilite_pet and petattr isn't set,
4137.                        set it to Inverse; if we're disabling, leave petattr
4138.                        alone so that re-enabling will get current value back */
4139.                     if (iflags.hilite_pet && !iflags.wc2_petattr)
4140.                         iflags.wc2_petattr = curses_read_attrs("I");
4141.                 }
4142. #endif
4143.                 need_redraw = TRUE;
4144.             } else if (boolopt[i].addr == &iflags.wc2_hitpointbar) {
4145.                 if (VIA_WINDOWPORT()) {
4146.                     /* [is reassessment really needed here?] */
4147.                     status_initialize(REASSESS_ONLY);
4148.                     need_redraw = TRUE;
4149.                 }
4150. #ifdef TEXTCOLOR
4151.             } else if (boolopt[i].addr == &iflags.use_color) {
4152.                 need_redraw = TRUE;
4153. #ifdef TOS
4154.                 if (iflags.BIOS) {
4155.                     if (colors_changed)
4156.                         restore_colors();
4157.                     else
4158.                         set_colors();
4159.                 }
4160. #endif
4161.             } else if (boolopt[i].addr == &iflags.use_menu_color
4162.                        || boolopt[i].addr == &iflags.wc2_guicolor) {
4163.                 update_inventory();
4164. #endif /* TEXTCOLOR */
4165.             }
4166.             return retval;
4167.         }
4168.     }
4169. 
4170.     /* Is it a symbol? */
4171.     if (strstr(opts, "S_") == opts && parsesymbols(opts, PRIMARY)) {
4172.         switch_symbols(TRUE);
4173.         check_gold_symbol();
4174.         return retval;
4175.     }
4176. 
4177.     /* out of valid options */
4178.     config_error_add("Unknown option '%s'", opts);
4179.     return FALSE;
4180. }
4181. 
4182. /* parse key:command */
4183. boolean
4184. parsebindings(bindings)
4185. char* bindings;
4186. {
4187.     char *bind;
4188.     char key;
4189.     int i;
4190.     boolean ret = FALSE;
4191. 
4192.     /* break off first binding from the rest; parse the rest */
4193.     if ((bind = index(bindings, ',')) != 0) {
4194.         *bind++ = 0;
4195.         ret |= parsebindings(bind);
4196.     }
4197. 
4198.     /* parse a single binding: first split around : */
4199.     if (! (bind = index(bindings, ':')))
4200.         return FALSE; /* it's not a binding */
4201.     *bind++ = 0;
4202. 
4203.     /* read the key to be bound */
4204.     key = txt2key(bindings);
4205.     if (!key) {
4206.         config_error_add("Unknown key binding key '%s'", bindings);
4207.         return FALSE;
4208.     }
4209. 
4210.     bind = trimspaces(bind);
4211. 
4212.     /* is it a special key? */
4213.     if (bind_specialkey(key, bind))
4214.         return TRUE;
4215. 
4216.     /* is it a menu command? */
4217.     for (i = 0; i < SIZE(default_menu_cmd_info); i++) {
4218.         if (!strcmp(default_menu_cmd_info[i].name, bind)) {
4219.             if (illegal_menu_cmd_key(key)) {
4220.                 config_error_add("Bad menu key %s:%s", visctrl(key), bind);
4221.                 return FALSE;
4222.             } else
4223.                 add_menu_cmd_alias(key, default_menu_cmd_info[i].cmd);
4224.             return TRUE;
4225.         }
4226.     }
4227. 
4228.     /* extended command? */
4229.     if (!bind_key(key, bind)) {
4230.         config_error_add("Unknown key binding command '%s'", bind);
4231.         return FALSE;
4232.     }
4233.     return TRUE;
4234. }
4235. 
4236. static NEARDATA const char *menutype[] = { "traditional", "combination",
4237.                                            "full", "partial" };
4238. 
4239. static NEARDATA const char *burdentype[] = { "unencumbered", "burdened",
4240.                                              "stressed",     "strained",
4241.                                              "overtaxed",    "overloaded" };
4242. 
4243. static NEARDATA const char *runmodes[] = { "teleport", "run", "walk",
4244.                                            "crawl" };
4245. 
4246. static NEARDATA const char *sortltype[] = { "none", "loot", "full" };
4247. 
4248. /*
4249.  * Convert the given string of object classes to a string of default object
4250.  * symbols.
4251.  */
4252. void
4253. oc_to_str(src, dest)
4254. char *src, *dest;
4255. {
4256.     int i;
4257. 
4258.     while ((i = (int) *src++) != 0) {
4259.         if (i < 0 || i >= MAXOCLASSES)
4260.             impossible("oc_to_str:  illegal object class %d", i);
4261.         else
4262.             *dest++ = def_oc_syms[i].sym;
4263.     }
4264.     *dest = '\0';
4265. }
4266. 
4267. /*
4268.  * Add the given mapping to the menu command map list.  Always keep the
4269.  * maps valid C strings.
4270.  */
4271. void
4272. add_menu_cmd_alias(from_ch, to_ch)
4273. char from_ch, to_ch;
4274. {
4275.     if (n_menu_mapped >= MAX_MENU_MAPPED_CMDS) {
4276.         pline("out of menu map space.");
4277.     } else {
4278.         mapped_menu_cmds[n_menu_mapped] = from_ch;
4279.         mapped_menu_op[n_menu_mapped] = to_ch;
4280.         n_menu_mapped++;
4281.         mapped_menu_cmds[n_menu_mapped] = '\0';
4282.         mapped_menu_op[n_menu_mapped] = '\0';
4283.     }
4284. }
4285. 
4286. char
4287. get_menu_cmd_key(ch)
4288. char ch;
4289. {
4290.     char *found = index(mapped_menu_op, ch);
4291. 
4292.     if (found) {
4293.         int idx = (int) (found - mapped_menu_op);
4294. 
4295.         ch = mapped_menu_cmds[idx];
4296.     }
4297.     return ch;
4298. }
4299. 
4300. /*
4301.  * Map the given character to its corresponding menu command.  If it
4302.  * doesn't match anything, just return the original.
4303.  */
4304. char
4305. map_menu_cmd(ch)
4306. char ch;
4307. {
4308.     char *found = index(mapped_menu_cmds, ch);
4309. 
4310.     if (found) {
4311.         int idx = (int) (found - mapped_menu_cmds);
4312. 
4313.         ch = mapped_menu_op[idx];
4314.     }
4315.     return ch;
4316. }
4317. 
4318. void
4319. show_menu_controls(win, dolist)
4320. winid win;
4321. boolean dolist;
4322. {
4323.     char buf[BUFSZ];
4324. 
4325.     putstr(win, 0, "Menu control keys:");
4326.     if (dolist) {
4327.         int i;
4328. 
4329.         for (i = 0; i < SIZE(default_menu_cmd_info); i++) {
4330.             Sprintf(buf, "%-8s %s",
4331.                     visctrl(get_menu_cmd_key(default_menu_cmd_info[i].cmd)),
4332.                     default_menu_cmd_info[i].desc);
4333.             putstr(win, 0, buf);
4334.         }
4335.     } else {
4336.         const char
4337.             fmt3[] = " %-12s       %-2s        %-2s  %s",
4338.             fmt2[] = " %-12s       %-2s        %-2s",
4339.             fmt1[] = " %10s  %-2s  %s",
4340.             fmt0[] = " %14s  %s";
4341. 
4342.         putstr(win, 0, "");
4343.         putstr(win, 0, "Selection:       On page   Full menu");
4344.         Sprintf(buf, fmt2, "Select all",
4345.                 visctrl(get_menu_cmd_key(MENU_SELECT_PAGE)),
4346.                 visctrl(get_menu_cmd_key(MENU_SELECT_ALL)));
4347.         putstr(win, 0, buf);
4348.         Sprintf(buf, fmt2, "Deselect all",
4349.                 visctrl(get_menu_cmd_key(MENU_UNSELECT_PAGE)),
4350.                 visctrl(get_menu_cmd_key(MENU_UNSELECT_ALL)));
4351.         putstr(win, 0, buf);
4352.         Sprintf(buf, fmt2, "Invert all",
4353.                 visctrl(get_menu_cmd_key(MENU_INVERT_PAGE)),
4354.                 visctrl(get_menu_cmd_key(MENU_INVERT_ALL)));
4355.         putstr(win, 0, buf);
4356.         Sprintf(buf, fmt3, "Text match", "",
4357.                 visctrl(get_menu_cmd_key(MENU_SEARCH)),
4358.                 "Search and toggle matching entries");
4359.         putstr(win, 0, buf);
4360.         putstr(win, 0, "");
4361.         putstr(win, 0, "Navigation:");
4362.         Sprintf(buf, fmt1, "Go to     ",
4363.                 visctrl(get_menu_cmd_key(MENU_NEXT_PAGE)),
4364.                 "Next page");
4365.         putstr(win, 0, buf);
4366.         Sprintf(buf, fmt1, "",
4367.                 visctrl(get_menu_cmd_key(MENU_PREVIOUS_PAGE)),
4368.                 "Previous page");
4369.         putstr(win, 0, buf);
4370.         Sprintf(buf, fmt1, "",
4371.                 visctrl(get_menu_cmd_key(MENU_FIRST_PAGE)),
4372.                 "First page");
4373.         putstr(win, 0, buf);
4374.         Sprintf(buf, fmt1, "",
4375.                 visctrl(get_menu_cmd_key(MENU_LAST_PAGE)),
4376.                 "Last page");
4377.         putstr(win, 0, buf);
4378.         Sprintf(buf, fmt0, "SPACE", "Next page, if any, otherwise RETURN");
4379.         putstr(win, 0, buf);
4380.         Sprintf(buf, fmt0, "RETURN/ENTER",
4381.                 "Finish menu with any selection(s) made");
4382.         putstr(win, 0, buf);
4383.         Sprintf(buf, fmt0, "ESCAPE",
4384.                 "Cancel menu without selecting anything");
4385.         putstr(win, 0, buf);
4386.     }
4387. }
4388. 
4389. #if defined(MICRO) || defined(MAC) || defined(WIN32)
4390. #define OPTIONS_HEADING "OPTIONS"
4391. #else
4392. #define OPTIONS_HEADING "NETHACKOPTIONS"
4393. #endif
4394. 
4395. static char fmtstr_doset[] = "%s%-15s [%s]   ";
4396. static char fmtstr_doset_tab[] = "%s\t[%s]";
4397. static char n_currently_set[] = "(%d currently set)";
4398. 
4399. /* doset('O' command) menu entries for compound options */
4400. STATIC_OVL void
4401. doset_add_menu(win, option, indexoffset)
4402. winid win;          /* window to add to */
4403. const char *option; /* option name */
4404. int indexoffset;    /* value to add to index in compopt[], or zero
4405.                        if option cannot be changed */
4406. {
4407.     const char *value = "unknown"; /* current value */
4408.     char buf[BUFSZ], buf2[BUFSZ];
4409.     anything any;
4410.     int i;
4411. 
4412.     any = zeroany;
4413.     if (indexoffset == 0) {
4414.         any.a_int = 0;
4415.         value = get_compopt_value(option, buf2);
4416.     } else {
4417.         for (i = 0; compopt[i].name; i++)
4418.             if (strcmp(option, compopt[i].name) == 0)
4419.                 break;
4420. 
4421.         if (compopt[i].name) {
4422.             any.a_int = i + 1 + indexoffset;
4423.             value = get_compopt_value(option, buf2);
4424.         } else {
4425.             /* We are trying to add an option not found in compopt[].
4426.                This is almost certainly bad, but we'll let it through anyway
4427.                (with a zero value, so it can't be selected). */
4428.             any.a_int = 0;
4429.         }
4430.     }
4431.     /* "    " replaces "a - " -- assumes menus follow that style */
4432.     if (!iflags.menu_tab_sep)
4433.         Sprintf(buf, fmtstr_doset, any.a_int ? "" : "    ", option,
4434.                 value);
4435.     else
4436.         Sprintf(buf, fmtstr_doset_tab, option, value);
4437.     add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED);
4438. }
4439. 
4440. STATIC_OVL void
4441. opts_add_others(win, name, id, bufx, nset)
4442. winid win;
4443. const char *name;
4444. int id;
4445. char *bufx;
4446. int nset;
4447. {
4448.     char buf[BUFSZ], buf2[BUFSZ];
4449.     anything any = zeroany;
4450. 
4451.     any.a_int = id;
4452.     if (!bufx)
4453.         Sprintf(buf2, n_currently_set, nset);
4454.     else
4455.         Sprintf(buf2, "%s", bufx);
4456.     if (!iflags.menu_tab_sep)
4457.         Sprintf(buf, fmtstr_doset, any.a_int ? "" : "    ",
4458.                 name, buf2);
4459.     else
4460.         Sprintf(buf, fmtstr_doset_tab, name, buf2);
4461.     add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED);
4462. }
4463. 
4464. int
4465. count_apes(VOID_ARGS)
4466. {
4467.     int numapes = 0;
4468.     struct autopickup_exception *ape = apelist;
4469. 
4470.     while (ape) {
4471.       numapes++;
4472.       ape = ape->next;
4473.     }
4474. 
4475.     return numapes;
4476. }
4477. 
4478. enum opt_other_enums {
4479.     OPT_OTHER_MSGTYPE = -4,
4480.     OPT_OTHER_MENUCOLOR = -3,
4481.     OPT_OTHER_STATHILITE = -2,
4482.     OPT_OTHER_APEXC = -1
4483.     /* these must be < 0 */
4484. };
4485. 
4486. static struct other_opts {
4487.     const char *name;
4488.     int optflags;
4489.     enum opt_other_enums code;
4490.     int NDECL((*othr_count_func));
4491. } othropt[] = {
4492.     { "autopickup exceptions", SET_IN_GAME, OPT_OTHER_APEXC, count_apes },
4493.     { "menu colors", SET_IN_GAME, OPT_OTHER_MENUCOLOR, count_menucolors },
4494.     { "message types", SET_IN_GAME, OPT_OTHER_MSGTYPE, msgtype_count },
4495. #ifdef STATUS_HILITES
4496.     { "status hilite rules", SET_IN_GAME, OPT_OTHER_STATHILITE,
4497.       count_status_hilites },
4498. #endif
4499.     { (char *) 0, 0, (enum opt_other_enums) 0 },
4500. };
4501. 
4502. /* the 'O' command */
4503. int
4504. doset() /* changing options via menu by Per Liboriussen */
4505. {
4506.     static boolean made_fmtstr = FALSE;
4507.     char buf[BUFSZ];
4508.     const char *name;
4509.     int i = 0, pass, boolcount, pick_cnt, pick_idx, opt_indx;
4510.     boolean *bool_p;
4511.     winid tmpwin;
4512.     anything any;
4513.     menu_item *pick_list;
4514.     int indexoffset, startpass, endpass, optflags;
4515.     boolean setinitial = FALSE, fromfile = FALSE;
4516.     unsigned longest_name_len;
4517. 
4518.     tmpwin = create_nhwindow(NHW_MENU);
4519.     start_menu(tmpwin);
4520. 
4521. #ifdef notyet /* SYSCF */
4522.     /* XXX I think this is still fragile.  Fixing initial/from_file and/or
4523.        changing the SET_* etc to bitmaps will let me make this better. */
4524.     if (wizard)
4525.         startpass = SET_IN_SYS;
4526.     else
4527. #endif
4528.         startpass = DISP_IN_GAME;
4529.     endpass = (wizard) ? SET_IN_WIZGAME : SET_IN_GAME;
4530. 
4531.     if (!made_fmtstr && !iflags.menu_tab_sep) {
4532.         /* spin through the options to find the longest name
4533.            and adjust the format string accordingly */
4534.         longest_name_len = 0;
4535.         for (pass = 0; pass <= 2; pass++)
4536.             for (i = 0; (name = ((pass == 0) ? boolopt[i].name
4537.                                  : (pass == 1) ? compopt[i].name
4538.                                    : othropt[i].name)) != 0; i++) {
4539.                 if (pass == 0 && !boolopt[i].addr)
4540.                     continue;
4541.                 optflags = (pass == 0) ? boolopt[i].optflags
4542.                            : (pass == 1) ? compopt[i].optflags
4543.                              : othropt[i].optflags;
4544.                 if (optflags < startpass || optflags > endpass)
4545.                     continue;
4546.                 if ((is_wc_option(name) && !wc_supported(name))
4547.                     || (is_wc2_option(name) && !wc2_supported(name)))
4548.                     continue;
4549. 
4550.                 if (strlen(name) > longest_name_len)
4551.                     longest_name_len = strlen(name);
4552.             }
4553.         Sprintf(fmtstr_doset, "%%s%%-%us [%%s]", longest_name_len);
4554.         made_fmtstr = TRUE;
4555.     }
4556. 
4557.     any = zeroany;
4558.     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
4559.              "Booleans (selecting will toggle value):", MENU_UNSELECTED);
4560.     any.a_int = 0;
4561.     /* first list any other non-modifiable booleans, then modifiable ones */
4562.     for (pass = 0; pass <= 1; pass++)
4563.         for (i = 0; (name = boolopt[i].name) != 0; i++)
4564.             if ((bool_p = boolopt[i].addr) != 0
4565.                 && ((boolopt[i].optflags <= DISP_IN_GAME && pass == 0)
4566.                     || (boolopt[i].optflags >= SET_IN_GAME && pass == 1))) {
4567.                 if (bool_p == &flags.female)
4568.                     continue; /* obsolete */
4569.                 if (boolopt[i].optflags == SET_IN_WIZGAME && !wizard)
4570.                     continue;
4571.                 if ((is_wc_option(name) && !wc_supported(name))
4572.                     || (is_wc2_option(name) && !wc2_supported(name)))
4573.                     continue;
4574. 
4575.                 any.a_int = (pass == 0) ? 0 : i + 1;
4576.                 if (!iflags.menu_tab_sep)
4577.                     Sprintf(buf, fmtstr_doset, (pass == 0) ? "    " : "",
4578.                             name, *bool_p ? "true" : "false");
4579.                 else
4580.                     Sprintf(buf, fmtstr_doset_tab,
4581.                             name, *bool_p ? "true" : "false");
4582.                 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf,
4583.                          MENU_UNSELECTED);
4584.             }
4585. 
4586.     boolcount = i;
4587.     indexoffset = boolcount;
4588.     any = zeroany;
4589.     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
4590.     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
4591.              "Compounds (selecting will prompt for new value):",
4592.              MENU_UNSELECTED);
4593. 
4594.     /* deliberately put playmode, name, role+race+gender+align first */
4595.     doset_add_menu(tmpwin, "playmode", 0);
4596.     doset_add_menu(tmpwin, "name", 0);
4597.     doset_add_menu(tmpwin, "role", 0);
4598.     doset_add_menu(tmpwin, "race", 0);
4599.     doset_add_menu(tmpwin, "gender", 0);
4600.     doset_add_menu(tmpwin, "align", 0);
4601. 
4602.     for (pass = startpass; pass <= endpass; pass++)
4603.         for (i = 0; (name = compopt[i].name) != 0; i++)
4604.             if (compopt[i].optflags == pass) {
4605.                 if (!strcmp(name, "playmode")  || !strcmp(name, "name")
4606.                     || !strcmp(name, "role")   || !strcmp(name, "race")
4607.                     || !strcmp(name, "gender") || !strcmp(name, "align"))
4608.                     continue;
4609.                 if ((is_wc_option(name) && !wc_supported(name))
4610.                     || (is_wc2_option(name) && !wc2_supported(name)))
4611.                     continue;
4612. 
4613.                 doset_add_menu(tmpwin, name,
4614.                                (pass == DISP_IN_GAME) ? 0 : indexoffset);
4615.             }
4616. 
4617.     any = zeroany;
4618.     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
4619.     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
4620.              "Other settings:", MENU_UNSELECTED);
4621. 
4622.     for (i = 0; (name = othropt[i].name) != 0; i++) {
4623.         if ((is_wc_option(name) && !wc_supported(name))
4624.             || (is_wc2_option(name) && !wc2_supported(name)))
4625.             continue;
4626.         opts_add_others(tmpwin, name, othropt[i].code,
4627.                         (char *) 0, othropt[i].othr_count_func());
4628.     }
4629. 
4630. #ifdef PREFIXES_IN_USE
4631.     any = zeroany;
4632.     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
4633.     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
4634.              "Variable playground locations:", MENU_UNSELECTED);
4635.     for (i = 0; i < PREFIX_COUNT; i++)
4636.         doset_add_menu(tmpwin, fqn_prefix_names[i], 0);
4637. #endif
4638.     end_menu(tmpwin, "Set what options?");
4639.     need_redraw = FALSE;
4640.     if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &pick_list)) > 0) {
4641.         /*
4642.          * Walk down the selection list and either invert the booleans
4643.          * or prompt for new values. In most cases, call parseoptions()
4644.          * to take care of options that require special attention, like
4645.          * redraws.
4646.          */
4647.         for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
4648.             opt_indx = pick_list[pick_idx].item.a_int - 1;
4649.             if (opt_indx < -1)
4650.                 opt_indx++; /* -1 offset for select_menu() */
4651.             if (opt_indx == OPT_OTHER_APEXC) {
4652.                 (void) special_handling("autopickup_exception", setinitial,
4653.                                         fromfile);
4654. #ifdef STATUS_HILITES
4655.             } else if (opt_indx == OPT_OTHER_STATHILITE) {
4656.                 if (!status_hilite_menu()) {
4657.                     pline("Bad status hilite(s) specified.");
4658.                 } else {
4659.                     if (wc2_supported("hilite_status"))
4660.                         preference_update("hilite_status");
4661.                 }
4662. #endif
4663.             } else if (opt_indx == OPT_OTHER_MENUCOLOR) {
4664.                     (void) special_handling("menu_colors", setinitial,
4665.                                             fromfile);
4666.             } else if (opt_indx == OPT_OTHER_MSGTYPE) {
4667.                     (void) special_handling("msgtype", setinitial, fromfile);
4668.             } else if (opt_indx < boolcount) {
4669.                 /* boolean option */
4670.                 Sprintf(buf, "%s%s", *boolopt[opt_indx].addr ? "!" : "",
4671.                         boolopt[opt_indx].name);
4672.                 (void) parseoptions(buf, setinitial, fromfile);
4673.                 if (wc_supported(boolopt[opt_indx].name)
4674.                     || wc2_supported(boolopt[opt_indx].name))
4675.                     preference_update(boolopt[opt_indx].name);
4676.             } else {
4677.                 /* compound option */
4678.                 opt_indx -= boolcount;
4679. 
4680.                 if (!special_handling(compopt[opt_indx].name, setinitial,
4681.                                       fromfile)) {
4682.                     char abuf[BUFSZ];
4683. 
4684.                     Sprintf(buf, "Set %s to what?", compopt[opt_indx].name);
4685.                     abuf[0] = '\0';
4686.                     getlin(buf, abuf);
4687.                     if (abuf[0] == '\033')
4688.                         continue;
4689.                     Sprintf(buf, "%s:", compopt[opt_indx].name);
4690.                     (void) strncat(eos(buf), abuf,
4691.                                    (sizeof buf - 1 - strlen(buf)));
4692.                     /* pass the buck */
4693.                     (void) parseoptions(buf, setinitial, fromfile);
4694.                 }
4695.                 if (wc_supported(compopt[opt_indx].name)
4696.                     || wc2_supported(compopt[opt_indx].name))
4697.                     preference_update(compopt[opt_indx].name);
4698.             }
4699.         }
4700.         free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
4701.     }
4702. 
4703.     destroy_nhwindow(tmpwin);
4704.     if (need_redraw) {
4705.         check_gold_symbol();
4706.         reglyph_darkroom();
4707.         (void) doredraw();
4708.     }
4709.     return 0;
4710. }
4711. 
4712. /* common to msg-types, menu-colors, autopickup-exceptions */
4713. STATIC_OVL int
4714. handle_add_list_remove(optname, numtotal)
4715. const char *optname;
4716. int numtotal;
4717. {
4718.     winid tmpwin;
4719.     anything any;
4720.     int i, pick_cnt, opt_idx;
4721.     menu_item *pick_list = (menu_item *) 0;
4722.     static const struct action {
4723.         char letr;
4724.         const char *desc;
4725.     } action_titles[] = {
4726.         { 'a', "add new %s" },         /* [0] */
4727.         { 'l', "list %s" },            /* [1] */
4728.         { 'r', "remove existing %s" }, /* [2] */
4729.         { 'x', "exit this menu" },     /* [3] */
4730.     };
4731. 
4732.     opt_idx = 0;
4733.     tmpwin = create_nhwindow(NHW_MENU);
4734.     start_menu(tmpwin);
4735.     any = zeroany;
4736.     for (i = 0; i < SIZE(action_titles); i++) {
4737.         char tmpbuf[BUFSZ];
4738. 
4739.         any.a_int++;
4740.         /* omit list and remove if there aren't any yet */
4741.         if (!numtotal && (i == 1 || i == 2))
4742.             continue;
4743.         Sprintf(tmpbuf, action_titles[i].desc,
4744.                 (i == 1) ? makeplural(optname) : optname);
4745.         add_menu(tmpwin, NO_GLYPH, &any, action_titles[i].letr, 0, ATR_NONE,
4746.                  tmpbuf, (i == 3) ? MENU_SELECTED : MENU_UNSELECTED);
4747.     }
4748.     end_menu(tmpwin, "Do what?");
4749.     if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &pick_list)) > 0) {
4750.         opt_idx = pick_list[0].item.a_int - 1;
4751.         if (pick_cnt > 1 && opt_idx == 3)
4752.             opt_idx = pick_list[1].item.a_int - 1;
4753.         free((genericptr_t) pick_list);
4754.     } else
4755.         opt_idx = 3; /* none selected, exit menu */
4756.     destroy_nhwindow(tmpwin);
4757.     return opt_idx;
4758. }
4759. 
4760. struct symsetentry *symset_list = 0; /* files.c will populate this with
4761.                                       * list of available sets */
4762. 
4763. STATIC_OVL boolean
4764. special_handling(optname, setinitial, setfromfile)
4765. const char *optname;
4766. boolean setinitial, setfromfile;
4767. {
4768.     winid tmpwin;
4769.     anything any;
4770.     int i, n;
4771.     char buf[BUFSZ];
4772. 
4773.     /* Special handling of menustyle, pickup_burden, pickup_types,
4774.      * disclose, runmode, msg_window, menu_headings, sortloot,
4775.      * and number_pad options.
4776.      * Also takes care of interactive autopickup_exception_handling changes.
4777.      */
4778.     if (!strcmp("menustyle", optname)) {
4779.         const char *style_name;
4780.         menu_item *style_pick = (menu_item *) 0;
4781. 
4782.         tmpwin = create_nhwindow(NHW_MENU);
4783.         start_menu(tmpwin);
4784.         any = zeroany;
4785.         for (i = 0; i < SIZE(menutype); i++) {
4786.             style_name = menutype[i];
4787.             /* note: separate `style_name' variable used
4788.                to avoid an optimizer bug in VAX C V2.3 */
4789.             any.a_int = i + 1;
4790.             add_menu(tmpwin, NO_GLYPH, &any, *style_name, 0, ATR_NONE,
4791.                      style_name, MENU_UNSELECTED);
4792.         }
4793.         end_menu(tmpwin, "Select menustyle:");
4794.         if (select_menu(tmpwin, PICK_ONE, &style_pick) > 0) {
4795.             flags.menu_style = style_pick->item.a_int - 1;
4796.             free((genericptr_t) style_pick);
4797.         }
4798.         destroy_nhwindow(tmpwin);
4799.     } else if (!strcmp("paranoid_confirmation", optname)) {
4800.         menu_item *paranoia_picks = (menu_item *) 0;
4801. 
4802.         tmpwin = create_nhwindow(NHW_MENU);
4803.         start_menu(tmpwin);
4804.         any = zeroany;
4805.         for (i = 0; paranoia[i].flagmask != 0; ++i) {
4806.             if (paranoia[i].flagmask == PARANOID_BONES && !wizard)
4807.                 continue;
4808.             any.a_int = paranoia[i].flagmask;
4809.             add_menu(tmpwin, NO_GLYPH, &any, *paranoia[i].argname, 0,
4810.                      ATR_NONE, paranoia[i].explain,
4811.                      (flags.paranoia_bits & paranoia[i].flagmask)
4812.                          ? MENU_SELECTED
4813.                          : MENU_UNSELECTED);
4814.         }
4815.         end_menu(tmpwin, "Actions requiring extra confirmation:");
4816.         i = select_menu(tmpwin, PICK_ANY, &paranoia_picks);
4817.         if (i >= 0) {
4818.             /* player didn't cancel; we reset all the paranoia options
4819.                here even if there were no items picked, since user
4820.                could have toggled off preselected ones to end up with 0 */
4821.             flags.paranoia_bits = 0;
4822.             if (i > 0) {
4823.                 /* at least 1 item set, either preselected or newly picked */
4824.                 while (--i >= 0)
4825.                     flags.paranoia_bits |= paranoia_picks[i].item.a_int;
4826.                 free((genericptr_t) paranoia_picks);
4827.             }
4828.         }
4829.         destroy_nhwindow(tmpwin);
4830.     } else if (!strcmp("pickup_burden", optname)) {
4831.         const char *burden_name, *burden_letters = "ubsntl";
4832.         menu_item *burden_pick = (menu_item *) 0;
4833. 
4834.         tmpwin = create_nhwindow(NHW_MENU);
4835.         start_menu(tmpwin);
4836.         any = zeroany;
4837.         for (i = 0; i < SIZE(burdentype); i++) {
4838.             burden_name = burdentype[i];
4839.             any.a_int = i + 1;
4840.             add_menu(tmpwin, NO_GLYPH, &any, burden_letters[i], 0, ATR_NONE,
4841.                      burden_name, MENU_UNSELECTED);
4842.         }
4843.         end_menu(tmpwin, "Select encumbrance level:");
4844.         if (select_menu(tmpwin, PICK_ONE, &burden_pick) > 0) {
4845.             flags.pickup_burden = burden_pick->item.a_int - 1;
4846.             free((genericptr_t) burden_pick);
4847.         }
4848.         destroy_nhwindow(tmpwin);
4849.     } else if (!strcmp("pickup_types", optname)) {
4850.         /* parseoptions will prompt for the list of types */
4851.         (void) parseoptions(strcpy(buf, "pickup_types"),
4852.                             setinitial, setfromfile);
4853.     } else if (!strcmp("disclose", optname)) {
4854.         /* order of disclose_names[] must correspond to
4855.            disclosure_options in decl.c */
4856.         static const char *disclosure_names[] = {
4857.             "inventory", "attributes", "vanquished",
4858.             "genocides", "conduct",    "overview",
4859.         };
4860.         int disc_cat[NUM_DISCLOSURE_OPTIONS];
4861.         int pick_cnt, pick_idx, opt_idx;
4862.         char c;
4863.         menu_item *disclosure_pick = (menu_item *) 0;
4864. 
4865.         tmpwin = create_nhwindow(NHW_MENU);
4866.         start_menu(tmpwin);
4867.         any = zeroany;
4868.         for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
4869.             Sprintf(buf, "%-12s[%c%c]", disclosure_names[i],
4870.                     flags.end_disclose[i], disclosure_options[i]);
4871.             any.a_int = i + 1;
4872.             add_menu(tmpwin, NO_GLYPH, &any, disclosure_options[i], 0,
4873.                      ATR_NONE, buf, MENU_UNSELECTED);
4874.             disc_cat[i] = 0;
4875.         }
4876.         end_menu(tmpwin, "Change which disclosure options categories:");
4877.         pick_cnt = select_menu(tmpwin, PICK_ANY, &disclosure_pick);
4878.         if (pick_cnt > 0) {
4879.             for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
4880.                 opt_idx = disclosure_pick[pick_idx].item.a_int - 1;
4881.                 disc_cat[opt_idx] = 1;
4882.             }
4883.             free((genericptr_t) disclosure_pick);
4884.             disclosure_pick = (menu_item *) 0;
4885.         }
4886.         destroy_nhwindow(tmpwin);
4887. 
4888.         for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
4889.             if (disc_cat[i]) {
4890.                 c = flags.end_disclose[i];
4891.                 Sprintf(buf, "Disclosure options for %s:",
4892.                         disclosure_names[i]);
4893.                 tmpwin = create_nhwindow(NHW_MENU);
4894.                 start_menu(tmpwin);
4895.                 any = zeroany;
4896.                 /* 'y','n',and '+' work as alternate selectors; '-' doesn't */
4897.                 any.a_char = DISCLOSE_NO_WITHOUT_PROMPT;
4898.                 add_menu(tmpwin, NO_GLYPH, &any, 0, any.a_char, ATR_NONE,
4899.                          "Never disclose, without prompting",
4900.                          (c == any.a_char) ? MENU_SELECTED : MENU_UNSELECTED);
4901.                 any.a_char = DISCLOSE_YES_WITHOUT_PROMPT;
4902.                 add_menu(tmpwin, NO_GLYPH, &any, 0, any.a_char, ATR_NONE,
4903.                          "Always disclose, without prompting",
4904.                          (c == any.a_char) ? MENU_SELECTED : MENU_UNSELECTED);
4905.                 if (*disclosure_names[i] == 'v') {
4906.                     any.a_char = DISCLOSE_SPECIAL_WITHOUT_PROMPT; /* '#' */
4907.                     add_menu(tmpwin, NO_GLYPH, &any, 0, any.a_char, ATR_NONE,
4908.                              "Always disclose, pick sort order from menu",
4909.                              (c == any.a_char) ? MENU_SELECTED
4910.                                                : MENU_UNSELECTED);
4911.                 }
4912.                 any.a_char = DISCLOSE_PROMPT_DEFAULT_NO;
4913.                 add_menu(tmpwin, NO_GLYPH, &any, 0, any.a_char, ATR_NONE,
4914.                          "Prompt, with default answer of \"No\"",
4915.                          (c == any.a_char) ? MENU_SELECTED : MENU_UNSELECTED);
4916.                 any.a_char = DISCLOSE_PROMPT_DEFAULT_YES;
4917.                 add_menu(tmpwin, NO_GLYPH, &any, 0, any.a_char, ATR_NONE,
4918.                          "Prompt, with default answer of \"Yes\"",
4919.                          (c == any.a_char) ? MENU_SELECTED : MENU_UNSELECTED);
4920.                 if (*disclosure_names[i] == 'v') {
4921.                     any.a_char = DISCLOSE_PROMPT_DEFAULT_SPECIAL; /* '?' */
4922.                     add_menu(tmpwin, NO_GLYPH, &any, 0, any.a_char, ATR_NONE,
4923.                 "Prompt, with default answer of \"Ask\" to request sort menu",
4924.                              (c == any.a_char) ? MENU_SELECTED
4925.                                                : MENU_UNSELECTED);
4926.                 }
4927.                 end_menu(tmpwin, buf);
4928.                 n = select_menu(tmpwin, PICK_ONE, &disclosure_pick);
4929.                 if (n > 0) {
4930.                     flags.end_disclose[i] = disclosure_pick[0].item.a_char;
4931.                     if (n > 1 && flags.end_disclose[i] == c)
4932.                         flags.end_disclose[i] = disclosure_pick[1].item.a_char;
4933.                     free((genericptr_t) disclosure_pick);
4934.                 }
4935.                 destroy_nhwindow(tmpwin);
4936.             }
4937.         }
4938.     } else if (!strcmp("runmode", optname)) {
4939.         const char *mode_name;
4940.         menu_item *mode_pick = (menu_item *) 0;
4941. 
4942.         tmpwin = create_nhwindow(NHW_MENU);
4943.         start_menu(tmpwin);
4944.         any = zeroany;
4945.         for (i = 0; i < SIZE(runmodes); i++) {
4946.             mode_name = runmodes[i];
4947.             any.a_int = i + 1;
4948.             add_menu(tmpwin, NO_GLYPH, &any, *mode_name, 0, ATR_NONE,
4949.                      mode_name, MENU_UNSELECTED);
4950.         }
4951.         end_menu(tmpwin, "Select run/travel display mode:");
4952.         if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) {
4953.             flags.runmode = mode_pick->item.a_int - 1;
4954.             free((genericptr_t) mode_pick);
4955.         }
4956.         destroy_nhwindow(tmpwin);
4957.     } else if (!strcmp("whatis_coord", optname)) {
4958.         menu_item *window_pick = (menu_item *) 0;
4959.         int pick_cnt;
4960.         char gp = iflags.getpos_coords;
4961. 
4962.         tmpwin = create_nhwindow(NHW_MENU);
4963.         start_menu(tmpwin);
4964.         any = zeroany;
4965.         any.a_char = GPCOORDS_COMPASS;
4966.         add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_COMPASS, 0, ATR_NONE,
4967.                  "compass ('east' or '3s' or '2n,4w')",
4968.                  (gp == GPCOORDS_COMPASS) ? MENU_SELECTED : MENU_UNSELECTED);
4969.         any.a_char = GPCOORDS_COMFULL;
4970.         add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_COMFULL, 0, ATR_NONE,
4971.                  "full compass ('east' or '3south' or '2north,4west')",
4972.                  (gp == GPCOORDS_COMFULL) ? MENU_SELECTED : MENU_UNSELECTED);
4973.         any.a_char = GPCOORDS_MAP;
4974.         add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_MAP, 0, ATR_NONE,
4975.                  "map <x,y>",
4976.                  (gp == GPCOORDS_MAP) ? MENU_SELECTED : MENU_UNSELECTED);
4977.         any.a_char = GPCOORDS_SCREEN;
4978.         add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_SCREEN, 0, ATR_NONE,
4979.                  "screen [row,column]",
4980.                  (gp == GPCOORDS_SCREEN) ? MENU_SELECTED : MENU_UNSELECTED);
4981.         any.a_char = GPCOORDS_NONE;
4982.         add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_NONE, 0, ATR_NONE,
4983.                  "none (no coordinates displayed)",
4984.                  (gp == GPCOORDS_NONE) ? MENU_SELECTED : MENU_UNSELECTED);
4985.         any.a_long = 0L;
4986.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
4987.         Sprintf(buf, "map: upper-left: <%d,%d>, lower-right: <%d,%d>%s",
4988.                 1, 0, COLNO - 1, ROWNO - 1,
4989.                 flags.verbose ? "; column 0 unused, off left edge" : "");
4990.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED);
4991.         if (strcmp(windowprocs.name, "tty")) /* only show for non-tty */
4992.             add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
4993.        "screen: row is offset to accommodate tty interface's use of top line",
4994.                      MENU_UNSELECTED);
4995. #if COLNO == 80
4996. #define COL80ARG flags.verbose ? "; column 80 is not used" : ""
4997. #else
4998. #define COL80ARG ""
4999. #endif
5000.         Sprintf(buf, "screen: upper-left: [%02d,%02d], lower-right: [%d,%d]%s",
5001.                 0 + 2, 1, ROWNO - 1 + 2, COLNO - 1, COL80ARG);
5002. #undef COL80ARG
5003.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED);
5004.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
5005.         end_menu(tmpwin,
5006.             "Select coordinate display when auto-describing a map position:");
5007.         if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &window_pick)) > 0) {
5008.             iflags.getpos_coords = window_pick[0].item.a_char;
5009.             /* PICK_ONE doesn't unselect preselected entry when
5010.                selecting another one */
5011.             if (pick_cnt > 1 && iflags.getpos_coords == gp)
5012.                 iflags.getpos_coords = window_pick[1].item.a_char;
5013.             free((genericptr_t) window_pick);
5014.         }
5015.         destroy_nhwindow(tmpwin);
5016.     } else if (!strcmp("whatis_filter", optname)) {
5017.         menu_item *window_pick = (menu_item *) 0;
5018.         int pick_cnt;
5019.         char gf = iflags.getloc_filter;
5020. 
5021.         tmpwin = create_nhwindow(NHW_MENU);
5022.         start_menu(tmpwin);
5023.         any = zeroany;
5024.         any.a_char = (GFILTER_NONE + 1);
5025.         add_menu(tmpwin, NO_GLYPH, &any, 'n',
5026.                  0, ATR_NONE, "no filtering",
5027.                  (gf == GFILTER_NONE) ? MENU_SELECTED : MENU_UNSELECTED);
5028.         any.a_char = (GFILTER_VIEW + 1);
5029.         add_menu(tmpwin, NO_GLYPH, &any, 'v',
5030.                  0, ATR_NONE, "in view only",
5031.                  (gf == GFILTER_VIEW) ? MENU_SELECTED : MENU_UNSELECTED);
5032.         any.a_char = (GFILTER_AREA + 1);
5033.         add_menu(tmpwin, NO_GLYPH, &any, 'a',
5034.                  0, ATR_NONE, "in same area",
5035.                  (gf == GFILTER_AREA) ? MENU_SELECTED : MENU_UNSELECTED);
5036.         end_menu(tmpwin,
5037.       "Select location filtering when going for next/previous map position:");
5038.         if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &window_pick)) > 0) {
5039.             iflags.getloc_filter = (window_pick[0].item.a_char - 1);
5040.             /* PICK_ONE doesn't unselect preselected entry when
5041.                selecting another one */
5042.             if (pick_cnt > 1 && iflags.getloc_filter == gf)
5043.                 iflags.getloc_filter = (window_pick[1].item.a_char - 1);
5044.             free((genericptr_t) window_pick);
5045.         }
5046.         destroy_nhwindow(tmpwin);
5047.     } else if (!strcmp("msg_window", optname)) {
5048. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS)
5049.         if (WINDOWPORT("tty") || WINDOWPORT("curses")) {
5050.             /* by Christian W. Cooper */
5051.             menu_item *window_pick = (menu_item *) 0;
5052. 
5053.             tmpwin = create_nhwindow(NHW_MENU);
5054.             start_menu(tmpwin);
5055.             any = zeroany;
5056.             if (!WINDOWPORT("curses")) {
5057.                 any.a_char = 's';
5058.                 add_menu(tmpwin, NO_GLYPH, &any, 's', 0, ATR_NONE,
5059.                          "single", MENU_UNSELECTED);
5060.                 any.a_char = 'c';
5061.                 add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, ATR_NONE,
5062.                          "combination", MENU_UNSELECTED);
5063.             }
5064.             any.a_char = 'f';
5065.             add_menu(tmpwin, NO_GLYPH, &any, 'f', 0, ATR_NONE, "full",
5066.                      MENU_UNSELECTED);
5067.             any.a_char = 'r';
5068.             add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, ATR_NONE, "reversed",
5069.                      MENU_UNSELECTED);
5070.             end_menu(tmpwin, "Select message history display type:");
5071.             if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) {
5072.                 iflags.prevmsg_window = window_pick->item.a_char;
5073.                 free((genericptr_t) window_pick);
5074.             }
5075.             destroy_nhwindow(tmpwin);
5076.         } else
5077. #endif /* msg_window for tty or curses */
5078.             pline("'%s' option is not supported for '%s'.",
5079.                   optname, windowprocs.name);
5080.     } else if (!strcmp("sortloot", optname)) {
5081.         const char *sortl_name;
5082.         menu_item *sortl_pick = (menu_item *) 0;
5083. 
5084.         tmpwin = create_nhwindow(NHW_MENU);
5085.         start_menu(tmpwin);
5086.         any = zeroany;
5087.         for (i = 0; i < SIZE(sortltype); i++) {
5088.             sortl_name = sortltype[i];
5089.             any.a_char = *sortl_name;
5090.             add_menu(tmpwin, NO_GLYPH, &any, *sortl_name, 0, ATR_NONE,
5091.                      sortl_name, (flags.sortloot == *sortl_name)
5092.                                     ? MENU_SELECTED : MENU_UNSELECTED);
5093.         }
5094.         end_menu(tmpwin, "Select loot sorting type:");
5095.         n = select_menu(tmpwin, PICK_ONE, &sortl_pick);
5096.         if (n > 0) {
5097.             char c = sortl_pick[0].item.a_char;
5098. 
5099.             if (n > 1 && c == flags.sortloot)
5100.                 c = sortl_pick[1].item.a_char;
5101.             flags.sortloot = c;
5102.             free((genericptr_t) sortl_pick);
5103.         }
5104.         destroy_nhwindow(tmpwin);
5105.     } else if (!strcmp("align_message", optname)
5106.                || !strcmp("align_status", optname)) {
5107.         menu_item *window_pick = (menu_item *) 0;
5108.         char abuf[BUFSZ];
5109.         boolean msg = (*(optname + 6) == 'm');
5110. 
5111.         tmpwin = create_nhwindow(NHW_MENU);
5112.         start_menu(tmpwin);
5113.         any = zeroany;
5114.         any.a_int = ALIGN_TOP;
5115.         add_menu(tmpwin, NO_GLYPH, &any, 't', 0, ATR_NONE, "top",
5116.                  MENU_UNSELECTED);
5117.         any.a_int = ALIGN_BOTTOM;
5118.         add_menu(tmpwin, NO_GLYPH, &any, 'b', 0, ATR_NONE, "bottom",
5119.                  MENU_UNSELECTED);
5120.         any.a_int = ALIGN_LEFT;
5121.         add_menu(tmpwin, NO_GLYPH, &any, 'l', 0, ATR_NONE, "left",
5122.                  MENU_UNSELECTED);
5123.         any.a_int = ALIGN_RIGHT;
5124.         add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, ATR_NONE, "right",
5125.                  MENU_UNSELECTED);
5126.         Sprintf(abuf, "Select %s window placement relative to the map:",
5127.                 msg ? "message" : "status");
5128.         end_menu(tmpwin, abuf);
5129.         if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) {
5130.             if (msg)
5131.                 iflags.wc_align_message = window_pick->item.a_int;
5132.             else
5133.                 iflags.wc_align_status = window_pick->item.a_int;
5134.             free((genericptr_t) window_pick);
5135.         }
5136.         destroy_nhwindow(tmpwin);
5137.     } else if (!strcmp("number_pad", optname)) {
5138.         static const char *npchoices[] = {
5139.             " 0 (off)", " 1 (on)", " 2 (on, MSDOS compatible)",
5140.             " 3 (on, phone-style digit layout)",
5141.             " 4 (on, phone-style layout, MSDOS compatible)",
5142.             "-1 (off, 'z' to move upper-left, 'y' to zap wands)"
5143.         };
5144.         menu_item *mode_pick = (menu_item *) 0;
5145. 
5146.         tmpwin = create_nhwindow(NHW_MENU);
5147.         start_menu(tmpwin);
5148.         any = zeroany;
5149.         for (i = 0; i < SIZE(npchoices); i++) {
5150.             any.a_int = i + 1;
5151.             add_menu(tmpwin, NO_GLYPH, &any, 'a' + i, 0, ATR_NONE,
5152.                      npchoices[i], MENU_UNSELECTED);
5153.         }
5154.         end_menu(tmpwin, "Select number_pad mode:");
5155.         if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) {
5156.             switch (mode_pick->item.a_int - 1) {
5157.             case 0:
5158.                 iflags.num_pad = FALSE;
5159.                 iflags.num_pad_mode = 0;
5160.                 break;
5161.             case 1:
5162.                 iflags.num_pad = TRUE;
5163.                 iflags.num_pad_mode = 0;
5164.                 break;
5165.             case 2:
5166.                 iflags.num_pad = TRUE;
5167.                 iflags.num_pad_mode = 1;
5168.                 break;
5169.             case 3:
5170.                 iflags.num_pad = TRUE;
5171.                 iflags.num_pad_mode = 2;
5172.                 break;
5173.             case 4:
5174.                 iflags.num_pad = TRUE;
5175.                 iflags.num_pad_mode = 3;
5176.                 break;
5177.             /* last menu choice: number_pad == -1 */
5178.             case 5:
5179.                 iflags.num_pad = FALSE;
5180.                 iflags.num_pad_mode = 1;
5181.                 break;
5182.             }
5183.             reset_commands(FALSE);
5184.             number_pad(iflags.num_pad ? 1 : 0);
5185.             free((genericptr_t) mode_pick);
5186.         }
5187.         destroy_nhwindow(tmpwin);
5188.     } else if (!strcmp("menu_headings", optname)) {
5189.         int mhattr = query_attr("How to highlight menu headings:");
5190. 
5191.         if (mhattr != -1)
5192.             iflags.menu_headings = mhattr;
5193.     } else if (!strcmp("msgtype", optname)) {
5194.         int opt_idx, nmt, mttyp;
5195.         char mtbuf[BUFSZ];
5196. 
5197.  msgtypes_again:
5198.         nmt = msgtype_count();
5199.         opt_idx = handle_add_list_remove("message type", nmt);
5200.         if (opt_idx == 3) { /* done */
5201.             return TRUE;
5202.         } else if (opt_idx == 0) { /* add new */
5203.             mtbuf[0] = '\0';
5204.             getlin("What new message pattern?", mtbuf);
5205.             if (*mtbuf == '\033')
5206.                 return TRUE;
5207.             if (*mtbuf
5208.                 && test_regex_pattern(mtbuf, (const char *)0)
5209.                 && (mttyp = query_msgtype()) != -1
5210.                 && !msgtype_add(mttyp, mtbuf)) {
5211.                 pline("Error adding the message type.");
5212.                 wait_synch();
5213.             }
5214.             goto msgtypes_again;
5215.         } else { /* list (1) or remove (2) */
5216.             int pick_idx, pick_cnt;
5217.             int mt_idx;
5218.             unsigned ln;
5219.             const char *mtype;
5220.             menu_item *pick_list = (menu_item *) 0;
5221.             struct plinemsg_type *tmp = plinemsg_types;
5222. 
5223.             tmpwin = create_nhwindow(NHW_MENU);
5224.             start_menu(tmpwin);
5225.             any = zeroany;
5226.             mt_idx = 0;
5227.             while (tmp) {
5228.                 mtype = msgtype2name(tmp->msgtype);
5229.                 any.a_int = ++mt_idx;
5230.                 Sprintf(mtbuf, "%-5s \"", mtype);
5231.                 ln = sizeof mtbuf - strlen(mtbuf) - sizeof "\"";
5232.                 if (strlen(tmp->pattern) > ln)
5233.                     Strcat(strncat(mtbuf, tmp->pattern, ln - 3), "...\"");
5234.                 else
5235.                     Strcat(strcat(mtbuf, tmp->pattern), "\"");
5236.                 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, mtbuf,
5237.                          MENU_UNSELECTED);
5238.                 tmp = tmp->next;
5239.             }
5240.             Sprintf(mtbuf, "%s message types",
5241.                     (opt_idx == 1) ? "List of" : "Remove which");
5242.             end_menu(tmpwin, mtbuf);
5243.             pick_cnt = select_menu(tmpwin,
5244.                                    (opt_idx == 1) ? PICK_NONE : PICK_ANY,
5245.                                    &pick_list);
5246.             if (pick_cnt > 0) {
5247.                 for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx)
5248.                     free_one_msgtype(pick_list[pick_idx].item.a_int - 1
5249.                                            - pick_idx);
5250.                 free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
5251.             }
5252.             destroy_nhwindow(tmpwin);
5253.             if (pick_cnt >= 0)
5254.                 goto msgtypes_again;
5255.         }
5256.     } else if (!strcmp("menu_colors", optname)) {
5257.         int opt_idx, nmc, mcclr, mcattr;
5258.         char mcbuf[BUFSZ];
5259. 
5260.  menucolors_again:
5261.         nmc = count_menucolors();
5262.         opt_idx = handle_add_list_remove("menucolor", nmc);
5263.         if (opt_idx == 3) { /* done */
5264.  menucolors_done:
5265.             /* in case we've made a change which impacts current persistent
5266.                inventory window; we don't track whether an actual changed
5267.                occurred, so just assume there was one and that it matters;
5268.                if we're wrong, a redundant update is cheap... */
5269.             if (iflags.use_menu_color)
5270.                 update_inventory();
5271. 
5272.             /* menu colors aren't being used; if any are defined, remind
5273.                player how to use them */
5274.             else if (nmc > 0)
5275.                 pline(
5276.     "To have menu colors become active, toggle 'menucolors' option to True.");
5277.             return TRUE;
5278. 
5279.         } else if (opt_idx == 0) { /* add new */
5280.             mcbuf[0] = '\0';
5281.             getlin("What new menucolor pattern?", mcbuf);
5282.             if (*mcbuf == '\033')
5283.                 goto menucolors_done;
5284.             if (*mcbuf
5285.                 && test_regex_pattern(mcbuf, (const char *)0)
5286.                 && (mcclr = query_color((char *) 0)) != -1
5287.                 && (mcattr = query_attr((char *) 0)) != -1
5288.                 && !add_menu_coloring_parsed(mcbuf, mcclr, mcattr)) {
5289.                 pline("Error adding the menu color.");
5290.                 wait_synch();
5291.             }
5292.             goto menucolors_again;
5293. 
5294.         } else { /* list (1) or remove (2) */
5295.             int pick_idx, pick_cnt;
5296.             int mc_idx;
5297.             unsigned ln;
5298.             const char *sattr, *sclr;
5299.             menu_item *pick_list = (menu_item *) 0;
5300.             struct menucoloring *tmp = menu_colorings;
5301.             char clrbuf[QBUFSZ];
5302. 
5303.             tmpwin = create_nhwindow(NHW_MENU);
5304.             start_menu(tmpwin);
5305.             any = zeroany;
5306.             mc_idx = 0;
5307.             while (tmp) {
5308.                 sattr = attr2attrname(tmp->attr);
5309.                 sclr = strcpy(clrbuf, clr2colorname(tmp->color));
5310.                 (void) strNsubst(clrbuf, " ", "-", 0);
5311.                 any.a_int = ++mc_idx;
5312.                 /* construct suffix */
5313.                 Sprintf(buf, "\"\"=%s%s%s", sclr,
5314.                         (tmp->attr != ATR_NONE) ? "&" : "",
5315.                         (tmp->attr != ATR_NONE) ? sattr : "");
5316.                 /* now main string */
5317.                 ln = sizeof buf - strlen(buf) - 1; /* length available */
5318.                 Strcpy(mcbuf, "\"");
5319.                 if (strlen(tmp->origstr) > ln)
5320.                     Strcat(strncat(mcbuf, tmp->origstr, ln - 3), "...");
5321.                 else
5322.                     Strcat(mcbuf, tmp->origstr);
5323.                 /* combine main string and suffix */
5324.                 Strcat(mcbuf, &buf[1]); /* skip buf[]'s initial quote */
5325.                 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, mcbuf,
5326.                          MENU_UNSELECTED);
5327.                 tmp = tmp->next;
5328.             }
5329.             Sprintf(mcbuf, "%s menu colors",
5330.                     (opt_idx == 1) ? "List of" : "Remove which");
5331.             end_menu(tmpwin, mcbuf);
5332.             pick_cnt = select_menu(tmpwin,
5333.                                    (opt_idx == 1) ? PICK_NONE : PICK_ANY,
5334.                                    &pick_list);
5335.             if (pick_cnt > 0) {
5336.                 for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx)
5337.                     free_one_menu_coloring(pick_list[pick_idx].item.a_int - 1
5338.                                            - pick_idx);
5339.                 free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
5340.             }
5341.             destroy_nhwindow(tmpwin);
5342.             if (pick_cnt >= 0)
5343.                 goto menucolors_again;
5344.         }
5345.     } else if (!strcmp("autopickup_exception", optname)) {
5346.         int opt_idx, numapes = 0;
5347.         char apebuf[2 + BUFSZ]; /* so &apebuf[1] is BUFSZ long for getlin() */
5348.         struct autopickup_exception *ape;
5349. 
5350.  ape_again:
5351.         numapes = count_apes();
5352.         opt_idx = handle_add_list_remove("autopickup exception", numapes);
5353.         if (opt_idx == 3) { /* done */
5354.             return TRUE;
5355.         } else if (opt_idx == 0) { /* add new */
5356.             /* EDIT_GETLIN:  assume user doesn't user want previous
5357.                exception used as default input string for this one... */
5358.             apebuf[0] = apebuf[1] = '\0';
5359.             getlin("What new autopickup exception pattern?", &apebuf[1]);
5360.             mungspaces(&apebuf[1]); /* regularize whitespace */
5361.             if (apebuf[1] == '\033')
5362.                 return TRUE;
5363.             if (apebuf[1]) {
5364.                 apebuf[0] = '\"';
5365.                 /* guarantee room for \" prefix and \"\0 suffix;
5366.                    -2 is good enough for apebuf[] but -3 makes
5367.                    sure the whole thing fits within normal BUFSZ */
5368.                 apebuf[sizeof apebuf - 2] = '\0';
5369.                 Strcat(apebuf, "\"");
5370.                 add_autopickup_exception(apebuf);
5371.             }
5372.             goto ape_again;
5373.         } else { /* list (1) or remove (2) */
5374.             int pick_idx, pick_cnt;
5375.             menu_item *pick_list = (menu_item *) 0;
5376. 
5377.             tmpwin = create_nhwindow(NHW_MENU);
5378.             start_menu(tmpwin);
5379.             if (numapes) {
5380.                 ape = apelist;
5381.                 any = zeroany;
5382.                 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
5383.                          "Always pickup '<'; never pickup '>'",
5384.                          MENU_UNSELECTED);
5385.                 for (i = 0; i < numapes && ape; i++) {
5386.                     any.a_void = (opt_idx == 1) ? 0 : ape;
5387.                     /* length of pattern plus quotes (plus '<'/'>') is
5388.                        less than BUFSZ */
5389.                     Sprintf(apebuf, "\"%c%s\"", ape->grab ? '<' : '>',
5390.                             ape->pattern);
5391.                     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, apebuf,
5392.                              MENU_UNSELECTED);
5393.                     ape = ape->next;
5394.                 }
5395.             }
5396.             Sprintf(apebuf, "%s autopickup exceptions",
5397.                     (opt_idx == 1) ? "List of" : "Remove which");
5398.             end_menu(tmpwin, apebuf);
5399.             pick_cnt = select_menu(tmpwin,
5400.                                    (opt_idx == 1) ? PICK_NONE : PICK_ANY,
5401.                                    &pick_list);
5402.             if (pick_cnt > 0) {
5403.                 for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx)
5404.                     remove_autopickup_exception(
5405.                                          (struct autopickup_exception *)
5406.                                              pick_list[pick_idx].item.a_void);
5407.                 free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
5408.             }
5409.             destroy_nhwindow(tmpwin);
5410.             if (pick_cnt >= 0)
5411.                 goto ape_again;
5412.         }
5413.     } else if (!strcmp("symset", optname)
5414.                || !strcmp("roguesymset", optname)) {
5415.         menu_item *symset_pick = (menu_item *) 0;
5416.         boolean rogueflag = (*optname == 'r'),
5417.                 ready_to_switch = FALSE,
5418.                 nothing_to_do = FALSE;
5419.         char *symset_name, fmtstr[20];
5420.         struct symsetentry *sl;
5421.         int res, which_set, setcount = 0, chosen = -2, defindx = 0;
5422. 
5423.         which_set = rogueflag ? ROGUESET : PRIMARY;
5424.         symset_list = (struct symsetentry *) 0;
5425.         /* clear symset[].name as a flag to read_sym_file() to build list */
5426.         symset_name = symset[which_set].name;
5427.         symset[which_set].name = (char *) 0;
5428. 
5429.         res = read_sym_file(which_set);
5430.         /* put symset name back */
5431.         symset[which_set].name = symset_name;
5432. 
5433.         if (res && symset_list) {
5434.             int thissize,
5435.                 biggest = (int) (sizeof "Default Symbols" - sizeof ""),
5436.                 big_desc = 0;
5437. 
5438.             for (sl = symset_list; sl; sl = sl->next) {
5439.                 /* check restrictions */
5440.                 if (rogueflag ? sl->primary : sl->rogue)
5441.                     continue;
5442. #ifndef MAC_GRAPHICS_ENV
5443.                 if (sl->handling == H_MAC)
5444.                     continue;
5445. #endif
5446. 
5447.                 setcount++;
5448.                 /* find biggest name */
5449.                 thissize = sl->name ? (int) strlen(sl->name) : 0;
5450.                 if (thissize > biggest)
5451.                     biggest = thissize;
5452.                 thissize = sl->desc ? (int) strlen(sl->desc) : 0;
5453.                 if (thissize > big_desc)
5454.                     big_desc = thissize;
5455.             }
5456.             if (!setcount) {
5457.                 pline("There are no appropriate %s symbol sets available.",
5458.                       rogueflag ? "rogue level" : "primary");
5459.                 return TRUE;
5460.             }
5461. 
5462.             Sprintf(fmtstr, "%%-%ds %%s", biggest + 2);
5463.             tmpwin = create_nhwindow(NHW_MENU);
5464.             start_menu(tmpwin);
5465.             any = zeroany;
5466.             any.a_int = 1; /* -1 + 2 [see 'if (sl->name) {' below]*/
5467.             if (!symset_name)
5468.                 defindx = any.a_int;
5469.             add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
5470.                      "Default Symbols",
5471.                      (any.a_int == defindx) ? MENU_SELECTED
5472.                                             : MENU_UNSELECTED);
5473. 
5474.             for (sl = symset_list; sl; sl = sl->next) {
5475.                 /* check restrictions */
5476.                 if (rogueflag ? sl->primary : sl->rogue)
5477.                     continue;
5478. #ifndef MAC_GRAPHICS_ENV
5479.                 if (sl->handling == H_MAC)
5480.                     continue;
5481. #endif
5482.                 if (sl->name) {
5483.                     /* +2: sl->idx runs from 0 to N-1 for N symsets;
5484.                        +1 because Defaults are implicitly in slot [0];
5485.                        +1 again so that valid data is never 0 */
5486.                     any.a_int = sl->idx + 2;
5487.                     if (symset_name && !strcmpi(sl->name, symset_name))
5488.                         defindx = any.a_int;
5489.                     Sprintf(buf, fmtstr, sl->name, sl->desc ? sl->desc : "");
5490.                     add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf,
5491.                              (any.a_int == defindx) ? MENU_SELECTED
5492.                                                     : MENU_UNSELECTED);
5493.                 }
5494.             }
5495.             Sprintf(buf, "Select %ssymbol set:",
5496.                     rogueflag ? "rogue level " : "");
5497.             end_menu(tmpwin, buf);
5498.             n = select_menu(tmpwin, PICK_ONE, &symset_pick);
5499.             if (n > 0) {
5500.                 chosen = symset_pick[0].item.a_int;
5501.                 /* if picking non-preselected entry yields 2, make sure
5502.                    that we're going with the non-preselected one */
5503.                 if (n == 2 && chosen == defindx)
5504.                     chosen = symset_pick[1].item.a_int;
5505.                 chosen -= 2; /* convert menu index to symset index;
5506.                               * "Default symbols" have index -1 */
5507.                 free((genericptr_t) symset_pick);
5508.             } else if (n == 0 && defindx > 0) {
5509.                 chosen = defindx - 2;
5510.             }
5511.             destroy_nhwindow(tmpwin);
5512. 
5513.             if (chosen > -1) {
5514.                 /* chose an actual symset name from file */
5515.                 for (sl = symset_list; sl; sl = sl->next)
5516.                     if (sl->idx == chosen)
5517.                         break;
5518.                 if (sl) {
5519.                     /* free the now stale attributes */
5520.                     clear_symsetentry(which_set, TRUE);
5521. 
5522.                     /* transfer only the name of the symbol set */
5523.                     symset[which_set].name = dupstr(sl->name);
5524.                     ready_to_switch = TRUE;
5525.                 }
5526.             } else if (chosen == -1) {
5527.                 /* explicit selection of defaults */
5528.                 /* free the now stale symset attributes */
5529.                 clear_symsetentry(which_set, TRUE);
5530.             } else
5531.                 nothing_to_do = TRUE;
5532.         } else if (!res) {
5533.             /* The symbols file could not be accessed */
5534.             pline("Unable to access \"%s\" file.", SYMBOLS);
5535.             return TRUE;
5536.         } else if (!symset_list) {
5537.             /* The symbols file was empty */
5538.             pline("There were no symbol sets found in \"%s\".", SYMBOLS);
5539.             return TRUE;
5540.         }
5541. 
5542.         /* clean up */
5543.         while ((sl = symset_list) != 0) {
5544.             symset_list = sl->next;
5545.             if (sl->name)
5546.                 free((genericptr_t) sl->name), sl->name = (char *) 0;
5547.             if (sl->desc)
5548.                 free((genericptr_t) sl->desc), sl->desc = (char *) 0;
5549.             free((genericptr_t) sl);
5550.         }
5551. 
5552.         if (nothing_to_do)
5553.             return TRUE;
5554. 
5555.         /* Set default symbols and clear the handling value */
5556.         if (rogueflag)
5557.             init_rogue_symbols();
5558.         else
5559.             init_primary_symbols();
5560. 
5561.         if (symset[which_set].name) {
5562.             /* non-default symbols */
5563.             if (read_sym_file(which_set)) {
5564.                 ready_to_switch = TRUE;
5565.             } else {
5566.                 clear_symsetentry(which_set, TRUE);
5567.                 return TRUE;
5568.             }
5569.         }
5570. 
5571.         if (ready_to_switch)
5572.             switch_symbols(TRUE);
5573. 
5574.         if (Is_rogue_level(&u.uz)) {
5575.             if (rogueflag)
5576.                 assign_graphics(ROGUESET);
5577.         } else if (!rogueflag)
5578.             assign_graphics(PRIMARY);
5579.         preference_update("symset");
5580.         need_redraw = TRUE;
5581. 
5582.     } else {
5583.         /* didn't match any of the special options */
5584.         return FALSE;
5585.     }
5586.     return TRUE;
5587. }
5588. 
5589. #define rolestring(val, array, field) \
5590.     ((val >= 0) ? array[val].field : (val == ROLE_RANDOM) ? randomrole : none)
5591. 
5592. /* This is ugly. We have all the option names in the compopt[] array,
5593.    but we need to look at each option individually to get the value. */
5594. STATIC_OVL const char *
5595. get_compopt_value(optname, buf)
5596. const char *optname;
5597. char *buf;
5598. {
5599.     static const char none[] = "(none)", randomrole[] = "random",
5600.                       to_be_done[] = "(to be done)",
5601.                       defopt[] = "default", defbrief[] = "def";
5602.     char ocl[MAXOCLASSES + 1];
5603.     int i;
5604. 
5605.     buf[0] = '\0';
5606.     if (!strcmp(optname, "align_message")
5607.         || !strcmp(optname, "align_status")) {
5608.         int which = !strcmp(optname, "align_status") ? iflags.wc_align_status
5609.                                                      : iflags.wc_align_message;
5610.         Sprintf(buf, "%s",
5611.                 (which == ALIGN_TOP) ? "top"
5612.                 : (which == ALIGN_LEFT) ? "left"
5613.                   : (which == ALIGN_BOTTOM) ? "bottom"
5614.                     : (which == ALIGN_RIGHT) ? "right"
5615.                       : defopt);
5616.     } else if (!strcmp(optname, "align"))
5617.         Sprintf(buf, "%s", rolestring(flags.initalign, aligns, adj));
5618. #ifdef WIN32
5619.     else if (!strcmp(optname, "altkeyhandler"))
5620.         Sprintf(buf, "%s",
5621.                 iflags.altkeyhandler[0] ? iflags.altkeyhandler : "default");
5622. #endif
5623. #ifdef BACKWARD_COMPAT
5624.     else if (!strcmp(optname, "boulder"))
5625.         Sprintf(buf, "%c",
5626.                 ov_primary_syms[SYM_BOULDER + SYM_OFF_X]
5627.                     ? ov_primary_syms[SYM_BOULDER + SYM_OFF_X]
5628.                     : showsyms[(int) objects[BOULDER].oc_class + SYM_OFF_O]);
5629. #endif
5630.     else if (!strcmp(optname, "catname"))
5631.         Sprintf(buf, "%s", catname[0] ? catname : none);
5632.     else if (!strcmp(optname, "disclose"))
5633.         for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
5634.             if (i)
5635.                 (void) strkitten(buf, ' ');
5636.             (void) strkitten(buf, flags.end_disclose[i]);
5637.             (void) strkitten(buf, disclosure_options[i]);
5638.         }
5639.     else if (!strcmp(optname, "dogname"))
5640.         Sprintf(buf, "%s", dogname[0] ? dogname : none);
5641.     else if (!strcmp(optname, "dungeon"))
5642.         Sprintf(buf, "%s", to_be_done);
5643.     else if (!strcmp(optname, "effects"))
5644.         Sprintf(buf, "%s", to_be_done);
5645.     else if (!strcmp(optname, "font_map"))
5646.         Sprintf(buf, "%s", iflags.wc_font_map ? iflags.wc_font_map : defopt);
5647.     else if (!strcmp(optname, "font_message"))
5648.         Sprintf(buf, "%s",
5649.                 iflags.wc_font_message ? iflags.wc_font_message : defopt);
5650.     else if (!strcmp(optname, "font_status"))
5651.         Sprintf(buf, "%s",
5652.                 iflags.wc_font_status ? iflags.wc_font_status : defopt);
5653.     else if (!strcmp(optname, "font_menu"))
5654.         Sprintf(buf, "%s",
5655.                 iflags.wc_font_menu ? iflags.wc_font_menu : defopt);
5656.     else if (!strcmp(optname, "font_text"))
5657.         Sprintf(buf, "%s",
5658.                 iflags.wc_font_text ? iflags.wc_font_text : defopt);
5659.     else if (!strcmp(optname, "font_size_map")) {
5660.         if (iflags.wc_fontsiz_map)
5661.             Sprintf(buf, "%d", iflags.wc_fontsiz_map);
5662.         else
5663.             Strcpy(buf, defopt);
5664.     } else if (!strcmp(optname, "font_size_message")) {
5665.         if (iflags.wc_fontsiz_message)
5666.             Sprintf(buf, "%d", iflags.wc_fontsiz_message);
5667.         else
5668.             Strcpy(buf, defopt);
5669.     } else if (!strcmp(optname, "font_size_status")) {
5670.         if (iflags.wc_fontsiz_status)
5671.             Sprintf(buf, "%d", iflags.wc_fontsiz_status);
5672.         else
5673.             Strcpy(buf, defopt);
5674.     } else if (!strcmp(optname, "font_size_menu")) {
5675.         if (iflags.wc_fontsiz_menu)
5676.             Sprintf(buf, "%d", iflags.wc_fontsiz_menu);
5677.         else
5678.             Strcpy(buf, defopt);
5679.     } else if (!strcmp(optname, "font_size_text")) {
5680.         if (iflags.wc_fontsiz_text)
5681.             Sprintf(buf, "%d", iflags.wc_fontsiz_text);
5682.         else
5683.             Strcpy(buf, defopt);
5684.     } else if (!strcmp(optname, "fruit"))
5685.         Sprintf(buf, "%s", pl_fruit);
5686.     else if (!strcmp(optname, "gender"))
5687.         Sprintf(buf, "%s", rolestring(flags.initgend, genders, adj));
5688.     else if (!strcmp(optname, "horsename"))
5689.         Sprintf(buf, "%s", horsename[0] ? horsename : none);
5690.     else if (!strcmp(optname, "map_mode")) {
5691.         i = iflags.wc_map_mode;
5692.         Sprintf(buf, "%s",
5693.                 (i == MAP_MODE_TILES) ? "tiles"
5694.                 : (i == MAP_MODE_ASCII4x6) ? "ascii4x6"
5695.                   : (i == MAP_MODE_ASCII6x8) ? "ascii6x8"
5696.                     : (i == MAP_MODE_ASCII8x8) ? "ascii8x8"
5697.                       : (i == MAP_MODE_ASCII16x8) ? "ascii16x8"
5698.                         : (i == MAP_MODE_ASCII7x12) ? "ascii7x12"
5699.                           : (i == MAP_MODE_ASCII8x12) ? "ascii8x12"
5700.                             : (i == MAP_MODE_ASCII16x12) ? "ascii16x12"
5701.                               : (i == MAP_MODE_ASCII12x16) ? "ascii12x16"
5702.                                 : (i == MAP_MODE_ASCII10x18) ? "ascii10x18"
5703.                                   : (i == MAP_MODE_ASCII_FIT_TO_SCREEN)
5704.                                     ? "fit_to_screen"
5705.                                     : defopt);
5706.     } else if (!strcmp(optname, "menustyle"))
5707.         Sprintf(buf, "%s", menutype[(int) flags.menu_style]);
5708.     else if (!strcmp(optname, "menu_deselect_all"))
5709.         Sprintf(buf, "%s", to_be_done);
5710.     else if (!strcmp(optname, "menu_deselect_page"))
5711.         Sprintf(buf, "%s", to_be_done);
5712.     else if (!strcmp(optname, "menu_first_page"))
5713.         Sprintf(buf, "%s", to_be_done);
5714.     else if (!strcmp(optname, "menu_invert_all"))
5715.         Sprintf(buf, "%s", to_be_done);
5716.     else if (!strcmp(optname, "menu_headings"))
5717.         Sprintf(buf, "%s", attr2attrname(iflags.menu_headings));
5718.     else if (!strcmp(optname, "menu_invert_page"))
5719.         Sprintf(buf, "%s", to_be_done);
5720.     else if (!strcmp(optname, "menu_last_page"))
5721.         Sprintf(buf, "%s", to_be_done);
5722.     else if (!strcmp(optname, "menu_next_page"))
5723.         Sprintf(buf, "%s", to_be_done);
5724.     else if (!strcmp(optname, "menu_previous_page"))
5725.         Sprintf(buf, "%s", to_be_done);
5726.     else if (!strcmp(optname, "menu_search"))
5727.         Sprintf(buf, "%s", to_be_done);
5728.     else if (!strcmp(optname, "menu_select_all"))
5729.         Sprintf(buf, "%s", to_be_done);
5730.     else if (!strcmp(optname, "menu_select_page"))
5731.         Sprintf(buf, "%s", to_be_done);
5732.     else if (!strcmp(optname, "monsters")) {
5733.         Sprintf(buf, "%s", to_be_done);
5734.     } else if (!strcmp(optname, "msghistory")) {
5735.         Sprintf(buf, "%u", iflags.msg_history);
5736. #ifdef TTY_GRAPHICS
5737.     } else if (!strcmp(optname, "msg_window")) {
5738.         Sprintf(buf, "%s", (iflags.prevmsg_window == 's') ? "single"
5739.                            : (iflags.prevmsg_window == 'c') ? "combination"
5740.                              : (iflags.prevmsg_window == 'f') ? "full"
5741.                                : "reversed");
5742. #endif
5743.     } else if (!strcmp(optname, "name")) {
5744.         Sprintf(buf, "%s", plname);
5745.     } else if (!strcmp(optname, "mouse_support")) {
5746. #ifdef WIN32
5747. #define MOUSEFIX1 ", QuickEdit off"
5748. #define MOUSEFIX2 ", QuickEdit unchanged"
5749. #else
5750. #define MOUSEFIX1 ", O/S adjusted"
5751. #define MOUSEFIX2 ", O/S unchanged"
5752. #endif
5753.         static const char *mousemodes[][2] = {
5754.             { "0=off", "" },
5755.             { "1=on",  MOUSEFIX1 },
5756.             { "2=on",  MOUSEFIX2 },
5757.         };
5758. #undef MOUSEFIX1
5759. #undef MOUSEFIX2
5760.         int ms = iflags.wc_mouse_support;
5761. 
5762.         if (ms >= 0 && ms <= 2)
5763.             Sprintf(buf, "%s%s", mousemodes[ms][0], mousemodes[ms][1]);
5764.     } else if (!strcmp(optname, "number_pad")) {
5765.         static const char *numpadmodes[] = {
5766.             "0=off", "1=on", "2=on, MSDOS compatible",
5767.             "3=on, phone-style layout",
5768.             "4=on, phone layout, MSDOS compatible",
5769.             "-1=off, y & z swapped", /*[5]*/
5770.         };
5771.         int indx = Cmd.num_pad
5772.                        ? (Cmd.phone_layout ? (Cmd.pcHack_compat ? 4 : 3)
5773.                                            : (Cmd.pcHack_compat ? 2 : 1))
5774.                        : Cmd.swap_yz ? 5 : 0;
5775. 
5776.         Strcpy(buf, numpadmodes[indx]);
5777.     } else if (!strcmp(optname, "objects")) {
5778.         Sprintf(buf, "%s", to_be_done);
5779.     } else if (!strcmp(optname, "packorder")) {
5780.         oc_to_str(flags.inv_order, ocl);
5781.         Sprintf(buf, "%s", ocl);
5782. #ifdef CHANGE_COLOR
5783.     } else if (!strcmp(optname, "palette")) {
5784.         Sprintf(buf, "%s", get_color_string());
5785. #endif
5786.     } else if (!strcmp(optname, "paranoid_confirmation")) {
5787.         char tmpbuf[QBUFSZ];
5788. 
5789.         tmpbuf[0] = '\0';
5790.         for (i = 0; paranoia[i].flagmask != 0; ++i)
5791.             if (flags.paranoia_bits & paranoia[i].flagmask)
5792.                 Sprintf(eos(tmpbuf), " %s", paranoia[i].argname);
5793.         Strcpy(buf, tmpbuf[0] ? &tmpbuf[1] : "none");
5794.     } else if (!strcmp(optname, "petattr")) {
5795. #ifdef CURSES_GRAPHICS
5796.         if (WINDOWPORT("curses")) {
5797.             char tmpbuf[QBUFSZ];
5798. 
5799.             Strcpy(buf, curses_fmt_attrs(tmpbuf));
5800.         } else
5801. #endif
5802.         if (iflags.wc2_petattr != 0)
5803.             Sprintf(buf, "0x%08x", iflags.wc2_petattr);
5804.         else
5805.             Strcpy(buf, defopt);
5806.     } else if (!strcmp(optname, "pettype")) {
5807.         Sprintf(buf, "%s", (preferred_pet == 'c') ? "cat"
5808.                            : (preferred_pet == 'd') ? "dog"
5809.                              : (preferred_pet == 'h') ? "horse"
5810.                                : (preferred_pet == 'n') ? "none"
5811.                                  : "random");
5812.     } else if (!strcmp(optname, "pickup_burden")) {
5813.         Sprintf(buf, "%s", burdentype[flags.pickup_burden]);
5814.     } else if (!strcmp(optname, "pickup_types")) {
5815.         oc_to_str(flags.pickup_types, ocl);
5816.         Sprintf(buf, "%s", ocl[0] ? ocl : "all");
5817.     } else if (!strcmp(optname, "pile_limit")) {
5818.         Sprintf(buf, "%d", flags.pile_limit);
5819.     } else if (!strcmp(optname, "playmode")) {
5820.         Strcpy(buf, wizard ? "debug" : discover ? "explore" : "normal");
5821.     } else if (!strcmp(optname, "race")) {
5822.         Sprintf(buf, "%s", rolestring(flags.initrace, races, noun));
5823.     } else if (!strcmp(optname, "roguesymset")) {
5824.         Sprintf(buf, "%s",
5825.                 symset[ROGUESET].name ? symset[ROGUESET].name : "default");
5826.         if (currentgraphics == ROGUESET && symset[ROGUESET].name)
5827.             Strcat(buf, ", active");
5828.     } else if (!strcmp(optname, "role")) {
5829.         Sprintf(buf, "%s", rolestring(flags.initrole, roles, name.m));
5830.     } else if (!strcmp(optname, "runmode")) {
5831.         Sprintf(buf, "%s", runmodes[flags.runmode]);
5832.     } else if (!strcmp(optname, "whatis_coord")) {
5833.         Sprintf(buf, "%s",
5834.                 (iflags.getpos_coords == GPCOORDS_MAP) ? "map"
5835.                 : (iflags.getpos_coords == GPCOORDS_COMPASS) ? "compass"
5836.                 : (iflags.getpos_coords == GPCOORDS_COMFULL) ? "full compass"
5837.                 : (iflags.getpos_coords == GPCOORDS_SCREEN) ? "screen"
5838.                 : "none");
5839.     } else if (!strcmp(optname, "whatis_filter")) {
5840.         Sprintf(buf, "%s",
5841.                 (iflags.getloc_filter == GFILTER_VIEW) ? "view"
5842.                 : (iflags.getloc_filter == GFILTER_AREA) ? "area"
5843.                 : "none");
5844.     } else if (!strcmp(optname, "scores")) {
5845.         Sprintf(buf, "%d top/%d around%s", flags.end_top, flags.end_around,
5846.                 flags.end_own ? "/own" : "");
5847.     } else if (!strcmp(optname, "scroll_amount")) {
5848.         if (iflags.wc_scroll_amount)
5849.             Sprintf(buf, "%d", iflags.wc_scroll_amount);
5850.         else
5851.             Strcpy(buf, defopt);
5852.     } else if (!strcmp(optname, "scroll_margin")) {
5853.         if (iflags.wc_scroll_margin)
5854.             Sprintf(buf, "%d", iflags.wc_scroll_margin);
5855.         else
5856.             Strcpy(buf, defopt);
5857.     } else if (!strcmp(optname, "sortloot")) {
5858.         for (i = 0; i < SIZE(sortltype); i++)
5859.             if (flags.sortloot == sortltype[i][0]) {
5860.                 Strcpy(buf, sortltype[i]);
5861.                 break;
5862.             }
5863.     } else if (!strcmp(optname, "player_selection")) {
5864.         Sprintf(buf, "%s", iflags.wc_player_selection ? "prompts" : "dialog");
5865. #ifdef MSDOS
5866.     } else if (!strcmp(optname, "soundcard")) {
5867.         Sprintf(buf, "%s", to_be_done);
5868. #endif
5869. #ifdef STATUS_HILITES
5870.     } else if (!strcmp("statushilites", optname)) {
5871.         if (!iflags.hilite_delta)
5872.             Strcpy(buf, "0 (off: don't highlight status fields)");
5873.         else
5874.             Sprintf(buf, "%ld (on: highlight status for %ld turns)",
5875.                     iflags.hilite_delta, iflags.hilite_delta);
5876. #endif
5877.     } else if (!strcmp(optname,"statuslines")) {
5878.         if (wc2_supported(optname))
5879.             Strcpy(buf, (iflags.wc2_statuslines < 3) ? "2" : "3");
5880.         /* else default to "unknown" */
5881.     } else if (!strcmp(optname, "suppress_alert")) {
5882.         if (flags.suppress_alert == 0L)
5883.             Strcpy(buf, none);
5884.         else
5885.             Sprintf(buf, "%lu.%lu.%lu", FEATURE_NOTICE_VER_MAJ,
5886.                     FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH);
5887.     } else if (!strcmp(optname, "symset")) {
5888.         Sprintf(buf, "%s",
5889.                 symset[PRIMARY].name ? symset[PRIMARY].name : "default");
5890.         if (currentgraphics == PRIMARY && symset[PRIMARY].name)
5891.             Strcat(buf, ", active");
5892.     } else if (!strcmp(optname, "term_cols")) {
5893.         if (iflags.wc2_term_cols)
5894.             Sprintf(buf, "%d", iflags.wc2_term_cols);
5895.         else
5896.             Strcpy(buf, defopt);
5897.     } else if (!strcmp(optname, "term_rows")) {
5898.         if (iflags.wc2_term_rows)
5899.             Sprintf(buf, "%d", iflags.wc2_term_rows);
5900.         else
5901.             Strcpy(buf, defopt);
5902.     } else if (!strcmp(optname, "tile_file")) {
5903.         Sprintf(buf, "%s",
5904.                 iflags.wc_tile_file ? iflags.wc_tile_file : defopt);
5905.     } else if (!strcmp(optname, "tile_height")) {
5906.         if (iflags.wc_tile_height)
5907.             Sprintf(buf, "%d", iflags.wc_tile_height);
5908.         else
5909.             Strcpy(buf, defopt);
5910.     } else if (!strcmp(optname, "tile_width")) {
5911.         if (iflags.wc_tile_width)
5912.             Sprintf(buf, "%d", iflags.wc_tile_width);
5913.         else
5914.             Strcpy(buf, defopt);
5915.     } else if (!strcmp(optname, "traps")) {
5916.         Sprintf(buf, "%s", to_be_done);
5917.     } else if (!strcmp(optname, "vary_msgcount")) {
5918.         if (iflags.wc_vary_msgcount)
5919.             Sprintf(buf, "%d", iflags.wc_vary_msgcount);
5920.         else
5921.             Strcpy(buf, defopt);
5922. #ifdef MSDOS
5923.     } else if (!strcmp(optname, "video")) {
5924.         Sprintf(buf, "%s", to_be_done);
5925. #endif
5926. #ifdef VIDEOSHADES
5927.     } else if (!strcmp(optname, "videoshades")) {
5928.         Sprintf(buf, "%s-%s-%s", shade[0], shade[1], shade[2]);
5929.     } else if (!strcmp(optname, "videocolors")) {
5930.         Sprintf(buf, "%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d",
5931.                 ttycolors[CLR_RED], ttycolors[CLR_GREEN],
5932.                 ttycolors[CLR_BROWN], ttycolors[CLR_BLUE],
5933.                 ttycolors[CLR_MAGENTA], ttycolors[CLR_CYAN],
5934.                 ttycolors[CLR_ORANGE], ttycolors[CLR_BRIGHT_GREEN],
5935.                 ttycolors[CLR_YELLOW], ttycolors[CLR_BRIGHT_BLUE],
5936.                 ttycolors[CLR_BRIGHT_MAGENTA], ttycolors[CLR_BRIGHT_CYAN]);
5937. #endif /* VIDEOSHADES */
5938.     } else if (!strcmp(optname,"windowborders")) {
5939.         Sprintf(buf, "%s",
5940.                 (iflags.wc2_windowborders == 0) ? "0=off"
5941.                 : (iflags.wc2_windowborders == 1) ? "1=on"
5942.                   : (iflags.wc2_windowborders == 2) ? "2=auto"
5943.                     : defopt);
5944.     } else if (!strcmp(optname, "windowtype")) {
5945.         Sprintf(buf, "%s", windowprocs.name);
5946.     } else if (!strcmp(optname, "windowcolors")) {
5947.         Sprintf(
5948.             buf, "%s/%s %s/%s %s/%s %s/%s",
5949.             iflags.wc_foregrnd_menu ? iflags.wc_foregrnd_menu : defbrief,
5950.             iflags.wc_backgrnd_menu ? iflags.wc_backgrnd_menu : defbrief,
5951.             iflags.wc_foregrnd_message ? iflags.wc_foregrnd_message
5952.                                        : defbrief,
5953.             iflags.wc_backgrnd_message ? iflags.wc_backgrnd_message
5954.                                        : defbrief,
5955.             iflags.wc_foregrnd_status ? iflags.wc_foregrnd_status : defbrief,
5956.             iflags.wc_backgrnd_status ? iflags.wc_backgrnd_status : defbrief,
5957.             iflags.wc_foregrnd_text ? iflags.wc_foregrnd_text : defbrief,
5958.             iflags.wc_backgrnd_text ? iflags.wc_backgrnd_text : defbrief);
5959. #ifdef PREFIXES_IN_USE
5960.     } else {
5961.         for (i = 0; i < PREFIX_COUNT; ++i)
5962.             if (!strcmp(optname, fqn_prefix_names[i]) && fqn_prefix[i])
5963.                 Sprintf(buf, "%s", fqn_prefix[i]);
5964. #endif
5965.     }
5966. 
5967.     if (!buf[0])
5968.         Strcpy(buf, "unknown");
5969.     return buf;
5970. }
5971. 
5972. int
5973. dotogglepickup()
5974. {
5975.     char buf[BUFSZ], ocl[MAXOCLASSES + 1];
5976. 
5977.     flags.pickup = !flags.pickup;
5978.     if (flags.pickup) {
5979.         oc_to_str(flags.pickup_types, ocl);
5980.         Sprintf(buf, "ON, for %s objects%s", ocl[0] ? ocl : "all",
5981.                 (apelist)
5982.                     ? ((count_apes() == 1)
5983.                            ? ", with one exception"
5984.                            : ", with some exceptions")
5985.                     : "");
5986.     } else {
5987.         Strcpy(buf, "OFF");
5988.     }
5989.     pline("Autopickup: %s.", buf);
5990.     return 0;
5991. }
5992. 
5993. int
5994. add_autopickup_exception(mapping)
5995. const char *mapping;
5996. {
5997.     static const char
5998.         APE_regex_error[] = "regex error in AUTOPICKUP_EXCEPTION",
5999.         APE_syntax_error[] = "syntax error in AUTOPICKUP_EXCEPTION";
6000. 
6001.     struct autopickup_exception *ape;
6002.     char text[256], end;
6003.     int n;
6004.     boolean grab = FALSE;
6005. 
6006.     /* scan length limit used to be 255, but smaller size allows the
6007.        quoted value to fit within BUFSZ, simplifying formatting elsewhere;
6008.        this used to ignore the possibility of trailing junk but now checks
6009.        for it, accepting whitespace but rejecting anything else unless it
6010.        starts with '#" for a comment */
6011.     end = '\0';
6012.     if ((n = sscanf(mapping, "\"<%253[^\"]\" %c", text, &end)) == 1
6013.         || (n == 2 && end == '#')) {
6014.         grab = TRUE;
6015.     } else if ((n = sscanf(mapping, "\">%253[^\"]\" %c", text, &end)) == 1
6016.                || (n = sscanf(mapping, "\"%253[^\"]\" %c", text, &end)) == 1
6017.                || (n == 2 && end == '#')) {
6018.         grab = FALSE;
6019.     } else {
6020.         config_error_add("%s", APE_syntax_error);
6021.         return 0;
6022.     }
6023. 
6024.     ape = (struct autopickup_exception *) alloc(sizeof *ape);
6025.     ape->regex = regex_init();
6026.     if (!regex_compile(text, ape->regex)) {
6027.         config_error_add("%s: %s", APE_regex_error,
6028.                          regex_error_desc(ape->regex));
6029.         regex_free(ape->regex);
6030.         free((genericptr_t) ape);
6031.         return 0;
6032.     }
6033. 
6034.     ape->pattern = dupstr(text);
6035.     ape->grab = grab;
6036.     ape->next = apelist;
6037.     apelist = ape;
6038.     return 1;
6039. }
6040. 
6041. STATIC_OVL void
6042. remove_autopickup_exception(whichape)
6043. struct autopickup_exception *whichape;
6044. {
6045.     struct autopickup_exception *ape, *freeape, *prev = 0;
6046. 
6047.     for (ape = apelist; ape;) {
6048.         if (ape == whichape) {
6049.             freeape = ape;
6050.             ape = ape->next;
6051.             if (prev)
6052.                 prev->next = ape;
6053.             else
6054.                 apelist = ape;
6055.             regex_free(freeape->regex);
6056.             free((genericptr_t) freeape->pattern);
6057.             free((genericptr_t) freeape);
6058.         } else {
6059.             prev = ape;
6060.             ape = ape->next;
6061.         }
6062.     }
6063. }
6064. 
6065. void
6066. free_autopickup_exceptions()
6067. {
6068.     struct autopickup_exception *ape = apelist;
6069. 
6070.     while ((ape = apelist) != 0) {
6071.       regex_free(ape->regex);
6072.       free((genericptr_t) ape->pattern);
6073.       apelist = ape->next;
6074.       free((genericptr_t) ape);
6075.     }
6076. }
6077. 
6078. /* bundle some common usage into one easy-to-use routine */
6079. int
6080. load_symset(s, which_set)
6081. const char *s;
6082. int which_set;
6083. {
6084.     clear_symsetentry(which_set, TRUE);
6085. 
6086.     if (symset[which_set].name)
6087.         free((genericptr_t) symset[which_set].name);
6088.     symset[which_set].name = dupstr(s);
6089. 
6090.     if (read_sym_file(which_set)) {
6091.         switch_symbols(TRUE);
6092.     } else {
6093.         clear_symsetentry(which_set, TRUE);
6094.         return 0;
6095.     }
6096.     return 1;
6097. }
6098. 
6099. void
6100. free_symsets()
6101. {
6102.     clear_symsetentry(PRIMARY, TRUE);
6103.     clear_symsetentry(ROGUESET, TRUE);
6104. 
6105.     /* symset_list is cleaned up as soon as it's used, so we shouldn't
6106.        have to anything about it here */
6107.     /* assert( symset_list == NULL ); */
6108. }
6109. 
6110. /* Parse the value of a SYMBOLS line from a config file */
6111. boolean
6112. parsesymbols(opts, which_set)
6113. register char *opts;
6114. int which_set;
6115. {
6116.     int val;
6117.     char *op, *symname, *strval;
6118.     struct symparse *symp;
6119. 
6120.     if ((op = index(opts, ',')) != 0) {
6121.         *op++ = 0;
6122.         if (!parsesymbols(op, which_set))
6123.             return FALSE;
6124.     }
6125. 
6126.     /* S_sample:string */
6127.     symname = opts;
6128.     strval = index(opts, ':');
6129.     if (!strval)
6130.         strval = index(opts, '=');
6131.     if (!strval)
6132.         return FALSE;
6133.     *strval++ = '\0';
6134. 
6135.     /* strip leading and trailing white space from symname and strval */
6136.     mungspaces(symname);
6137.     mungspaces(strval);
6138. 
6139.     symp = match_sym(symname);
6140.     if (!symp)
6141.         return FALSE;
6142. 
6143.     if (symp->range && symp->range != SYM_CONTROL) {
6144.         val = sym_val(strval);
6145.         if (which_set == ROGUESET)
6146.             update_ov_rogue_symset(symp, val);
6147.         else
6148.             update_ov_primary_symset(symp, val);
6149.     }
6150.     return TRUE;
6151. }
6152. 
6153. struct symparse *
6154. match_sym(buf)
6155. char *buf;
6156. {
6157.     size_t len = strlen(buf);
6158.     const char *p = index(buf, ':'), *q = index(buf, '=');
6159.     struct symparse *sp = loadsyms;
6160. 
6161.     if (!p || (q && q < p))
6162.         p = q;
6163.     if (p) {
6164.         /* note: there will be at most one space before the '='
6165.            because caller has condensed buf[] with mungspaces() */
6166.         if (p > buf && p[-1] == ' ')
6167.             p--;
6168.         len = (int) (p - buf);
6169.     }
6170.     while (sp->range) {
6171.         if ((len >= strlen(sp->name)) && !strncmpi(buf, sp->name, len))
6172.             return sp;
6173.         sp++;
6174.     }
6175.     return (struct symparse *) 0;
6176. }
6177. 
6178. int
6179. sym_val(strval)
6180. const char *strval; /* up to 4*BUFSZ-1 long; only first few chars matter */
6181. {
6182.     char buf[QBUFSZ], tmp[QBUFSZ]; /* to hold trucated copy of 'strval' */
6183. 
6184.     buf[0] = '\0';
6185.     if (!strval[0] || !strval[1]) { /* empty, or single character */
6186.         /* if single char is space or tab, leave buf[0]=='\0' */
6187.         if (!isspace((uchar) strval[0]))
6188.             buf[0] = strval[0];
6189.     } else if (strval[0] == '\) { /* single quote */
6190.         /* simple matching single quote; we know strval[1] isn't '\0' */
6191.         if (strval[2] == '\ && !strval[3]) {
6192.             /* accepts '\' as backslash and  as single quote */
6193.             buf[0] = strval[1];
6194. 
6195.         /* if backslash, handle single or double quote or second backslash */
6196.         } else if (strval[1] == '\\' && strval[2] && strval[3] == '\
6197.             && index("'\"\\", strval[2]) && !strval[4]) {
6198.             buf[0] = strval[2];
6199. 
6200.         /* not simple quote or basic backslash;
6201.            strip closing quote and let escapes() deal with it */
6202.         } else {
6203.             char *p;
6204. 
6205.             /* +1: skip opening single quote */
6206.             (void) strncpy(tmp, strval + 1, sizeof tmp - 1);
6207.             tmp[sizeof tmp - 1] = '\0';
6208.             if ((p = rindex(tmp, '\)) != 0) {
6209.                 *p = '\0';
6210.                 escapes(tmp, buf);
6211.             } /* else buf[0] stays '\0' */
6212.         }
6213.     } else { /* not lone char nor single quote */
6214.         (void) strncpy(tmp, strval, sizeof tmp - 1);
6215.         tmp[sizeof tmp - 1] = '\0';
6216.         escapes(tmp, buf);
6217.     }
6218. 
6219.     return (int) *buf;
6220. }
6221. 
6222. /* data for option_help() */
6223. static const char *opt_intro[] = {
6224.     "",
6225.     "                 NetHack Options Help:", "",
6226. #define CONFIG_SLOT 3 /* fill in next value at run-time */
6227.     (char *) 0,
6228. #if !defined(MICRO) && !defined(MAC)
6229.     "or use `NETHACKOPTIONS=\"<options>\"' in your environment",
6230. #endif
6231.     "(<options> is a list of options separated by commas)",
6232. #ifdef VMS
6233.     "-- for example, $ DEFINE NETHACKOPTIONS \"noautopickup,fruit:kumquat\"",
6234. #endif
6235.     "or press \"O\" while playing and use the menu.",
6236.     "",
6237.  "Boolean options (which can be negated by prefixing them with '!' or \"no\"):",
6238.     (char *) 0
6239. };
6240. 
6241. static const char *opt_epilog[] = {
6242.     "",
6243.     "Some of the options can be set only before the game is started; those",
6244.     "items will not be selectable in the 'O' command's menu.",
6245.     (char *) 0
6246. };
6247. 
6248. void
6249. option_help()
6250. {
6251.     char buf[BUFSZ], buf2[BUFSZ];
6252.     register int i;
6253.     winid datawin;
6254. 
6255.     datawin = create_nhwindow(NHW_TEXT);
6256.     Sprintf(buf, "Set options as OPTIONS=<options> in %s", configfile);
6257.     opt_intro[CONFIG_SLOT] = (const char *) buf;
6258.     for (i = 0; opt_intro[i]; i++)
6259.         putstr(datawin, 0, opt_intro[i]);
6260. 
6261.     /* Boolean options */
6262.     for (i = 0; boolopt[i].name; i++) {
6263.         if (boolopt[i].addr) {
6264.             if (boolopt[i].addr == &iflags.sanity_check && !wizard)
6265.                 continue;
6266.             if (boolopt[i].addr == &iflags.menu_tab_sep && !wizard)
6267.                 continue;
6268.             next_opt(datawin, boolopt[i].name);
6269.         }
6270.     }
6271.     next_opt(datawin, "");
6272. 
6273.     /* Compound options */
6274.     putstr(datawin, 0, "Compound options:");
6275.     for (i = 0; compopt[i].name; i++) {
6276.         Sprintf(buf2, "`%s'", compopt[i].name);
6277.         Sprintf(buf, "%-20s - %s%c", buf2, compopt[i].descr,
6278.                 compopt[i + 1].name ? ',' : '.');
6279.         putstr(datawin, 0, buf);
6280.     }
6281. 
6282.     for (i = 0; opt_epilog[i]; i++)
6283.         putstr(datawin, 0, opt_epilog[i]);
6284. 
6285.     display_nhwindow(datawin, FALSE);
6286.     destroy_nhwindow(datawin);
6287.     return;
6288. }
6289. 
6290. /*
6291.  * prints the next boolean option, on the same line if possible, on a new
6292.  * line if not. End with next_opt("").
6293.  */
6294. void
6295. next_opt(datawin, str)
6296. winid datawin;
6297. const char *str;
6298. {
6299.     static char *buf = 0;
6300.     int i;
6301.     char *s;
6302. 
6303.     if (!buf)
6304.         *(buf = (char *) alloc(BUFSZ)) = '\0';
6305. 
6306.     if (!*str) {
6307.         s = eos(buf);
6308.         if (s > &buf[1] && s[-2] == ',')
6309.             Strcpy(s - 2, "."); /* replace last ", " */
6310.         i = COLNO;              /* (greater than COLNO - 2) */
6311.     } else {
6312.         i = strlen(buf) + strlen(str) + 2;
6313.     }
6314. 
6315.     if (i > COLNO - 2) { /* rule of thumb */
6316.         putstr(datawin, 0, buf);
6317.         buf[0] = 0;
6318.     }
6319.     if (*str) {
6320.         Strcat(buf, str);
6321.         Strcat(buf, ", ");
6322.     } else {
6323.         putstr(datawin, 0, str);
6324.         free((genericptr_t) buf), buf = 0;
6325.     }
6326.     return;
6327. }
6328. 
6329. /* Returns the fid of the fruit type; if that type already exists, it
6330.  * returns the fid of that one; if it does not exist, it adds a new fruit
6331.  * type to the chain and returns the new one.
6332.  * If replace_fruit is sent in, replace the fruit in the chain rather than
6333.  * adding a new entry--for user specified fruits only.
6334.  */
6335. int
6336. fruitadd(str, replace_fruit)
6337. char *str;
6338. struct fruit *replace_fruit;
6339. {
6340.     register int i;
6341.     register struct fruit *f;
6342.     int highest_fruit_id = 0, globpfx;
6343.     char buf[PL_FSIZ], altname[PL_FSIZ];
6344.     boolean user_specified = (str == pl_fruit);
6345.     /* if not user-specified, then it's a fruit name for a fruit on
6346.      * a bones level or from orctown raider's loot...
6347.      */
6348. 
6349.     /* Note: every fruit has an id (kept in obj->spe) of at least 1;
6350.      * 0 is an error.
6351.      */
6352.     if (user_specified) {
6353.         boolean found = FALSE, numeric = FALSE;
6354. 
6355.         /* force fruit to be singular; this handling is not
6356.            needed--or wanted--for fruits from bones because
6357.            they already received it in their original game;
6358.            str==pl_fruit but makesingular() creates a copy
6359.            so we need to copy that back into pl_fruit */
6360.         nmcpy(pl_fruit, makesingular(str), PL_FSIZ);
6361.         /* (assertion doesn't matter; we use 'pl_fruit' from here on out) */
6362.         /* assert( str == pl_fruit ); */
6363. 
6364.         /* disallow naming after other foods (since it'd be impossible
6365.          * to tell the difference); globs might have a size prefix which
6366.          * needs to be skipped in order to match the object type name
6367.          */
6368.         globpfx = (!strncmp(pl_fruit, "small ", 6)
6369.                    || !strncmp(pl_fruit, "large ", 6)) ? 6
6370.                   : (!strncmp(pl_fruit, "very large ", 11)) ? 11
6371.                     : 0;
6372.         for (i = bases[FOOD_CLASS]; objects[i].oc_class == FOOD_CLASS; i++) {
6373.             if (!strcmp(OBJ_NAME(objects[i]), pl_fruit)
6374.                 || (globpfx > 0
6375.                     && !strcmp(OBJ_NAME(objects[i]), &pl_fruit[globpfx]))) {
6376.                 found = TRUE;
6377.                 break;
6378.             }
6379.         }
6380.         if (!found) {
6381.             char *c;
6382. 
6383.             for (c = pl_fruit; *c >= '0' && *c <= '9'; c++)
6384.                 continue;
6385.             if (!*c || isspace((uchar) *c))
6386.                 numeric = TRUE;
6387.         }
6388.         if (found || numeric
6389.             /* these checks for applying food attributes to actual items
6390.                are case sensitive; "glob of foo" is caught by 'found'
6391.                if 'foo' is a valid glob; when not valid, allow it as-is */
6392.             || !strncmp(pl_fruit, "cursed ", 7)
6393.             || !strncmp(pl_fruit, "uncursed ", 9)
6394.             || !strncmp(pl_fruit, "blessed ", 8)
6395.             || !strncmp(pl_fruit, "partly eaten ", 13)
6396.             || (!strncmp(pl_fruit, "tin of ", 7)
6397.                 && (!strcmp(pl_fruit + 7, "spinach")
6398.                     || name_to_mon(pl_fruit + 7) >= LOW_PM))
6399.             || !strcmp(pl_fruit, "empty tin")
6400.             || (!strcmp(pl_fruit, "glob")
6401.                 || (globpfx > 0 && !strcmp("glob", &pl_fruit[globpfx])))
6402.             || ((str_end_is(pl_fruit, " corpse")
6403.                  || str_end_is(pl_fruit, " egg"))
6404.                 && name_to_mon(pl_fruit) >= LOW_PM)) {
6405.             Strcpy(buf, pl_fruit);
6406.             Strcpy(pl_fruit, "candied ");
6407.             nmcpy(pl_fruit + 8, buf, PL_FSIZ - 8);
6408.         }
6409.         *altname = '\0';
6410.         /* This flag indicates that a fruit has been made since the
6411.          * last time the user set the fruit.  If it hasn't, we can
6412.          * safely overwrite the current fruit, preventing the user from
6413.          * setting many fruits in a row and overflowing.
6414.          * Possible expansion: check for specific fruit IDs, not for
6415.          * any fruit.
6416.          */
6417.         flags.made_fruit = FALSE;
6418.         if (replace_fruit) {
6419.             /* replace_fruit is already part of the fruit chain;
6420.                update it in place rather than looking it up again */
6421.             f = replace_fruit;
6422.             copynchars(f->fname, pl_fruit, PL_FSIZ - 1);
6423.             goto nonew;
6424.         }
6425.     } else {
6426.         /* not user_supplied, so assumed to be from bones (or orc gang) */
6427.         copynchars(altname, str, PL_FSIZ - 1);
6428.         sanitize_name(altname);
6429.         flags.made_fruit = TRUE; /* for safety.  Any fruit name added from a
6430.                                   * bones level should exist anyway. */
6431.     }
6432.     f = fruit_from_name(*altname ? altname : str, FALSE, &highest_fruit_id);
6433.     if (f)
6434.         goto nonew;
6435. 
6436.     /* Maximum number of named fruits is 127, even if obj->spe can
6437.        handle bigger values.  If adding another fruit would overflow,
6438.        use a random fruit instead... we've got a lot to choose from.
6439.        current_fruit remains as is. */
6440.     if (highest_fruit_id >= 127)
6441.         return rnd(127);
6442. 
6443.     f = newfruit();
6444.     (void) memset((genericptr_t) f, 0, sizeof (struct fruit));
6445.     copynchars(f->fname, *altname ? altname : str, PL_FSIZ - 1);
6446.     f->fid = ++highest_fruit_id;
6447.     /* we used to go out of our way to add it at the end of the list,
6448.        but the order is arbitrary so use simpler insertion at start */
6449.     f->nextf = ffruit;
6450.     ffruit = f;
6451.  nonew:
6452.     if (user_specified)
6453.         context.current_fruit = f->fid;
6454.     return f->fid;
6455. }
6456. 
6457. /*
6458.  * This is a somewhat generic menu for taking a list of NetHack style
6459.  * class choices and presenting them via a description
6460.  * rather than the traditional NetHack characters.
6461.  * (Benefits users whose first exposure to NetHack is via tiles).
6462.  *
6463.  * prompt
6464.  *           The title at the top of the menu.
6465.  *
6466.  * category: 0 = monster class
6467.  *           1 = object  class
6468.  *
6469.  * way
6470.  *           FALSE = PICK_ONE, TRUE = PICK_ANY
6471.  *
6472.  * class_list
6473.  *           a null terminated string containing the list of choices.
6474.  *
6475.  * class_selection
6476.  *           a null terminated string containing the selected characters.
6477.  *
6478.  * Returns number selected.
6479.  */
6480. int
6481. choose_classes_menu(prompt, category, way, class_list, class_select)
6482. const char *prompt;
6483. int category;
6484. boolean way;
6485. char *class_list;
6486. char *class_select;
6487. {
6488.     menu_item *pick_list = (menu_item *) 0;
6489.     winid win;
6490.     anything any;
6491.     char buf[BUFSZ];
6492.     int i, n;
6493.     int ret;
6494.     int next_accelerator, accelerator;
6495. 
6496.     if (class_list == (char *) 0 || class_select == (char *) 0)
6497.         return 0;
6498.     accelerator = 0;
6499.     next_accelerator = 'a';
6500.     any = zeroany;
6501.     win = create_nhwindow(NHW_MENU);
6502.     start_menu(win);
6503.     while (*class_list) {
6504.         const char *text;
6505.         boolean selected;
6506. 
6507.         text = (char *) 0;
6508.         selected = FALSE;
6509.         switch (category) {
6510.         case 0:
6511.             text = def_monsyms[def_char_to_monclass(*class_list)].explain;
6512.             accelerator = *class_list;
6513.             Sprintf(buf, "%s", text);
6514.             break;
6515.         case 1:
6516.             text = def_oc_syms[def_char_to_objclass(*class_list)].explain;
6517.             accelerator = next_accelerator;
6518.             Sprintf(buf, "%c  %s", *class_list, text);
6519.             break;
6520.         default:
6521.             impossible("choose_classes_menu: invalid category %d", category);
6522.         }
6523.         if (way && *class_select) { /* Selections there already */
6524.             if (index(class_select, *class_list)) {
6525.                 selected = TRUE;
6526.             }
6527.         }
6528.         any.a_int = *class_list;
6529.         add_menu(win, NO_GLYPH, &any, accelerator, category ? *class_list : 0,
6530.                  ATR_NONE, buf, selected);
6531.         ++class_list;
6532.         if (category > 0) {
6533.             ++next_accelerator;
6534.             if (next_accelerator == ('z' + 1))
6535.                 next_accelerator = 'A';
6536.             if (next_accelerator == ('Z' + 1))
6537.                 break;
6538.         }
6539.     }
6540.     if (category == 1 && next_accelerator <= 'z') {
6541.         /* for objects, add "A - ' '  all classes", after a separator */
6542.         any = zeroany;
6543.         add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED);
6544.         any.a_int = (int) ' ';
6545.         Sprintf(buf, "%c  %s", (char) any.a_int, "all classes of objects");
6546.         /* we won't preselect this even if the incoming list is empty;
6547.            having it selected means that it would have to be explicitly
6548.            de-selected in order to select anything else */
6549.         add_menu(win, NO_GLYPH, &any, 'A', 0, ATR_NONE, buf, MENU_UNSELECTED);
6550.     }
6551.     end_menu(win, prompt);
6552.     n = select_menu(win, way ? PICK_ANY : PICK_ONE, &pick_list);
6553.     destroy_nhwindow(win);
6554.     if (n > 0) {
6555.         if (category == 1) {
6556.             /* for object classes, first check for 'all'; it means 'use
6557.                a blank list' rather than 'collect every possible choice' */
6558.             for (i = 0; i < n; ++i)
6559.                 if (pick_list[i].item.a_int == ' ') {
6560.                     pick_list[0].item.a_int = ' ';
6561.                     n = 1; /* return 1; also an implicit 'break;' */
6562.                 }
6563.         }
6564.         for (i = 0; i < n; ++i)
6565.             *class_select++ = (char) pick_list[i].item.a_int;
6566.         free((genericptr_t) pick_list);
6567.         ret = n;
6568.     } else if (n == -1) {
6569.         class_select = eos(class_select);
6570.         ret = -1;
6571.     } else
6572.         ret = 0;
6573.     *class_select = '\0';
6574.     return ret;
6575. }
6576. 
6577. static struct wc_Opt wc_options[] = {
6578.     { "ascii_map", WC_ASCII_MAP },
6579.     { "color", WC_COLOR },
6580.     { "eight_bit_tty", WC_EIGHT_BIT_IN },
6581.     { "hilite_pet", WC_HILITE_PET },
6582.     { "popup_dialog", WC_POPUP_DIALOG },
6583.     { "player_selection", WC_PLAYER_SELECTION },
6584.     { "preload_tiles", WC_PRELOAD_TILES },
6585.     { "tiled_map", WC_TILED_MAP },
6586.     { "tile_file", WC_TILE_FILE },
6587.     { "tile_width", WC_TILE_WIDTH },
6588.     { "tile_height", WC_TILE_HEIGHT },
6589.     { "use_inverse", WC_INVERSE },
6590.     { "align_message", WC_ALIGN_MESSAGE },
6591.     { "align_status", WC_ALIGN_STATUS },
6592.     { "font_map", WC_FONT_MAP },
6593.     { "font_menu", WC_FONT_MENU },
6594.     { "font_message", WC_FONT_MESSAGE },
6595. #if 0
6596.     {"perm_invent", WC_PERM_INVENT},
6597. #endif
6598.     { "font_size_map", WC_FONTSIZ_MAP },
6599.     { "font_size_menu", WC_FONTSIZ_MENU },
6600.     { "font_size_message", WC_FONTSIZ_MESSAGE },
6601.     { "font_size_status", WC_FONTSIZ_STATUS },
6602.     { "font_size_text", WC_FONTSIZ_TEXT },
6603.     { "font_status", WC_FONT_STATUS },
6604.     { "font_text", WC_FONT_TEXT },
6605.     { "map_mode", WC_MAP_MODE },
6606.     { "scroll_amount", WC_SCROLL_AMOUNT },
6607.     { "scroll_margin", WC_SCROLL_MARGIN },
6608.     { "splash_screen", WC_SPLASH_SCREEN },
6609.     { "vary_msgcount", WC_VARY_MSGCOUNT },
6610.     { "windowcolors", WC_WINDOWCOLORS },
6611.     { "mouse_support", WC_MOUSE_SUPPORT },
6612.     { (char *) 0, 0L }
6613. };
6614. static struct wc_Opt wc2_options[] = {
6615.     { "fullscreen", WC2_FULLSCREEN },
6616.     { "softkeyboard", WC2_SOFTKEYBOARD },
6617.     { "wraptext", WC2_WRAPTEXT },
6618.     { "use_darkgray", WC2_DARKGRAY },
6619.     { "hitpointbar", WC2_HITPOINTBAR },
6620.     { "hilite_status", WC2_HILITE_STATUS },
6621.     /* name shown in 'O' menu is different */
6622.     { "status hilite rules", WC2_HILITE_STATUS },
6623.     /* statushilites doesn't have its own bit */
6624.     { "statushilites", WC2_HILITE_STATUS },
6625.     { "term_cols", WC2_TERM_SIZE },
6626.     { "term_rows", WC2_TERM_SIZE },
6627.     { "petattr", WC2_PETATTR },
6628.     { "guicolor", WC2_GUICOLOR },
6629.     { "statuslines", WC2_STATUSLINES },
6630.     { "windowborders", WC2_WINDOWBORDERS },
6631.     { (char *) 0, 0L }
6632. };
6633. 
6634. /*
6635.  * If a port wants to change or ensure that the SET_IN_SYS,
6636.  * SET_IN_FILE, DISP_IN_GAME, or SET_IN_GAME status of an option is
6637.  * correct (for controlling its display in the option menu) call
6638.  * set_option_mod_status()
6639.  * with the appropriate second argument.
6640.  */
6641. void
6642. set_option_mod_status(optnam, status)
6643. const char *optnam;
6644. int status;
6645. {
6646.     int k;
6647. 
6648.     if (SET__IS_VALUE_VALID(status)) {
6649.         impossible("set_option_mod_status: status out of range %d.", status);
6650.         return;
6651.     }
6652.     for (k = 0; boolopt[k].name; k++) {
6653.         if (!strncmpi(boolopt[k].name, optnam, strlen(optnam))) {
6654.             boolopt[k].optflags = status;
6655.             return;
6656.         }
6657.     }
6658.     for (k = 0; compopt[k].name; k++) {
6659.         if (!strncmpi(compopt[k].name, optnam, strlen(optnam))) {
6660.             compopt[k].optflags = status;
6661.             return;
6662.         }
6663.     }
6664. }
6665. 
6666. /*
6667.  * You can set several wc_options in one call to
6668.  * set_wc_option_mod_status() by setting
6669.  * the appropriate bits for each option that you
6670.  * are setting in the optmask argument
6671.  * prior to calling.
6672.  *    example: set_wc_option_mod_status(WC_COLOR|WC_SCROLL_MARGIN,
6673.  * SET_IN_GAME);
6674.  */
6675. void
6676. set_wc_option_mod_status(optmask, status)
6677. unsigned long optmask;
6678. int status;
6679. {
6680.     int k = 0;
6681. 
6682.     if (SET__IS_VALUE_VALID(status)) {
6683.         impossible("set_wc_option_mod_status: status out of range %d.",
6684.                    status);
6685.         return;
6686.     }
6687.     while (wc_options[k].wc_name) {
6688.         if (optmask & wc_options[k].wc_bit) {
6689.             set_option_mod_status(wc_options[k].wc_name, status);
6690.         }
6691.         k++;
6692.     }
6693. }
6694. 
6695. STATIC_OVL boolean
6696. is_wc_option(optnam)
6697. const char *optnam;
6698. {
6699.     int k = 0;
6700. 
6701.     while (wc_options[k].wc_name) {
6702.         if (strcmp(wc_options[k].wc_name, optnam) == 0)
6703.             return TRUE;
6704.         k++;
6705.     }
6706.     return FALSE;
6707. }
6708. 
6709. STATIC_OVL boolean
6710. wc_supported(optnam)
6711. const char *optnam;
6712. {
6713.     int k;
6714. 
6715.     for (k = 0; wc_options[k].wc_name; ++k) {
6716.         if (!strcmp(wc_options[k].wc_name, optnam))
6717.             return (windowprocs.wincap & wc_options[k].wc_bit) ? TRUE : FALSE;
6718.     }
6719.     return FALSE;
6720. }
6721. 
6722. /*
6723.  * You can set several wc2_options in one call to
6724.  * set_wc2_option_mod_status() by setting
6725.  * the appropriate bits for each option that you
6726.  * are setting in the optmask argument
6727.  * prior to calling.
6728.  *    example:
6729.  * set_wc2_option_mod_status(WC2_FULLSCREEN|WC2_SOFTKEYBOARD|WC2_WRAPTEXT,
6730.  * SET_IN_FILE);
6731.  */
6732. 
6733. void
6734. set_wc2_option_mod_status(optmask, status)
6735. unsigned long optmask;
6736. int status;
6737. {
6738.     int k = 0;
6739. 
6740.     if (SET__IS_VALUE_VALID(status)) {
6741.         impossible("set_wc2_option_mod_status: status out of range %d.",
6742.                    status);
6743.         return;
6744.     }
6745.     while (wc2_options[k].wc_name) {
6746.         if (optmask & wc2_options[k].wc_bit) {
6747.             set_option_mod_status(wc2_options[k].wc_name, status);
6748.         }
6749.         k++;
6750.     }
6751. }
6752. 
6753. STATIC_OVL boolean
6754. is_wc2_option(optnam)
6755. const char *optnam;
6756. {
6757.     int k = 0;
6758. 
6759.     while (wc2_options[k].wc_name) {
6760.         if (strcmp(wc2_options[k].wc_name, optnam) == 0)
6761.             return TRUE;
6762.         k++;
6763.     }
6764.     return FALSE;
6765. }
6766. 
6767. STATIC_OVL boolean
6768. wc2_supported(optnam)
6769. const char *optnam;
6770. {
6771.     int k;
6772. 
6773.     for (k = 0; wc2_options[k].wc_name; ++k) {
6774.         if (!strcmp(wc2_options[k].wc_name, optnam))
6775.             return (windowprocs.wincap2 & wc2_options[k].wc_bit) ? TRUE
6776.                                                                  : FALSE;
6777.     }
6778.     return FALSE;
6779. }
6780. 
6781. STATIC_OVL void
6782. wc_set_font_name(opttype, fontname)
6783. int opttype;
6784. char *fontname;
6785. {
6786.     char **fn = (char **) 0;
6787. 
6788.     if (!fontname)
6789.         return;
6790.     switch (opttype) {
6791.     case MAP_OPTION:
6792.         fn = &iflags.wc_font_map;
6793.         break;
6794.     case MESSAGE_OPTION:
6795.         fn = &iflags.wc_font_message;
6796.         break;
6797.     case TEXT_OPTION:
6798.         fn = &iflags.wc_font_text;
6799.         break;
6800.     case MENU_OPTION:
6801.         fn = &iflags.wc_font_menu;
6802.         break;
6803.     case STATUS_OPTION:
6804.         fn = &iflags.wc_font_status;
6805.         break;
6806.     default:
6807.         return;
6808.     }
6809.     if (fn) {
6810.         if (*fn)
6811.             free((genericptr_t) *fn);
6812.         *fn = dupstr(fontname);
6813.     }
6814.     return;
6815. }
6816. 
6817. STATIC_OVL int
6818. wc_set_window_colors(op)
6819. char *op;
6820. {
6821.     /* syntax:
6822.      *  menu white/black message green/yellow status white/blue text
6823.      * white/black
6824.      */
6825.     int j;
6826.     char buf[BUFSZ];
6827.     char *wn, *tfg, *tbg, *newop;
6828.     static const char *wnames[] = { "menu", "message", "status", "text" };
6829.     static const char *shortnames[] = { "mnu", "msg", "sts", "txt" };
6830.     static char **fgp[] = { &iflags.wc_foregrnd_menu,
6831.                             &iflags.wc_foregrnd_message,
6832.                             &iflags.wc_foregrnd_status,
6833.                             &iflags.wc_foregrnd_text };
6834.     static char **bgp[] = { &iflags.wc_backgrnd_menu,
6835.                             &iflags.wc_backgrnd_message,
6836.                             &iflags.wc_backgrnd_status,
6837.                             &iflags.wc_backgrnd_text };
6838. 
6839.     Strcpy(buf, op);
6840.     newop = mungspaces(buf);
6841.     while (newop && *newop) {
6842.         wn = tfg = tbg = (char *) 0;
6843. 
6844.         /* until first non-space in case there's leading spaces - before
6845.          * colorname*/
6846.         if (*newop == ' ')
6847.             newop++;
6848.         if (*newop)
6849.             wn = newop;
6850.         else
6851.             return 0;
6852. 
6853.         /* until first space - colorname*/
6854.         while (*newop && *newop != ' ')
6855.             newop++;
6856.         if (*newop)
6857.             *newop = '\0';
6858.         else
6859.             return 0;
6860.         newop++;
6861. 
6862.         /* until first non-space - before foreground*/
6863.         if (*newop == ' ')
6864.             newop++;
6865.         if (*newop)
6866.             tfg = newop;
6867.         else
6868.             return 0;
6869. 
6870.         /* until slash - foreground */
6871.         while (*newop && *newop != '/')
6872.             newop++;
6873.         if (*newop)
6874.             *newop = '\0';
6875.         else
6876.             return 0;
6877.         newop++;
6878. 
6879.         /* until first non-space (in case there's leading space after slash) -
6880.          * before background */
6881.         if (*newop == ' ')
6882.             newop++;
6883.         if (*newop)
6884.             tbg = newop;
6885.         else
6886.             return 0;
6887. 
6888.         /* until first space - background */
6889.         while (*newop && *newop != ' ')
6890.             newop++;
6891.         if (*newop)
6892.             *newop++ = '\0';
6893. 
6894.         for (j = 0; j < 4; ++j) {
6895.             if (!strcmpi(wn, wnames[j]) || !strcmpi(wn, shortnames[j])) {
6896.                 if (tfg && !strstri(tfg, " ")) {
6897.                     if (*fgp[j])
6898.                         free((genericptr_t) *fgp[j]);
6899.                     *fgp[j] = dupstr(tfg);
6900.                 }
6901.                 if (tbg && !strstri(tbg, " ")) {
6902.                     if (*bgp[j])
6903.                         free((genericptr_t) *bgp[j]);
6904.                     *bgp[j] = dupstr(tbg);
6905.                 }
6906.                 break;
6907.             }
6908.         }
6909.     }
6910.     return 1;
6911. }
6912. 
6913. /* set up for wizard mode if player or save file has requested to it;
6914.    called from port-specific startup code to handle `nethack -D' or
6915.    OPTIONS=playmode:debug, or from dorecover()'s restgamestate() if
6916.    restoring a game which was saved in wizard mode */
6917. void
6918. set_playmode()
6919. {
6920.     if (wizard) {
6921.         if (authorize_wizard_mode())
6922.             Strcpy(plname, "wizard");
6923.         else
6924.             wizard = FALSE; /* not allowed or not available */
6925.         /* force explore mode if we didn't make it into wizard mode */
6926.         discover = !wizard;
6927.         iflags.deferred_X = FALSE;
6928.     }
6929.     /* don't need to do anything special for explore mode or normal play */
6930. }
6931. 
6932. #endif /* OPTION_LISTS_ONLY */
6933. 
6934. /*options.c*/