Source:NetHack 5.0.0/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 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/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 5.0	options.c	$NHDT-Date: 1737556914 2025/01/22 06:41:54 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.753 $ */
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. #ifndef OPTION_LISTS_ONLY
7. #include "hack.h"
8. #include "tcap.h"
9. #else /* OPTION_LISTS_ONLY: (AMIGA) external program for opt lists */
10. #include "config.h"
11. #include "objclass.h"
12. #include "flag.h"
13. NEARDATA struct flag flags; /* provide linkage */
14. NEARDATA struct instance_flags iflags; /* provide linkage */
15. NEARDATA struct accessibility_data a11y;
16. #define static
17. #endif
18. 
19. #define BACKWARD_COMPAT
20. #define COMPLAIN_ABOUT_PRAYCONFIRM
21. 
22. /* whether the 'msg_window' option is used to control ^P behavior */
23. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS)
24. #define PREV_MSGS 1
25. #else
26. #define PREV_MSGS 0
27. #endif
28. 
29. /*
30.  *  NOTE:  If you add (or delete) an option, please review the following:
31.  *             doc/options.txt
32.  *
33.  *         It contains how-to info and outlines some required/suggested
34.  *         updates that should accompany your change.
35.  */
36. 
37. /*
38.  * include/optlist.h is utilized 3 successive times, for 3 different
39.  * objectives.
40.  *
41.  * The first time is with NHOPT_PROTO defined, to produce and include
42.  * the prototypes for the individual option processing functions.
43.  *
44.  * The second time is with NHOPT_ENUM defined, to produce the enum values
45.  * for the individual options that are used throughout options processing.
46.  * They are generally opt_optname, where optname is the name of the option.
47.  *
48.  * The third time is with NHOPT_PARSE defined, to produce the initializers
49.  * to fill out the allopt[] array of options (both boolean and compound).
50.  *
51.  */
52. 
53. #define OPTIONS_C
54. 
55. #define NHOPT_PROTO
56. #include "optlist.h"
57. #undef NHOPT_PROTO
58. 
59. #define NHOPT_PARSE
60. static struct allopt_t allopt_init[] = {
61. #include "optlist.h"
62.     {(const char *) 0, OptS_Advanced, 0, 0, 0, set_in_sysconf, BoolOpt,
63.      No, No, No, No, Term_False, 0, (boolean *) 0,
64.      (int (*)(int, int, boolean, char *, char *)) 0,
65.      (char *) 0, (const char *) 0, (const char *) 0, 0, 0, 0, TRUE }
66. };
67. #undef NHOPT_PARSE
68. 
69. #undef OPTIONS_C
70. 
71. #define PILE_LIMIT_DFLT 5
72. #define rolestring(val, array, field) \
73.     ((val >= 0) ? array[val].field : (val == ROLE_RANDOM) ? randomrole : none)
74. 
75. enum window_option_types {
76.     MESSAGE_OPTION = 1,
77.     STATUS_OPTION,
78.     MAP_OPTION,
79.     MENU_OPTION,
80.     TEXT_OPTION
81. };
82. 
83. enum optn_result {
84.     optn_silenterr = -1, optn_err = 0, optn_ok
85. };
86. enum requests {
87.     do_nothing, do_init, do_set, do_handler, get_val, get_cnf_val
88. };
89. 
90. static struct allopt_t allopt[SIZE(allopt_init)];
91. 
92. #ifndef OPTION_LISTS_ONLY
93. 
94. /* use rest of file */
95. 
96. /* extern char configfile[]; */ /* for messages; files.c */
97. extern const struct symparse loadsyms[];
98. #if defined(TOS)
99. extern boolean colors_changed;  /* in tos.c */
100. #endif
101. #ifdef VIDEOSHADES
102. extern char *shade[3];          /* in sys/msdos/video.c */
103. extern char ttycolors[CLR_MAX]; /* in sys/msdos/video.c */
104. #endif
105. 
106. static char empty_optstr[] = { '\0' };
107. static boolean duplicate, using_alias;
108. static boolean give_opt_msg = TRUE;
109. 
110. enum { MAX_ROLEOPT = 4 };  /* 4: role,race,gend,algn */
111. static boolean opt_set_in_config[OPTCOUNT];
112. static char *roleoptvals[MAX_ROLEOPT][num_opt_phases];
113. 
114. static NEARDATA const char *OptS_type[OptS_Advanced+1] = {
115.     "General", "Behavior", "Map", "Status", "Advanced"
116. };
117. 
118. static const char def_inv_order[MAXOCLASSES] = {
119.     COIN_CLASS, AMULET_CLASS, WEAPON_CLASS, ARMOR_CLASS, FOOD_CLASS,
120.     SCROLL_CLASS, SPBOOK_CLASS, POTION_CLASS, RING_CLASS, WAND_CLASS,
121.     TOOL_CLASS, GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, 0,
122. };
123. 
124. static const char none[] = "(none)", randomrole[] = "random",
125.                   to_be_done[] = "(to be done)",
126.                   defopt[] = "default", defbrief[] = "def";
127. 
128. /* paranoia[] - used by parseoptions() and handler_paranoid_confirmation() */
129. static const struct paranoia_opts {
130.     int flagmask;        /* which paranoid option */
131.     const char *argname; /* primary name */
132.     int argMinLen;       /* minimum number of letters to match */
133.     const char *synonym; /* alternate name (optional) */
134.     int synMinLen;
135.     const char *explain; /* for interactive menu */
136. } paranoia[] = {
137.     /* there are some initial-letter conflicts: "a"ttack vs "A"utoall vs
138.        "a"ll, "attack" takes precedence and "all" isn't present in the
139.        interactive menu with "Autoall" capitalized there,
140.        and "d"ie vs "d"eath, synonyms for each other so doesn't matter;
141.        (also "p"ray vs "P"aranoia, "pray" takes precedence since "Paranoia"
142.        is just a synonym for "Confirm"); "b"ones vs "br"eak-wand, the
143.        latter requires at least two letters; "e"at vs "ex"plore,
144.        "cont"inue eating vs "C"onfirm; "wand"-break vs "Were"-change,
145.        both require at least two letters during config processing but use
146.        one letter with case-sensitivity for 'm O's interactive menu;
147.        if any entry or alias beginning with 'n' gets added, aside from "none",
148.        the parsing to accept "nofoo" to mean "!foo" will need fixing */
149.     { PARANOID_CONFIRM, "Confirm", 1, "Paranoia", 2,
150.       "for \"yes\" confirmations, require \"no\" to reject" },
151.     { PARANOID_QUIT, "quit", 1, "explore", 2,
152.       "yes vs y to quit or to enter explore mode" },
153.     { PARANOID_DIE, "die", 1, "death", 2,
154.       "yes vs y to die (explore mode or debug mode)" },
155.     { PARANOID_BONES, "bones", 1, 0, 0,
156.       "yes vs y to save bones data when dying in debug mode" },
157.     { PARANOID_HIT, "attack", 1, "hit", 1,
158.       "yes vs y to attack a peaceful monster" },
159.     { PARANOID_BREAKWAND, "wand-break", 2, "break-wand", 2,
160.       "yes vs y to break a wand via (a)pply" },
161.     { PARANOID_EATING, "eat", 1, "continue", 4,
162.       "yes vs y to continue eating after first bite when satiated" },
163.     { PARANOID_WERECHANGE, "Were-change", 2, (const char *) 0, 0,
164.       "yes vs y to change form when lycanthropy is controllable" },
165.     /* extra y/n questions rather than changing y/n to yes/n[o];
166.        they switch to yes/no if paranoid:confirm is also set */
167.     { PARANOID_PRAY, "pray", 1, 0, 0,
168.       "y required to pray (supersedes old \"prayconfirm\" option)" },
169.     { PARANOID_TRAP, "trap", 1, "move-trap", 1,
170.       "y required to enter known trap unless considered harmless" },
171.     { PARANOID_AUTOALL, "Autoall", 2, "autoselect-all", 2,
172.       "y required to pick filter choice 'A' for menustyle:Full" },
173.     /* not a yes/n[o] vs y/n change nor a y/n addition */
174.     { PARANOID_SWIM, "swim", 1, 0, 0,
175.       "'m' prefix necessary to deliberately walk into lava or water" },
176.     { PARANOID_REMOVE, "Remove", 1, "Takeoff", 1,
177.       /* normally when there is only 1 candidate it's chosen automatically */
178.       "always pick from inventory for Remove and Takeoff" },
179.     /* for config file parsing; interactive menu skips these */
180.     { 0, "none", 4, 0, 0, 0 }, /* require full word match */
181.     { ~0, "all", 3, 0, 0, 0 }, /* ditto */
182. };
183. 
184. static NEARDATA const char *menutype[][3] = { /* 'menustyle' settings */
185.     { "traditional",  "[prompt for object class(es), then",
186.                       " ask y/n for each item in those classes]" },
187.     { "combination",  "[prompt for object class(es), then",
188.                       " use menu for items in those classes]" },
189.     { "full",         "[use menu to choose class(es), then",
190.                       " use another menu for items in those]" },
191.     { "partial",      "[skip class filtering; always",
192.                       " use menu of all available items]" }
193. };
194. #if PREV_MSGS /* tty supports all four settings, curses just final two */
195. static NEARDATA const char *msgwind[][3] = { /* 'msg_window' settings */
196.     { "single",       "[show one old message at a time,",
197.                       " most recent first]" },
198.     { "combination",  "[for consecutive ^P requests, use",
199.                       " 'single' for first two, then 'full']" },
200.     { "full",         "[show all available messages,",
201.                       " oldest first and most recent last]" },
202.     { "reversed",     "[show all available messages,",
203.                       " most recent first]" }
204. };
205. #endif
206. /* autounlock settings */
207. static NEARDATA const char *unlocktypes[][2] = {
208.     { "untrap",    "(might fail)" },
209.     { "apply-key", "" },
210.     { "kick",      "(doors only)" },
211.     { "force",     "(chests/boxes only)" },
212. };
213. static NEARDATA const char *burdentype[] = {
214.     "unencumbered", "burdened",     "stressed",
215.     "strained",     "overtaxed",    "overloaded"
216. };
217. static NEARDATA const char *runmodes[] = {
218.     "teleport",     "run",          "walk",     "crawl"
219. };
220. static NEARDATA const char *sortltype[] = {
221.     "none",         "loot",         "full"
222. };
223. /* second column is an alias for the first; third is brief explanation;
224.    entries 5 and 6 are 1|4 and 2|4 (tty only) */
225. static NEARDATA const char *perminv_modes[][3] = {
226.   /*0*/ { "none",      "off",        "no permanent inventory window" },
227.   /*1*/ { "all" ,      "on",         "all inventory except for gold" },
228.   /*2*/ { "full",      "gold",       "full inventory including gold" },
229.   /*3*/ { NULL,        NULL,         NULL },
230.   /*4*/ { NULL,        NULL,         NULL },
231. #ifdef TTY_PERM_INVENT
232.   /*5*/ { "on+grid",   "all+grid",   "all except gold, plus unused letters" },
233.   /*6*/ { "gold+grid", "full+grid",  "full inventory, plus unused letters" },
234. #else
235.   /*5*/ { NULL,        NULL,         NULL },
236.   /*6*/ { NULL,        NULL,         NULL },
237. #endif
238.   /*7*/ { NULL,        NULL,         NULL },
239.   /*8*/ { "in-use",    "inuse-only", "subset: items currently in use" },
240. };
241. 
242. struct objsymopt {
243.     int num;
244.     const char *nam;
245.     const char *descr;
246. };
247. 
248. /*
249.  * menuobjsyms:
250.  *   Inventory display for the various values of menuobjsyms.
251.  *   4' and 5' represent !sortpack which lacks headers; they
252.  *   produce the same result.
253.  *
254.  *   0:                         1:
255.  *        Weapons                    Weapons  (')')
256.  *        a - 15 darts               a - 15 darts
257.  *        Armor                      Armor    ('[')
258.  *        b - Hawaiian shirt         b - Hawaiian shirt
259.  *   2:                         3:
260.  *        Weapons                    Weapons  (')')
261.  *        a ) 15 darts               a ) 15 darts
262.  *        Armor                      Armor    ('[')
263.  *        b [ Hawaiian shirt         b [ Hawaiian shirt
264.  *   4:                         5:
265.  *        Weapons                    Weapons  (')')
266.  *        a - 15 darts               a - 15 darts
267.  *        Armor                      Armor    ('[')
268.  *        b - Hawaiian shirt         b - Hawaiian shirt
269.  *   4':                        5':
270.  *        a ) 15 darts               a ) 15 darts
271.  *        b [ Hawaiian shirt         b [ Hawaiian shirt
272.  */
273. static const struct objsymopt objsymvals[] = {
274.     { 0, "none",         "don't show object symbols in menus" },
275.     { 1, "headers",      "show object symbols in menu header lines" },
276.     { 2, "entries",      "show object symbols in individual menu entries" },
277.     { 3, "both",         "show object symbols in headers and menu entries" },
278.     { 4, "conditional",  "show objsyms in entries if no headers are shown" },
279.     { 5, "one-or-other", "show objsyms in header, in entries if no header" },
280. };
281. 
282. /*
283.  * Default menu manipulation command accelerators.  These may _not_ be:
284.  *
285.  *      + a number or '#' - reserved for counts
286.  *      + an upper or lower case US ASCII letter - used for accelerators
287.  *      + ESC - reserved for escaping the menu
288.  *      + NULL, CR or LF - reserved for committing the selection(s).  NULL
289.  *        is kind of odd, but the tty's xwaitforspace() will return it if
290.  *        someone hits a <ret>.
291.  *      + a default object class symbol - used for object class accelerators
292.  *
293.  * Standard letters (for now) are:
294.  *
295.  *              <  back 1 page
296.  *              >  forward 1 page
297.  *              ^  first page
298.  *              |  last page
299.  *              :  search
300.  *
301.  *              page            all
302.  *               ,    select     .
303.  *               \    deselect   -
304.  *               ~    invert     @
305.  *
306.  * The command name list is duplicated in the compopt array.
307.  */
308. typedef struct {
309.     const char *name;
310.     char cmd;
311.     const char *desc;
312. } menu_cmd_t;
313. 
314. static const menu_cmd_t default_menu_cmd_info[] = {
315.     { "menu_next_page",     MENU_NEXT_PAGE,     "Go to next page" },
316.     { "menu_previous_page", MENU_PREVIOUS_PAGE, "Go to previous page" },
317.     { "menu_first_page",    MENU_FIRST_PAGE,    "Go to first page" },
318.     { "menu_last_page",     MENU_LAST_PAGE,     "Go to last page" },
319.     { "menu_select_all",    MENU_SELECT_ALL,
320.                             "Select all items in entire menu" },
321.     { "menu_invert_all",    MENU_INVERT_ALL,
322.                             "Invert selection for all items" },
323.     { "menu_deselect_all",  MENU_UNSELECT_ALL,
324.                             "Unselect all items in entire menu" },
325.     { "menu_select_page",   MENU_SELECT_PAGE,
326.                             "Select all items on current page" },
327.     { "menu_invert_page",   MENU_INVERT_PAGE,
328.                             "Invert current page's selections" },
329.     { "menu_deselect_page", MENU_UNSELECT_PAGE,
330.                             "Unselect all items on current page" },
331.     { "menu_search",        MENU_SEARCH,
332.                             "Search and invert matching items" },
333.     { "menu_shift_right",   MENU_SHIFT_RIGHT,
334.                             "Pan current page to right (perm_invent only)" },
335.     { "menu_shift_left",    MENU_SHIFT_LEFT,
336.                             "Pan current page to left (perm_invent only)" },
337.     { (char *) 0, '\0', (char *) 0 }
338. };
339. 
340. static const char n_currently_set[] = "(%d currently set)";
341. 
342. staticfn void nmcpy(char *, const char *, int);
343. staticfn void escapes(const char *, char *);
344. staticfn void rejectoption(const char *);
345. staticfn char *string_for_opt(char *, boolean);
346. staticfn char *string_for_env_opt(const char *, char *, boolean);
347. staticfn void bad_negation(const char *, boolean);
348. staticfn void set_menuobjsyms_flags(int);
349. staticfn int change_inv_order(char *);
350. staticfn boolean warning_opts(char *, const char *);
351. staticfn int feature_alert_opts(char *, const char *);
352. staticfn boolean duplicate_opt_detection(int);
353. staticfn void complain_about_duplicate(int);
354. staticfn int length_without_val(const char *, int len);
355. staticfn void determine_ambiguities(void);
356. staticfn int check_misc_menu_command(char *, char *);
357. staticfn int opt2roleopt(int);
358. staticfn char *getoptstr(int, int);
359. staticfn void saveoptstr(int, const char *);
360. staticfn void unsaveoptstr(int, int);
361. staticfn int petname_optfn(int, int, boolean, char *, char *);
362. staticfn int shared_menu_optfn(int, int, boolean, char *, char *);
363. staticfn int spcfn_misc_menu_cmd(int, int, boolean, char *, char *);
364. 
365. staticfn const char * msgtype2name(int);
366. staticfn int query_msgtype(void);
367. staticfn boolean msgtype_add(int, char *);
368. staticfn void free_one_msgtype(int);
369. staticfn int msgtype_count(void);
370. staticfn boolean test_regex_pattern(const char *, const char *);
371. staticfn boolean parse_role_opt(int, boolean, const char *, char *, char **);
372. staticfn char *get_cnf_role_opt(int);
373. staticfn unsigned int longest_option_name(int, int);
374. staticfn int doset_simple_menu(void);
375. staticfn void reset_needed_visuals(void);
376. staticfn void doset_add_menu(winid, const char *, const char *, int, int);
377. staticfn int handle_add_list_remove(const char *, int);
378. staticfn void all_options_conds(strbuf_t *);
379. staticfn void all_options_menucolors(strbuf_t *);
380. staticfn void all_options_msgtypes(strbuf_t *);
381. staticfn void all_options_apes(strbuf_t *);
382. #ifdef CHANGE_COLOR
383. staticfn void all_options_palette(strbuf_t *);
384. #endif
385. staticfn void remove_autopickup_exception(struct autopickup_exception *);
386. staticfn int count_apes(void);
387. staticfn int count_cond(void);
388. staticfn void enhance_menu_text(char *, size_t, int, boolean *,
389.                                 struct allopt_t *);
390. staticfn boolean can_set_perm_invent(void);
391. staticfn int handler_align_misc(int);
392. staticfn int handler_autounlock(int);
393. staticfn int handler_disclose(void);
394. staticfn int handler_menu_headings(void);
395. staticfn int handler_menu_objsyms(void);
396. staticfn int handler_menustyle(void);
397. staticfn int handler_msg_window(void);
398. staticfn int handler_number_pad(void);
399. staticfn int handler_paranoid_confirmation(void);
400. staticfn int handler_perminv_mode(void);
401. staticfn int handler_pickup_burden(void);
402. staticfn int handler_pickup_types(void);
403. staticfn int handler_runmode(void);
404. staticfn int handler_petattr(void);
405. staticfn int handler_sortloot(void);
406. staticfn int handler_symset(int);
407. staticfn int handler_versinfo(void);
408. staticfn int handler_whatis_coord(void);
409. staticfn int handler_whatis_filter(void);
410. /* next few are not allopt[] entries, so will only be called
411.    directly from doset, not from individual optfn's */
412. staticfn int handler_autopickup_exception(void);
413. staticfn int handler_menu_colors(void);
414. staticfn int handler_msgtype(void);
415. staticfn int handler_windowborders(void);
416. 
417. staticfn boolean is_wc_option(const char *);
418. staticfn boolean wc_supported(const char *);
419. staticfn boolean is_wc2_option(const char *);
420. staticfn boolean wc2_supported(const char *);
421. staticfn void wc_set_font_name(int, char *);
422. staticfn int wc_set_window_colors(char *);
423. staticfn boolean illegal_menu_cmd_key(uchar);
424. staticfn const char *term_for_boolean(int, boolean *);
425. 
426. /* ask user if they want a tutorial, except if tutorial boolean option has
427.    been set in config - either on or off - in which case just obey that
428.    setting without asking */
429. boolean
430. ask_do_tutorial(void)
431. {
432.     boolean dotut = flags.tutorial;
433. 
434.     if (!opt_set_in_config[opt_tutorial]) {
435.         winid win;
436.         menu_item *sel;
437.         anything any;
438.         char buf[BUFSZ];
439.         const char *rc;
440.         boolean norc;
441.         int n, pass = 0;
442. 
443.         rc = nh_basename(get_configfile(), TRUE);
444.         norc = !strcmp(get_configfile(), "/dev/null");
445.         Snprintf(buf, sizeof buf,
446.                  "Put \"OPTIONS=!tutorial\" in %s to skip this query.",
447.                  (rc && *rc && !norc) ? rc : "your configuration file");
448.         do {
449.             win = create_nhwindow(NHW_MENU);
450.             start_menu(win, MENU_BEHAVE_STANDARD);
451.             any = cg.zeroany;
452.             any.a_char = 'y';
453.             add_menu(win, &nul_glyphinfo, &any, any.a_char, 0,
454.                      ATR_NONE, NO_COLOR,
455.                      "Yes, do a tutorial", MENU_ITEMFLAGS_NONE);
456.             any.a_char = 'n';
457.             add_menu(win, &nul_glyphinfo, &any, any.a_char, 0,
458.                      ATR_NONE, NO_COLOR,
459.                      "No, just start play", MENU_ITEMFLAGS_NONE);
460. 
461.             add_menu_str(win, "");
462.             add_menu_str(win, buf);
463.             if (pass++) /* we'll get here after <space> or <return> */
464.                 add_menu_str(win, "(Please choose 'y' or 'n'.)");
465. 
466.             end_menu(win, "Do you want a tutorial?");
467. 
468.             n = select_menu(win, PICK_ONE, &sel);
469.             destroy_nhwindow(win);
470.         } while (!n);
471.         if (n > 0) {
472.             dotut = (sel[0].item.a_char == 'y');
473.             free((genericptr_t) sel);
474.         } else { /* ESC */
475.             dotut = FALSE;
476.         }
477.     }
478.     return dotut;
479. }
480. 
481. /*
482.  **********************************
483.  *
484.  *   parseoptions
485.  *
486.  **********************************
487.  */
488. boolean
489. parseoptions(
490.     char *opts,
491.     boolean tinitial,
492.     boolean tfrom_file)
493. {
494.     char *op;
495.     boolean negated, got_match = FALSE, pfx_match = FALSE;
496. #if 0
497.     boolean has_val = FALSE;
498. #endif
499.     int i, matchidx = -1, optresult = optn_err, optlen, optlen_wo_val;
500.     boolean retval = TRUE;
501. 
502.     duplicate = FALSE;
503.     using_alias = FALSE;
504.     go.opt_initial = tinitial;
505.     go.opt_from_file = tfrom_file;
506.     /*
507.      * Process elements of comma-separated list in right to left order.
508.      * When some options are set interactively--notably various compound
509.      * options that issue a prompt for a value--they use parseoptions()
510.      * to handle setting the new value.  For those, 'tinitial' is False
511.      * and if user tries to supply a comma-separated list, it will be
512.      * treated as part of the current option, probably failing to parse.
513.      */
514.     if (tinitial && (op = strchr(opts, ',')) != 0) {
515.         *op++ = 0;
516.         /* current element remains pending while the rest of the line gets
517.            handled recursively; if the rest of line contains any commas,
518.            then the process will recurse deeper as it is processed */
519.         if (!parseoptions(op, go.opt_initial, go.opt_from_file))
520.             retval = FALSE;
521.     }
522.     if (strlen(opts) > BUFSZ / 2) {
523.         config_error_add("Option too long, max length is %i characters",
524.                          (BUFSZ / 2));
525.         return FALSE;
526.     }
527. 
528.     /* strip leading and trailing white space */
529.     while (isspace((uchar) *opts))
530.         opts++;
531.     op = eos(opts);
532.     while (--op >= opts && isspace((uchar) *op))
533.         *op = '\0';
534. 
535.     if (!*opts) {
536.         config_error_add("Empty statement");
537.         return FALSE;
538.     }
539.     negated = FALSE;
540.     while ((*opts == '!') || !strncmpi(opts, "no", 2)) {
541.         opts += (*opts == '!') ? 1 : (opts[2] != '-') ? 2 : 3;
542.         negated = !negated;
543.     }
544.     optlen = (int) strlen(opts);
545.     optlen_wo_val = length_without_val(opts, optlen);
546.     if (optlen_wo_val < optlen) {
547. #if 0
548.         has_val = TRUE;
549. #endif
550.         optlen = optlen_wo_val;
551. #if 0
552.     } else {
553.         has_val = FALSE;
554. #endif
555.     }
556. 
557.     for (i = 0; i < OPTCOUNT; ++i) {
558.         got_match = FALSE;
559. 
560.         if (allopt[i].pfx) {
561.             if (str_start_is(opts, allopt[i].name, TRUE)) {
562.                 matchidx = i;
563.                 got_match = pfx_match = TRUE;
564.             }
565.         }
566. #if 0   /* this prevents "boolopt:True" &c */
567.         if (!got_match) {
568.             if (has_val && !allopt[i].valok)
569.                 continue;
570.         }
571. #endif
572.         /*
573.          * During option initialization, the function
574.          *     determine_ambiguities()
575.          * figured out exactly how many characters are required to
576.          * unambiguously differentiate one option from all others, and it
577.          * placed that number into each option's allopt[n].minmatch.
578.          *
579.          */
580.         if (!got_match && allopt[i].name)
581.             got_match = match_optname(opts, allopt[i].name,
582.                                       allopt[i].minmatch, TRUE);
583.         if (got_match) {
584.             if (!allopt[i].pfx && optlen < allopt[i].minmatch) {
585.                 config_error_add(
586.              "Ambiguous option %s, %d characters are needed to differentiate",
587.                                  opts, allopt[i].minmatch);
588.                 break;
589.             }
590.             matchidx = i;
591.             break;
592.         }
593.     }
594. 
595.     if (!got_match) {
596.         /* spin through the aliases to see if there's a match in those.
597.            Note that if multiple delimited aliases for the same option
598.            becomes desirable in the future, this is where you'll need
599.            to split a delimited allopt[i].alias field into each
600.            individual alias */
601. 
602.         for (i = 0; i < OPTCOUNT; ++i) {
603.             if (!allopt[i].alias)
604.                 continue;
605.             got_match = match_optname(opts, allopt[i].alias,
606.                                       (int) strlen(allopt[i].alias),
607.                                       TRUE);
608.             if (got_match) {
609.                 matchidx = i;
610.                 using_alias = TRUE;
611.                 break;
612.             }
613.         }
614.     }
615. 
616.     /* allow optfn's to test whether they were called from parseoptions() */
617.     program_state.in_parseoptions++;
618. 
619.     if (got_match && (matchidx >= 0 && matchidx < OPTCOUNT)
620.                       && !allopt[matchidx].disregarded) {
621.         duplicate = duplicate_opt_detection(matchidx);
622.         if (duplicate && !allopt[matchidx].dupeok)
623.             complain_about_duplicate(matchidx);
624. 
625.         /* check for bad negation, so option functions don't have to */
626.         if (negated && !allopt[matchidx].negateok) {
627.             bad_negation(allopt[matchidx].name, TRUE);
628.             return optn_err;
629.         }
630. 
631.         /*
632.          * Now call the option's associated function via the function
633.          * pointer for it in the allopt[] array, specifying a 'do_set' req.
634.          */
635.         if (allopt[matchidx].optfn) {
636.             op = string_for_opt(opts, TRUE);
637.             optresult = (*allopt[matchidx].optfn)(allopt[matchidx].idx,
638.                                                   do_set, negated, opts, op);
639.             if (optresult == optn_ok)
640.                 opt_set_in_config[matchidx] = TRUE;
641.         }
642.     }
643. 
644.     if (program_state.in_parseoptions > 0)
645.         program_state.in_parseoptions--;
646. 
647. #if 0
648.     /* This specialization shouldn't be needed any longer because each of
649.        the individual options is part of the allopts[] list, thus already
650.        taken care of in the for-loop above */
651.     if (!got_match) {
652.         int res = check_misc_menu_command(opts, op);
653. 
654.         if (res >= 0)
655.             optresult = spcfn_misc_menu_cmd(res, do_set, negated, opts, op);
656.         if (optresult == optn_ok)
657.             got_match = TRUE;
658.     }
659. #endif
660. 
661.     if (!got_match) {
662.         /* Is it a symbol? */
663.         if (strstr(opts, "S_") == opts && parsesymbols(opts, PRIMARYSET)) {
664.             switch_symbols(TRUE);
665.             check_gold_symbol();
666.             optresult = optn_ok;
667.         }
668.     }
669. 
670.     if (optresult == optn_silenterr
671.         || (got_match && allopt[matchidx].disregarded)
672.             || (!got_match && config_unmatched_ignored()))
673.         return FALSE;
674.     if (pfx_match && optresult == optn_err) {
675.         char pfxbuf[BUFSZ], *pfxp;
676. 
677.         Snprintf(pfxbuf, sizeof pfxbuf, "%s", opts);
678.         if ((pfxp = strchr(pfxbuf, ':')) != 0)
679.             *pfxp = '\0';
680.         config_error_add("bad option suffix variation '%s'", pfxbuf);
681.         return FALSE;
682.     }
683.     if (got_match && optresult == optn_err)
684.         return FALSE;
685.     if (optresult == optn_ok)
686.         return retval;
687. 
688.     /* out of valid options */
689.     config_error_add("Unknown option '%s'", opts);
690.     return FALSE;
691. }
692. 
693. staticfn int
694. check_misc_menu_command(char *opts, char *op UNUSED)
695. {
696.     int i;
697.     const char *name_to_check;
698. 
699.     /* check for menu command mapping */
700.     for (i = 0; default_menu_cmd_info[i].name; i++) {
701.         name_to_check = default_menu_cmd_info[i].name;
702.         if (match_optname(opts, name_to_check,
703.                           (int) strlen(name_to_check), TRUE))
704.             return i;
705.     }
706.     return -1;
707. }
708. 
709. static int roleopt2opt[4] = {
710.     opt_role, opt_race, opt_gender, opt_alignment
711. };
712. 
713. /* role => 0, race => 1, gender => 2, alignment =>3 */
714. staticfn int
715. opt2roleopt(int roleopt)
716. {
717.     switch (roleopt) {
718.     case opt_role:
719.         return 0;
720.     case opt_race:
721.         return 1;
722.     case opt_gender:
723.         return 2;
724.     case opt_alignment:
725.         return 3;
726.     default:
727.         break;
728.     }
729.     return 0;
730. }
731. 
732. /* fetch saved option string for a particular option phase */
733. staticfn char *
734. getoptstr(int optidx, int ophase)
735. {
736.     int roleoptindx = opt2roleopt(optidx);
737. 
738.     if (ophase == num_opt_phases) { /* any source */
739.         int phase;
740. 
741.         /* find non-Null, in order optvals[][play_opt], [cmdline_opt],
742.            [environ_opt], [rc_file_opt], [syscf_opt], [builtin_opt] */
743.         for (phase = num_opt_phases - 1; phase >= 0; --phase)
744.             if (roleoptvals[roleoptindx][phase]) {
745.                 ophase = phase;
746.                 break;
747.             }
748.     }
749.     if ((roleoptindx >= 0 && roleoptindx < MAX_ROLEOPT
750.           && ophase >= 0 && ophase < num_opt_phases))
751.         return roleoptvals[roleoptindx][ophase];
752.     panic("bad index roleoptvals[%d][%d]", roleoptindx, ophase);
753.     /*NOTREACHED*/
754. }
755. 
756. /* to track some unparsed option settings in case #saveoptions needs them */
757. staticfn void
758. saveoptstr(int optidx, const char *optstr)
759. {
760.     int phase = go.opt_phase, roleoptindx = opt2roleopt(optidx);
761.     const char *p = strchr(optstr, ':'), *q = strchr(optstr, '=');
762. 
763.     /* strip away "optname:" from optname:optstr */
764.     if (!p || (q && q < p))
765.         p = q;
766.     if (p)
767.         optstr = p + 1;
768. 
769.     if (roleoptvals[roleoptindx][phase])
770.         free((genericptr_t) roleoptvals[roleoptindx][phase]);
771.     roleoptvals[roleoptindx][phase] = dupstr(optstr);
772. }
773. 
774. /* discard specific saved option string */
775. staticfn void
776. unsaveoptstr(int optidx, int ophase)
777. {
778.     int roleoptindx = opt2roleopt(optidx);
779. 
780.     if (roleoptvals[roleoptindx][ophase])
781.         free((genericptr_t) roleoptvals[roleoptindx][ophase]),
782.         roleoptvals[roleoptindx][ophase] = 0;
783. }
784. 
785. /* discard all saved option strings */
786. void
787. freeroleoptvals(void)
788. {
789.     int i, j;
790. 
791.     for (i = 0; i < 4; ++i)
792.         for (j = 0; j < num_opt_phases; ++j)
793.             unsaveoptstr(roleopt2opt[i], j);
794. }
795. 
796. #if 0   /* not needed */
797. 
798. /* put roleoptvals[][] into save file; will be needed if #saveoptions
799.    takes place after restore */
800. void
801. saveoptvals(NHFILE *nhfp)
802. {
803.     if (update_file(nhfp)) {
804.         char *val;
805.         unsigned len;
806.         int i, j;
807. 
808.         for (i = 0; i < 4; ++i)
809.             for (j = 0; j < num_opt_phases; ++j) {
810.                 val = roleoptvals[i][j];
811.                 len = val ? Strlen(val) + 1 : 0;
812.                 Sfo_unsigned(nhfp, &len, "optvals-len");
813.                 if (val)
814.                     Sfo_char(nhfp, val, "optvals-val", len);
815.             }
816.     }
817.     if (release_data(nhfp))
818.         freeroleoptvals();
819. }
820. 
821. /* get roleoptvals[][] from save file */
822. void
823. restoptvals(NHFILE *nhfp)
824. {
825.     char *val;
826.     unsigned len;
827.     int i, j;
828. 
829.     if (nhfp->structlevel) {
830.         for (i = 0; i < 4; ++i)
831.             for (j = 0; j < num_opt_phases; ++j) {
832.                 /* len includes terminating '\0' for non-Null values */
833.                 Sfi_unsigned(nhfp, &len, "optvals-len");
834.                 if (len) {
835.                     val = roleoptvals[i][j] = (char *) alloc(len);
836.                     Sfi_char(nhfp, val, "opvals-val", (int) len);
837.                 } else {
838.                     roleoptvals[i][j] = NULL;
839.                 }
840.             }
841.     }
842. }
843. 
844. #endif /* 0 */
845. 
846. /* common to optfn_catname(), optfn_dogname(), optfn_horsename() */
847. staticfn int
848. petname_optfn(
849.     int optidx, int req,
850.     boolean negated,
851.     char *opts, char *op)
852. {
853.     char failsafe[PL_PSIZ + 1];
854.     char *petname = (optidx == opt_catname) ? gc.catname
855.                     : (optidx == opt_dogname) ? gd.dogname
856.                       : (optidx == opt_horsename) ? gh.horsename
857.                         : failsafe;
858. 
859.     if (req == do_init) {
860.         ;
861.     } else if (req == do_set) {
862.         if (op == empty_optstr && !negated)
863.             return optn_err;
864.         if (negated || !strcmp(op, "none") || !strcmp(op, none))
865.             op = empty_optstr;
866.         nmcpy(petname, op, PL_PSIZ);
867.         sanitize_name(petname);
868.     } else if (req == get_val || req == get_cnf_val) {
869.         failsafe[0] = '\0';
870.         Sprintf(opts, "%s", *petname ? petname
871.                             : (req == get_cnf_val) ? "none" : none);
872.     }
873.     return optn_ok;
874. }
875. 
876. /*
877.  **********************************
878.  *
879.  *   Per-option Functions
880.  *
881.  **********************************
882.  */
883. 
884. staticfn int
885. optfn_alignment(
886.     int optidx,
887.     int req,
888.     boolean negated,
889.     char *opts,
890.     char *op)
891. {
892.     if (req == do_init) {
893.         return optn_ok;
894.     }
895.     if (req == do_set) {
896.         /* alignment:string */
897.         if (!parse_role_opt(optidx, negated, allopt[optidx].name, opts, &op))
898.             return optn_silenterr;
899. 
900.         if (*op != '!') {
901.             if ((flags.initalign = str2align(op)) == ROLE_NONE) {
902.                 config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
903.                 return optn_err;
904.             }
905.             saveoptstr(optidx, rolestring(flags.initalign, aligns, adj));
906.         }
907.         return optn_ok;
908.     }
909.     if (req == get_val) {
910.         Sprintf(opts, "%s", rolestring(flags.initalign, aligns, adj));
911.         return optn_ok;
912.     }
913.     if (req == get_cnf_val) {
914.         op = get_cnf_role_opt(optidx);
915.         Strcpy(opts, op ? op : "none");
916.         return optn_ok;
917.     }
918.     return optn_ok;
919. }
920. 
921. 
922. staticfn int
923. optfn_align_message(
924.     int optidx, int req, boolean negated,
925.     char *opts, char *op)
926. {
927.     if (req == do_init) {
928.         return optn_ok;
929.     }
930.     if (req == do_set) {
931.         /* WINCAP align_message:[left|top|right|bottom] */
932. 
933.         op = string_for_opt(opts, negated);
934.         if ((op != empty_optstr) && !negated) {
935.             if (!strncmpi(op, "left", sizeof "left" - 1))
936.                 iflags.wc_align_message = ALIGN_LEFT;
937.             else if (!strncmpi(op, "top", sizeof "top" - 1))
938.                 iflags.wc_align_message = ALIGN_TOP;
939.             else if (!strncmpi(op, "right", sizeof "right" - 1))
940.                 iflags.wc_align_message = ALIGN_RIGHT;
941.             else if (!strncmpi(op, "bottom", sizeof "bottom" - 1))
942.                 iflags.wc_align_message = ALIGN_BOTTOM;
943.             else {
944.                 config_error_add("Unknown %s parameter '%s'",
945.                                  allopt[optidx].name, op);
946.                 return optn_err;
947.             }
948.         } else if (negated) {
949.             bad_negation(allopt[optidx].name, TRUE);
950.             return optn_err;
951.         }
952.         return optn_ok;
953.     }
954.     if (req == get_val || req == get_cnf_val) {
955.         int which;
956. 
957.         which = iflags.wc_align_message;
958.         Sprintf(opts, "%s",
959.                 (which == ALIGN_TOP) ? "top"
960.                 : (which == ALIGN_LEFT) ? "left"
961.                   : (which == ALIGN_BOTTOM) ? "bottom"
962.                     : (which == ALIGN_RIGHT) ? "right"
963.                       : defopt);
964.         return optn_ok;
965.     }
966.     if (req == do_handler) {
967.         return handler_align_misc(optidx);
968.     }
969.     return optn_ok;
970. }
971. 
972. staticfn int
973. optfn_align_status(
974.     int optidx, int req, boolean negated,
975.     char *opts, char *op)
976. {
977.     if (req == do_init) {
978.         return optn_ok;
979.     }
980.     if (req == do_set) {
981.         /* WINCAP align_status:[left|top|right|bottom] */
982.         op = string_for_opt(opts, negated);
983.         if ((op != empty_optstr) && !negated) {
984.             if (!strncmpi(op, "left", sizeof "left" - 1))
985.                 iflags.wc_align_status = ALIGN_LEFT;
986.             else if (!strncmpi(op, "top", sizeof "top" - 1))
987.                 iflags.wc_align_status = ALIGN_TOP;
988.             else if (!strncmpi(op, "right", sizeof "right" - 1))
989.                 iflags.wc_align_status = ALIGN_RIGHT;
990.             else if (!strncmpi(op, "bottom", sizeof "bottom" - 1))
991.                 iflags.wc_align_status = ALIGN_BOTTOM;
992.             else {
993.                 config_error_add("Unknown %s parameter '%s'",
994.                                  allopt[optidx].name, op);
995.                 return optn_err;
996.             }
997.         } else if (negated) {
998.             bad_negation(allopt[optidx].name, TRUE);
999.             return optn_err;
1000.         }
1001.         return optn_ok;
1002.     }
1003.     if (req == get_val || req == get_cnf_val) {
1004.         int which;
1005. 
1006.         which = iflags.wc_align_status;
1007.         Sprintf(opts, "%s",
1008.                 (which == ALIGN_TOP) ? "top"
1009.                 : (which == ALIGN_LEFT) ? "left"
1010.                   : (which == ALIGN_BOTTOM) ? "bottom"
1011.                     : (which == ALIGN_RIGHT) ? "right"
1012.                       : defopt);
1013.         return optn_ok;
1014.     }
1015.     if (req == do_handler) {
1016.         return handler_align_misc(optidx);
1017.     }
1018.     return optn_ok;
1019. }
1020. 
1021. staticfn int
1022. optfn_altkeyhandling(
1023.     int optidx UNUSED,
1024.     int req,
1025.     boolean negated,
1026.     char *opts,
1027.     char *op)
1028. {
1029.     if (req == do_init) {
1030.         return optn_ok;
1031.     }
1032.     if (req == do_set) {
1033.         /* altkeyhandling:string */
1034. 
1035. #if defined(WIN32CON) && defined(TTY_GRAPHICS)
1036.         if (op == empty_optstr || negated)
1037.             return optn_err;
1038.         set_altkeyhandling(op);
1039. #else
1040.         nhUse(negated);
1041.         nhUse(op);
1042. #endif
1043.         return optn_ok;
1044.     }
1045.     if (req == get_val || req == get_cnf_val) {
1046.         opts[0] = '\0';
1047. #ifdef WIN32
1048.         Sprintf(opts, "%s",
1049.                 (iflags.key_handling == nh340_keyhandling)
1050.                     ? "340"
1051.                     : (iflags.key_handling == ray_keyhandling)
1052.                         ? "ray"
1053.                         : "default");
1054. #endif
1055.         return optn_ok;
1056.     }
1057. #ifdef WIN32CON
1058.     if (req == do_handler) {
1059.         return set_keyhandling_via_option();
1060.     }
1061. #endif
1062.     return optn_ok;
1063. }
1064. 
1065. staticfn int
1066. optfn_autounlock(
1067.     int optidx,
1068.     int req,
1069.     boolean negated,
1070.     char *opts,
1071.     char *op)
1072. {
1073.     if (req == do_init) {
1074.         flags.autounlock = AUTOUNLOCK_APPLY_KEY;
1075.         return optn_ok;
1076.     }
1077.     if (req == do_set) {
1078.         /* autounlock:none or autounlock:untrap+apply-key+kick+force;
1079.            autounlock without a value is same as autounlock:apply-key and
1080.            !autounlock is same as autounlock:none; multiple values can be
1081.            space separated or plus-sign separated but the same separation
1082.            must be used for each element, not mix&match */
1083.         char sep, *nxt;
1084.         unsigned newflags;
1085.         int i;
1086. 
1087.         if ((op = string_for_opt(opts, TRUE)) == empty_optstr) {
1088.             flags.autounlock = negated ? 0 : AUTOUNLOCK_APPLY_KEY;
1089.             return optn_ok;
1090.         }
1091.         newflags = 0;
1092.         sep = strchr(op, '+') ? '+' : ' ';
1093.         while (op) {
1094.             boolean matched = FALSE;
1095.             op = trimspaces(op); /* might have leading space */
1096.             if ((nxt = strchr(op, sep)) != 0) {
1097.                 *nxt++ = '\0';
1098.                 op = trimspaces(op); /* might have trailing space after
1099.                                       * plus sign removal */
1100.             }
1101.             if (str_start_is("none", op, TRUE))
1102.                 negated = TRUE, matched = TRUE;
1103.             for (i = 0; i < SIZE(unlocktypes) && !matched; ++i) {
1104.                 if (str_start_is(unlocktypes[i][0], op, TRUE)
1105.                     /* fuzzymatch() doesn't match leading substrings but
1106.                        this allows "apply_key" and "applykey" to match
1107.                        "apply-key"; "apply key" too if part of foo+bar */
1108.                     || fuzzymatch(op, unlocktypes[i][0], " -_", TRUE)) {
1109.                     matched = TRUE;
1110.                     switch (*op) {
1111.                     case 'u':
1112.                         newflags |= AUTOUNLOCK_UNTRAP;
1113.                         break;
1114.                     case 'a':
1115.                         newflags |= AUTOUNLOCK_APPLY_KEY;
1116.                         break;
1117.                     case 'k':
1118.                         newflags |= AUTOUNLOCK_KICK;
1119.                         break;
1120.                     case 'f':
1121.                         newflags |= AUTOUNLOCK_FORCE;
1122.                         break;
1123.                     default:
1124.                         matched = FALSE;
1125.                         break;
1126.                     }
1127.                 }
1128.             }
1129.             if (!matched) {
1130.                 config_error_add("Invalid value for \"%s\": \"%s\"",
1131.                                  allopt[optidx].name, op);
1132.                 return optn_silenterr;
1133.             }
1134.             op = nxt;
1135.         }
1136.         if (negated && newflags != 0) {
1137.             config_error_add(
1138.                      "Invalid value combination for \"%s\": 'none' with some",
1139.                              allopt[optidx].name);
1140.             return optn_silenterr;
1141.         }
1142.         flags.autounlock = newflags;
1143.         return optn_ok;
1144.     }
1145.     if (req == get_val || req == get_cnf_val) {
1146.         if (!flags.autounlock) {
1147.             Strcpy(opts, "none");
1148.         } else {
1149.             static const char plus[] = " + ";
1150.             const char *p = "";
1151. 
1152.             *opts = '\0';
1153.             if (flags.autounlock & AUTOUNLOCK_UNTRAP)
1154.                 Sprintf(eos(opts), "%s%s", p, unlocktypes[0][0]), p = plus;
1155.             if (flags.autounlock & AUTOUNLOCK_APPLY_KEY)
1156.                 Sprintf(eos(opts), "%s%s", p, unlocktypes[1][0]), p = plus;
1157.             if (flags.autounlock & AUTOUNLOCK_KICK)
1158.                 Sprintf(eos(opts), "%s%s", p, unlocktypes[2][0]), p = plus;
1159.             if (flags.autounlock & AUTOUNLOCK_FORCE)
1160.                 Sprintf(eos(opts), "%s%s", p, unlocktypes[3][0]); /*no more p*/
1161.         }
1162.         return optn_ok;
1163.     }
1164.     if (req == do_handler) {
1165.         return handler_autounlock(optidx);
1166.     }
1167.     return optn_ok;
1168. }
1169. 
1170. staticfn int
1171. optfn_boulder(
1172.     int optidx UNUSED, int req, boolean negated UNUSED,
1173.     char *opts, char *op UNUSED)
1174. {
1175. #ifdef BACKWARD_COMPAT
1176.     int clash = 0;
1177. #endif
1178. 
1179.     if (req == do_init) {
1180.         return optn_ok;
1181.     }
1182.     if (req == do_set) {
1183.         /* boulder:symbol */
1184. 
1185. #ifdef BACKWARD_COMPAT
1186. 
1187.         /* if ((opts = string_for_env_opt(allopt[optidx].name, opts, FALSE))
1188.                == empty_optstr)
1189.          */
1190.         if ((opts = string_for_opt(opts, FALSE)) == empty_optstr)
1191.             return FALSE;
1192.         escapes(opts, opts);
1193.         /* note: dummy monclass #0 has symbol value '\0'; we allow that--
1194.            attempting to set bouldersym to '^@'/'\0' will reset to default */
1195.         if (def_char_to_monclass(opts[0]) != MAXMCLASSES)
1196.             clash = opts[0] ? 1 : 0;
1197.         else if (opts[0] >= '1' && opts[0] < WARNCOUNT + '0')
1198.             clash = 2;
1199.         if (opts[0] < ' ') {
1200.             config_error_add("boulder symbol cannot be a control character");
1201.             return optn_ok;
1202.         } else if (clash) {
1203.             /* symbol chosen matches a used monster or warning
1204.                symbol which is not good - reject it */
1205.             config_error_add("Badoption - boulder symbol '%s' would conflict "
1206.                              "with a %s symbol",
1207.                              visctrl(opts[0]),
1208.                              (clash == 1) ? "monster" : "warning");
1209.         } else {
1210.             /*
1211.              * Override the default boulder symbol.
1212.              */
1213.             go.ov_primary_syms[SYM_BOULDER + SYM_OFF_X] = (nhsym) opts[0];
1214.             go.ov_rogue_syms[SYM_BOULDER + SYM_OFF_X] = (nhsym) opts[0];
1215.             /* for 'initial', update of BOULDER symbol is done in
1216.                initoptions_finish(), after all symset options
1217.                have been processed */
1218.             if (!go.opt_initial) {
1219.                 nhsym sym = get_othersym(SYM_BOULDER,
1220.                                          Is_rogue_level(&u.uz) ? ROGUESET
1221.                                                                : PRIMARYSET);
1222. 
1223.                 if (sym)
1224.                     gs.showsyms[SYM_BOULDER + SYM_OFF_X] = sym;
1225.                 go.opt_need_redraw = TRUE;
1226.             }
1227.         }
1228.         return optn_ok;
1229. #else
1230.         config_error_add("'%s' no longer supported; use S_boulder:c instead",
1231.                          allopt[optidx].name);
1232.         return optn_err;
1233. #endif
1234.     }
1235.     if (req == get_val || req == get_cnf_val) {
1236.         opts[0] = '\0';
1237. #ifdef BACKWARD_COMPAT
1238.         Sprintf(opts, "%c",
1239.                 go.ov_primary_syms[SYM_BOULDER + SYM_OFF_X]
1240.                   ? go.ov_primary_syms[SYM_BOULDER + SYM_OFF_X]
1241.                   : gs.showsyms[(int) objects[BOULDER].oc_class + SYM_OFF_O]);
1242. #endif
1243.         return optn_ok;
1244.     }
1245.     return optn_ok;
1246. }
1247. 
1248. staticfn int
1249. optfn_catname(
1250.     int optidx, int req,
1251.     boolean negated,
1252.     char *opts, char *op)
1253. {
1254.     return petname_optfn(optidx, req, negated, opts, op);
1255. }
1256. 
1257. #ifdef CRASHREPORT
1258. staticfn int
1259. optfn_crash_email(
1260.     int optidx UNUSED, int req, boolean negated UNUSED,
1261.     char *opts, char *op)
1262. {
1263.     if (req == do_init) {
1264.         return optn_ok;
1265.     }
1266.     if (req == do_set) {
1267.         if ((op = string_for_opt(opts, FALSE)) == empty_optstr)
1268.             return optn_err;
1269.         if (gc.crash_email)
1270.             free((genericptr_t) gc.crash_email);
1271.         gc.crash_email = dupstr(op);
1272.         return optn_ok;
1273.     }
1274.     if (req == get_val || req == get_cnf_val) {
1275.         if (!opts)
1276.             return optn_err;
1277.         if (gc.crash_email)
1278.             Sprintf(opts, "%s", gc.crash_email);
1279.         return optn_ok;
1280.     }
1281.     return optn_ok;
1282. }
1283. 
1284. staticfn int
1285. optfn_crash_name(
1286.     int optidx UNUSED, int req, boolean negated UNUSED,
1287.     char *opts, char *op)
1288. {
1289.     if (req == do_init) {
1290.         return optn_ok;
1291.     }
1292.     if (req == do_set) {
1293.         if ((op = string_for_opt(opts, FALSE)) == empty_optstr)
1294.             return optn_err;
1295.         if (gc.crash_name)
1296.             free((genericptr_t) gc.crash_name);
1297.         gc.crash_name = dupstr(op);
1298.         return optn_ok;
1299.     }
1300.     if (req == get_val || req == get_cnf_val) {
1301.         if (!opts)
1302.             return optn_err;
1303.         if (gc.crash_name)
1304.             Sprintf(opts, "%s", gc.crash_name);
1305.         return optn_ok;
1306.     }
1307.     return optn_ok;
1308. }
1309. 
1310. staticfn int
1311. optfn_crash_urlmax(
1312.     int optidx UNUSED, int req, boolean negated UNUSED,
1313.     char *opts, char *op)
1314. {
1315.     if (req == do_init) {
1316.         return optn_ok;
1317.     }
1318.     if (req == do_set) {
1319.         if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
1320.             int temp = atoi(op);
1321. 
1322.             if (temp < 75){
1323.                 config_error_add("Invalid value %d for crash_urlmax. "
1324.                                  " Minimum value is 75.", temp);
1325.                 return optn_err;
1326.             }
1327.             gc.crash_urlmax = temp;
1328.         } else
1329.             return optn_err;
1330.         return optn_ok;
1331.     }
1332.     if (req == get_val || req == get_cnf_val) {
1333.         if (!opts)
1334.             return optn_err;
1335.         Sprintf(opts, "%d", gc.crash_urlmax);
1336.         return optn_ok;
1337.     }
1338.     return optn_ok;
1339. }
1340. 
1341. #endif /* CRASHREPORT */
1342. 
1343. #ifdef CURSES_GRAPHICS
1344. staticfn int
1345. optfn_cursesgraphics(
1346.     int optidx, int req, boolean negated,
1347.     char *opts, char *op UNUSED)
1348. {
1349. #ifdef BACKWARD_COMPAT
1350.     boolean badflag = FALSE;
1351. #endif
1352. 
1353.     if (req == do_init) {
1354.         return optn_ok;
1355.     }
1356.     if (req == do_set) {
1357.         /* "cursesgraphics" */
1358. 
1359. #ifdef BACKWARD_COMPAT
1360.         if (!negated) {
1361.             /* There is no rogue level cursesgraphics-specific set */
1362.             if (gs.symset[PRIMARYSET].name) {
1363.                 badflag = TRUE;
1364.             } else {
1365.                 gs.symset[PRIMARYSET].name = dupstr(allopt[optidx].name);
1366.                 if (!read_sym_file(PRIMARYSET)) {
1367.                     badflag = TRUE;
1368.                     clear_symsetentry(PRIMARYSET, TRUE);
1369.                 } else
1370.                     switch_symbols(TRUE);
1371.             }
1372.             if (badflag) {
1373.                 config_error_add("Failure to load symbol set %s.",
1374.                                  allopt[optidx].name);
1375.                 return optn_err;
1376.             }
1377.         }
1378.         return optn_ok;
1379. #else
1380.         config_error_add("'%s' no longer supported; use 'symset:%s' instead",
1381.                          allopt[optidx].name, allopt[optidx].name);
1382.         return optn_err;
1383. #endif
1384.     }
1385.     if (req == get_val || req == get_cnf_val) {
1386.         opts[0] = '\0';
1387.         return optn_ok;
1388.     }
1389.     return optn_ok;
1390. }
1391. #endif
1392. 
1393. staticfn int
1394. optfn_DECgraphics(
1395.     int optidx, int req, boolean negated,
1396.     char *opts, char *op UNUSED)
1397. {
1398. #ifdef BACKWARD_COMPAT
1399.     boolean badflag = FALSE;
1400. #endif
1401. 
1402.     if (req == do_init) {
1403.         return optn_ok;
1404.     }
1405.     if (req == do_set) {
1406.         /* "DECgraphics" */
1407. 
1408. #ifdef BACKWARD_COMPAT
1409.         if (!negated) {
1410.             /* There is no rogue level DECgraphics-specific set */
1411.             if (gs.symset[PRIMARYSET].name) {
1412.                 badflag = TRUE;
1413.             } else {
1414.                 gs.symset[PRIMARYSET].name = dupstr(allopt[optidx].name);
1415.                 if (!read_sym_file(PRIMARYSET)) {
1416.                     badflag = TRUE;
1417.                     clear_symsetentry(PRIMARYSET, TRUE);
1418.                 } else
1419.                     switch_symbols(TRUE);
1420.             }
1421.             if (badflag) {
1422.                 config_error_add("Failure to load symbol set %s.",
1423.                                  allopt[optidx].name);
1424.                 return optn_err;
1425.             }
1426.         }
1427.         return optn_ok;
1428. #else
1429.         config_error_add("'%s' no longer supported; use 'symset:%s' instead",
1430.                          allopt[optidx].name, allopt[optidx].name);
1431.         return optn_err;
1432. #endif
1433.     }
1434.     if (req == get_val || req == get_cnf_val) {
1435.         opts[0] = '\0';
1436.         return optn_ok;
1437.     }
1438.     return optn_ok;
1439. }
1440. 
1441. staticfn int
1442. optfn_disclose(
1443.     int optidx, int req, boolean negated,
1444.     char *opts, char *op)
1445. {
1446.     int i, idx, prefix_val;
1447.     unsigned num;
1448. 
1449.     if (req == do_init) {
1450.         return optn_ok;
1451.     }
1452.     if (req == do_set) {
1453.         /* things to disclose at end of game */
1454. 
1455.         /*
1456.          * The order that the end_disclose options are stored:
1457.          *      inventory, attribs, vanquished, genocided,
1458.          *      conduct, overview.
1459.          * There is an array in flags:
1460.          *      end_disclose[NUM_DISCLOSURE_OPT];
1461.          * with option settings for the each of the following:
1462.          * iagvc [see disclosure_options in decl.c]:
1463.          * Allowed setting values in that array are:
1464.          *      DISCLOSE_PROMPT_DEFAULT_YES  ask with default answer yes
1465.          *      DISCLOSE_PROMPT_DEFAULT_NO   ask with default answer no
1466.          *      DISCLOSE_YES_WITHOUT_PROMPT  always disclose and don't ask
1467.          *      DISCLOSE_NO_WITHOUT_PROMPT   never disclose and don't ask
1468.          *      DISCLOSE_PROMPT_DEFAULT_SPECIAL  for 'vanq'/'genod' only...
1469.          *      DISCLOSE_SPECIAL_WITHOUT_PROMPT  ...to set up sort order.
1470.          *
1471.          * Those setting values can be used in the option
1472.          * string as a prefix to get the desired behavior.
1473.          *
1474.          * For backward compatibility, no prefix is required,
1475.          * and the presence of a i,a,g,v, or c without a prefix
1476.          * sets the corresponding value to DISCLOSE_YES_WITHOUT_PROMPT.
1477.          */
1478. 
1479.         op = string_for_opt(opts, TRUE);
1480.         if (op != empty_optstr && negated) {
1481.             bad_negation(allopt[optidx].name, TRUE);
1482.             return optn_err;
1483.         }
1484.         /* "disclose" without a value means "all with prompting"
1485.            and negated means "none without prompting" */
1486.         if (op == empty_optstr || !strcmpi(op, "all")
1487.             || !strcmpi(op, "none")) {
1488.             if (op != empty_optstr && !strcmpi(op, "none"))
1489.                 negated = TRUE;
1490.             for (num = 0; num < NUM_DISCLOSURE_OPTIONS; num++)
1491.                 flags.end_disclose[num] = negated
1492.                                               ? DISCLOSE_NO_WITHOUT_PROMPT
1493.                                               : DISCLOSE_PROMPT_DEFAULT_YES;
1494.             return optn_ok;
1495.         }
1496. 
1497.         num = 0;
1498.         prefix_val = -1;
1499.         while (*op && num < sizeof flags.end_disclose - 1) {
1500.             static char valid_settings[] = { DISCLOSE_PROMPT_DEFAULT_YES,
1501.                                              DISCLOSE_PROMPT_DEFAULT_NO,
1502.                                              DISCLOSE_PROMPT_DEFAULT_SPECIAL,
1503.                                              DISCLOSE_YES_WITHOUT_PROMPT,
1504.                                              DISCLOSE_NO_WITHOUT_PROMPT,
1505.                                              DISCLOSE_SPECIAL_WITHOUT_PROMPT,
1506.                                              '\0' };
1507.             char c;
1508.             const char *dop;
1509. 
1510.             c = lowc(*op);
1511.             if (c == 'k')
1512.                 c = 'v'; /* killed -> vanquished */
1513.             if (c == 'd')
1514.                 c = 'o'; /* dungeon -> overview */
1515.             dop = strchr(disclosure_options, c);
1516.             if (dop) {
1517.                 idx = (int) (dop - disclosure_options);
1518.                 if (idx < 0 || idx > NUM_DISCLOSURE_OPTIONS - 1) {
1519.                     impossible("bad disclosure index %d %c", idx, c);
1520.                     continue;
1521.                 }
1522.                 if (prefix_val != -1) {
1523.                     if (*dop != 'v' && *dop != 'g') {
1524.                         if (prefix_val == DISCLOSE_PROMPT_DEFAULT_SPECIAL)
1525.                             prefix_val = DISCLOSE_PROMPT_DEFAULT_YES;
1526.                         if (prefix_val == DISCLOSE_SPECIAL_WITHOUT_PROMPT)
1527.                             prefix_val = DISCLOSE_YES_WITHOUT_PROMPT;
1528.                     }
1529.                     flags.end_disclose[idx] = prefix_val;
1530.                     prefix_val = -1;
1531.                 } else
1532.                     flags.end_disclose[idx] = DISCLOSE_YES_WITHOUT_PROMPT;
1533.             } else if (strchr(valid_settings, c)) {
1534.                 prefix_val = c;
1535.             } else if (c == ' ') {
1536.                 ; /* do nothing */
1537.             } else {
1538.                 config_error_add("Unknown %s parameter '%c'",
1539.                                  allopt[optidx].name, *op);
1540.                 return optn_err;
1541.             }
1542.             op++;
1543.         }
1544.         return optn_ok;
1545.     }
1546.     if (req == get_val || req == get_cnf_val) {
1547.         opts[0] = '\0';
1548.         for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
1549.             if (i)
1550.                 (void) strkitten(opts, ' ');
1551.             (void) strkitten(opts, flags.end_disclose[i]);
1552.             (void) strkitten(opts, disclosure_options[i]);
1553.         }
1554.         return optn_ok;
1555.     }
1556.     if (req == do_handler) {
1557.         return handler_disclose();
1558.     }
1559.     return optn_ok;
1560. }
1561. 
1562. staticfn int
1563. optfn_dogname(
1564.     int optidx, int req,
1565.     boolean negated,
1566.     char *opts, char *op)
1567. {
1568.     return petname_optfn(optidx, req, negated, opts, op);
1569. }
1570. 
1571. staticfn int
1572. optfn_dungeon(
1573.     int optidx UNUSED, int req, boolean negated UNUSED,
1574.     char *opts, char *op UNUSED)
1575. {
1576.     if (req == do_init) {
1577.         return optn_ok;
1578.     }
1579.     if (req == do_set) {
1580.         return optn_ok;
1581.     }
1582.     if (req == get_val) {
1583.         Sprintf(opts, "%s", to_be_done);
1584.         return optn_ok;
1585.     }
1586.     if (req == get_cnf_val) {
1587.         opts[0] = '\0';
1588.         return optn_ok;
1589.     }
1590.     return optn_ok;
1591. }
1592. 
1593. staticfn int
1594. optfn_effects(
1595.     int optidx UNUSED, int req, boolean negated UNUSED,
1596.     char *opts, char *op UNUSED)
1597. {
1598.     if (req == do_init) {
1599.         return optn_ok;
1600.     }
1601.     if (req == do_set) {
1602.         return optn_ok;
1603.     }
1604.     if (req == get_val) {
1605.         Sprintf(opts, "%s", to_be_done);
1606.         return optn_ok;
1607.     }
1608.     if (req == get_cnf_val) {
1609.         opts[0] = '\0';
1610.         return optn_ok;
1611.     }
1612.     return optn_ok;
1613. }
1614. 
1615. staticfn int
1616. optfn_font_map(
1617.     int optidx, int req, boolean negated,
1618.     char *opts, char *op)
1619. {
1620.     /* send them over to the prefix handling for font_ */
1621.     return pfxfn_font(optidx, req, negated, opts, op);
1622. }
1623. 
1624. staticfn int
1625. optfn_font_menu(
1626.     int optidx, int req, boolean negated,
1627.     char *opts, char *op)
1628. {
1629.     /* send them over to the prefix handling for font_ */
1630.     return pfxfn_font(optidx, req, negated, opts, op);
1631. }
1632. 
1633. staticfn int
1634. optfn_font_message(
1635.     int optidx, int req, boolean negated,
1636.     char *opts, char *op)
1637. {
1638.     /* send them over to the prefix handling for font_ */
1639.     return pfxfn_font(optidx, req, negated, opts, op);
1640. }
1641. 
1642. staticfn int
1643. optfn_font_size_map(
1644.     int optidx, int req, boolean negated,
1645.     char *opts, char *op)
1646. {
1647.     /* send them over to the prefix handling for font_ */
1648.     return pfxfn_font(optidx, req, negated, opts, op);
1649. }
1650. 
1651. staticfn int
1652. optfn_font_size_menu(
1653.     int optidx, int req, boolean negated,
1654.     char *opts, char *op)
1655. {
1656.     /* send them over to the prefix handling for font_ */
1657.     return pfxfn_font(optidx, req, negated, opts, op);
1658. }
1659. 
1660. staticfn int
1661. optfn_font_size_message(
1662.     int optidx, int req, boolean negated,
1663.     char *opts, char *op)
1664. {
1665.     /* send them over to the prefix handling for font_ */
1666.     return pfxfn_font(optidx, req, negated, opts, op);
1667. }
1668. 
1669. staticfn int
1670. optfn_font_size_status(
1671.     int optidx, int req, boolean negated,
1672.     char *opts, char *op)
1673. {
1674.     /* send them over to the prefix handling for font_ */
1675.     return pfxfn_font(optidx, req, negated, opts, op);
1676. }
1677. 
1678. staticfn int
1679. optfn_font_size_text(
1680.     int optidx, int req, boolean negated,
1681.     char *opts, char *op)
1682. {
1683.     /* send them over to the prefix handling for font_ */
1684.     return pfxfn_font(optidx, req, negated, opts, op);
1685. }
1686. 
1687. staticfn int
1688. optfn_font_status(
1689.     int optidx, int req, boolean negated,
1690.     char *opts, char *op)
1691. {
1692.     /* send them over to the prefix handling for font_ */
1693.     return pfxfn_font(optidx, req, negated, opts, op);
1694. }
1695. 
1696. staticfn int
1697. optfn_font_text(
1698.     int optidx, int req, boolean negated,
1699.     char *opts, char *op)
1700. {
1701.     /* send them over to the prefix handling for font_ */
1702.     return pfxfn_font(optidx, req, negated, opts, op);
1703. }
1704. 
1705. staticfn int
1706. optfn_fruit(
1707.     int optidx UNUSED, int req, boolean negated,
1708.     char *opts, char *op)
1709. {
1710.     struct fruit *forig = 0;
1711. 
1712.     if (req == do_init) {
1713.         return optn_ok;
1714.     }
1715.     if (req == do_set) {
1716.         op = string_for_opt(opts, negated || !go.opt_initial);
1717.         if (negated) {
1718.             if (op != empty_optstr) {
1719.                 bad_negation("fruit", TRUE);
1720.                 return optn_err;
1721.             }
1722.             op = empty_optstr;
1723.             goto goodfruit;
1724.         }
1725.         if (op == empty_optstr)
1726.             return optn_err;
1727.         /* strip leading/trailing spaces, condense internal ones (3.6.2) */
1728.         mungspaces(op);
1729.         if (!go.opt_initial) {
1730.             struct fruit *f;
1731.             int fnum = 0;
1732. 
1733.             /* count number of named fruits; if 'op' is found among them,
1734.                then the count doesn't matter because we won't be adding it */
1735.             f = fruit_from_name(op, FALSE, &fnum);
1736.             if (!f) {
1737.                 if (!flags.made_fruit)
1738.                     forig = fruit_from_name(svp.pl_fruit, FALSE, (int *) 0);
1739. 
1740.                 if (!forig && fnum >= 100) {
1741.                     config_error_add(
1742.                         "Doing that so many times isn't very fruitful.");
1743.                     return optn_ok;
1744.                 }
1745.             }
1746.         }
1747.  goodfruit:
1748.         nmcpy(svp.pl_fruit, op, PL_FSIZ);
1749.         sanitize_name(svp.pl_fruit);
1750.         /* OBJ_NAME(objects[SLIME_MOLD]) won't work for this after
1751.            initialization; it gets changed to generic "fruit" */
1752.         if (!*svp.pl_fruit)
1753.             nmcpy(svp.pl_fruit, "slime mold", PL_FSIZ);
1754.         if (!go.opt_initial) {
1755.             /* if 'forig' is nonNull, we replace it rather than add
1756.                a new fruit; it can only be nonNull if no fruits have
1757.                been created since the previous name was put in place */
1758.             (void) fruitadd(svp.pl_fruit, forig);
1759.             if (give_opt_msg)
1760.                 pline("Fruit is now \"%s\".", svp.pl_fruit);
1761.         }
1762.         /* If initial, then initoptions is allowed to do it instead
1763.          * of here (initoptions always has to do it even if there's
1764.          * no fruit option at all.  Also, we don't want people
1765.          * setting multiple fruits in their options.)
1766.          */
1767.         return optn_ok;
1768.     }
1769.     if (req == get_val || req == get_cnf_val) {
1770.         Sprintf(opts, "%s", svp.pl_fruit);
1771.         return optn_ok;
1772.     }
1773.     return optn_ok;
1774. }
1775. 
1776. staticfn int
1777. optfn_gender(
1778.     int optidx,
1779.     int req,
1780.     boolean negated,
1781.     char *opts,
1782.     char *op)
1783. {
1784.     if (req == do_init) {
1785.         return optn_ok;
1786.     }
1787.     if (req == do_set) {
1788.         /* gender:string */
1789.         if (!parse_role_opt(optidx, negated, allopt[optidx].name, opts, &op))
1790.             return optn_silenterr;
1791. 
1792.         if (*op != '!') {
1793.             if ((flags.initgend = str2gend(op)) == ROLE_NONE) {
1794.                 config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
1795.                 return optn_err;
1796.             }
1797.             flags.female = flags.initgend;
1798.             saveoptstr(optidx, rolestring(flags.initgend, genders, adj));
1799.         }
1800.         return optn_ok;
1801.     }
1802.     if (req == get_val) {
1803.         Sprintf(opts, "%s", rolestring(flags.initgend, genders, adj));
1804.         return optn_ok;
1805.     }
1806.     if (req == get_cnf_val) {
1807.         op = get_cnf_role_opt(optidx);
1808.         Strcpy(opts, op ? op : "none");
1809.         return optn_ok;
1810.     }
1811.     return optn_ok;
1812. }
1813. 
1814. staticfn int
1815. optfn_glyph(
1816.     int optidx UNUSED, int req, boolean negated,
1817.     char *opts, char *op)
1818. {
1819.     int glyph;
1820. 
1821.     if (req == do_init) {
1822.         return optn_ok;
1823.     }
1824.     if (req == do_set) {
1825.         /* OPTION=glyph:G_glyph/U+NNNN/r-g-b */
1826.         if (negated) {
1827.             if (op != empty_optstr) {
1828.                 bad_negation("glyph", TRUE);
1829.                 return optn_err;
1830.             }
1831.         }
1832.         if (op == empty_optstr)
1833.             return optn_err;
1834.         /* strip leading/trailing spaces, condense internal ones (3.6.2) */
1835.         mungspaces(op);
1836.         if (!glyphrep_to_custom_map_entries(op, &glyph))
1837.             return optn_err;
1838.         return optn_ok;
1839.     }
1840.     if (req == get_val) {
1841.         Sprintf(opts, "%s", to_be_done);
1842.         return optn_ok;
1843.     }
1844.     if (req == get_cnf_val) {
1845.         opts[0] = '\0';
1846.         return optn_ok;
1847.     }
1848.     return optn_ok;
1849. }
1850. 
1851. staticfn int
1852. optfn_hilite_status(
1853.     int optidx UNUSED,
1854.     int req,
1855.     boolean negated,
1856.     char *opts,
1857.     char *op)
1858. {
1859.     if (req == do_init) {
1860.         return optn_ok;
1861.     }
1862.     if (req == do_set) {
1863.         /* hilite fields in status prompt */
1864. #ifdef STATUS_HILITES
1865.         op = string_for_opt(opts, TRUE);
1866.         if (op != empty_optstr && negated) {
1867.             clear_status_hilites();
1868.             return optn_ok;
1869.         } else if (op == empty_optstr) {
1870.             config_error_add("Value is mandatory for hilite_status");
1871.             return optn_err;
1872.         }
1873.         if (!parse_status_hl1(op, go.opt_from_file))
1874.             return optn_err;
1875.         return optn_ok;
1876. #else
1877.         nhUse(negated);
1878.         nhUse(op);
1879.         config_error_add("'%s' is not supported", allopt[optidx].name);
1880.         return optn_err;
1881. #endif
1882.     }
1883.     if (req == get_val || req == get_cnf_val) {
1884.         opts[0] = '\0';
1885. #ifdef STATUS_HILITES
1886.         if (req == get_val)
1887.             Strcpy(opts, count_status_hilites()
1888.                      ? "(see \"status highlight rules\" below)"
1889.                      : "(none)");
1890. #endif
1891.         return optn_ok;
1892.     }
1893.     return optn_ok;
1894. }
1895. 
1896. staticfn int
1897. optfn_horsename(
1898.     int optidx,
1899.     int req, boolean negated,
1900.     char *opts, char *op)
1901. {
1902.     return petname_optfn(optidx, req, negated, opts, op);
1903. }
1904. 
1905. staticfn int
1906. optfn_IBMgraphics(
1907.     int optidx, int req, boolean negated,
1908.     char *opts, char *op UNUSED)
1909. {
1910. #ifdef BACKWARD_COMPAT
1911.     const char *sym_name = allopt[optidx].name;
1912.     boolean badflag = FALSE;
1913.     int i;
1914. #endif
1915. 
1916.     if (req == do_init) {
1917.         return optn_ok;
1918.     }
1919.     if (req == do_set) {
1920.         /* "IBMgraphics" */
1921. 
1922. #ifdef BACKWARD_COMPAT
1923. 
1924.         if (!negated) {
1925.             for (i = 0; i < NUM_GRAPHICS; ++i) {
1926.                 if (gs.symset[i].name) {
1927.                     badflag = TRUE;
1928.                 } else {
1929.                     if (i == ROGUESET)
1930.                         sym_name = "RogueIBM";
1931.                     gs.symset[i].name = dupstr(sym_name);
1932.                     if (!read_sym_file(i)) {
1933.                         badflag = TRUE;
1934.                         clear_symsetentry(i, TRUE);
1935.                         break;
1936.                     }
1937.                 }
1938.             }
1939.             if (badflag) {
1940.                 config_error_add("Failure to load symbol set %s.", sym_name);
1941.                 return optn_err;
1942.             } else {
1943.                 switch_symbols(TRUE);
1944.                 if (!go.opt_initial && Is_rogue_level(&u.uz))
1945.                     assign_graphics(ROGUESET);
1946.             }
1947.         }
1948.         return optn_ok;
1949. #else
1950.         config_error_add("'%s' no longer supported; use 'symset:%s' instead",
1951.                          allopt[optidx].name, allopt[optidx].name);
1952.         return optn_err;
1953. #endif
1954.     }
1955.     if (req == get_val || req == get_cnf_val) {
1956.         opts[0] = '\0';
1957.         return optn_ok;
1958.     }
1959.     return optn_ok;
1960. }
1961. 
1962. staticfn int
1963. optfn_map_mode(
1964.     int optidx, int req, boolean negated,
1965.     char *opts, char *op)
1966. {
1967.     int i;
1968. 
1969.     if (req == do_init) {
1970.         return optn_ok;
1971.     }
1972.     if (req == do_set) {
1973.         /* WINCAP
1974.          *
1975.          *  map_mode:[tiles|ascii4x6|ascii6x8|ascii8x8|ascii16x8|ascii7x12
1976.          *            |ascii8x12|ascii16x12|ascii12x16|ascii10x18|fit_to_screen
1977.          *            |ascii_fit_to_screen|tiles_fit_to_screen]
1978.          */
1979.         op = string_for_opt(opts, negated);
1980.         if (op != empty_optstr && !negated) {
1981.             int save_map_mode = iflags.wc_map_mode;
1982. 
1983.             if (!strcmpi(op, "tiles"))
1984.                 iflags.wc_map_mode = MAP_MODE_TILES;
1985.             else if (!strncmpi(op, "ascii4x6", sizeof "ascii4x6" - 1))
1986.                 iflags.wc_map_mode = MAP_MODE_ASCII4x6;
1987.             else if (!strncmpi(op, "ascii6x8", sizeof "ascii6x8" - 1))
1988.                 iflags.wc_map_mode = MAP_MODE_ASCII6x8;
1989.             else if (!strncmpi(op, "ascii8x8", sizeof "ascii8x8" - 1))
1990.                 iflags.wc_map_mode = MAP_MODE_ASCII8x8;
1991.             else if (!strncmpi(op, "ascii16x8", sizeof "ascii16x8" - 1))
1992.                 iflags.wc_map_mode = MAP_MODE_ASCII16x8;
1993.             else if (!strncmpi(op, "ascii7x12", sizeof "ascii7x12" - 1))
1994.                 iflags.wc_map_mode = MAP_MODE_ASCII7x12;
1995.             else if (!strncmpi(op, "ascii8x12", sizeof "ascii8x12" - 1))
1996.                 iflags.wc_map_mode = MAP_MODE_ASCII8x12;
1997.             else if (!strncmpi(op, "ascii16x12", sizeof "ascii16x12" - 1))
1998.                 iflags.wc_map_mode = MAP_MODE_ASCII16x12;
1999.             else if (!strncmpi(op, "ascii12x16", sizeof "ascii12x16" - 1))
2000.                 iflags.wc_map_mode = MAP_MODE_ASCII12x16;
2001.             else if (!strncmpi(op, "ascii10x18", sizeof "ascii10x18" - 1))
2002.                 iflags.wc_map_mode = MAP_MODE_ASCII10x18;
2003.             else if (!strncmpi(op, "fit_to_screen",
2004.                                sizeof "fit_to_screen" - 1))
2005.                 iflags.wc_map_mode = MAP_MODE_ASCII_FIT_TO_SCREEN;
2006.             else if (!strncmpi(op, "ascii_fit_to_screen",
2007.                                sizeof "ascii_fit_to_screen" - 1))
2008.                 iflags.wc_map_mode = MAP_MODE_ASCII_FIT_TO_SCREEN;
2009.             else if (!strncmpi(op, "tiles_fit_to_screen",
2010.                                sizeof "tiles_fit_to_screen" - 1))
2011.                 iflags.wc_map_mode = MAP_MODE_TILES_FIT_TO_SCREEN;
2012.             else {
2013.                 config_error_add("Unknown %s parameter '%s'",
2014.                                  allopt[optidx].name, op);
2015.                 return optn_err;
2016.             }
2017.             if (wc_supported("map_mode")) {
2018.                 if (!iflags.wc_map_mode
2019.                     || save_map_mode != iflags.wc_map_mode)
2020.                     preference_update("map_mode");
2021.             }
2022.         } else if (negated) {
2023.             bad_negation(allopt[optidx].name, TRUE);
2024.             return optn_err;
2025.         }
2026.         return optn_ok;
2027.     }
2028.     if (req == get_val || req == get_cnf_val) {
2029.         i = iflags.wc_map_mode;
2030.         Sprintf(opts, "%s",
2031.                 (i == MAP_MODE_TILES) ? "tiles"
2032.                 : (i == MAP_MODE_ASCII4x6) ? "ascii4x6"
2033.                   : (i == MAP_MODE_ASCII6x8) ? "ascii6x8"
2034.                     : (i == MAP_MODE_ASCII8x8) ? "ascii8x8"
2035.                       : (i == MAP_MODE_ASCII16x8) ? "ascii16x8"
2036.                         : (i == MAP_MODE_ASCII7x12) ? "ascii7x12"
2037.                           : (i == MAP_MODE_ASCII8x12) ? "ascii8x12"
2038.                             : (i == MAP_MODE_ASCII16x12) ? "ascii16x12"
2039.                               : (i == MAP_MODE_ASCII12x16) ? "ascii12x16"
2040.                                 : (i == MAP_MODE_ASCII10x18) ? "ascii10x18"
2041.                                   : (i == MAP_MODE_ASCII_FIT_TO_SCREEN)
2042.                                     ? "fit_to_screen"
2043.                                     : defopt);
2044.         return optn_ok;
2045.     }
2046.     return optn_ok;
2047. }
2048. 
2049. /* all the key assignment options for menu_* commands are identical
2050.    but optlist.h treats them as distinct rather than sharing one */
2051. staticfn int
2052. shared_menu_optfn(int optidx UNUSED, int req, boolean negated,
2053.                    char *opts, char *op)
2054. {
2055.     if (req == do_init) {
2056.         return optn_ok;
2057.     }
2058.     if (req == do_set) {
2059.         int res = check_misc_menu_command(opts, op);
2060. 
2061.         if (res < 0)
2062.             return optn_err;
2063.         return spcfn_misc_menu_cmd(res, req, negated, opts, op);
2064.     }
2065.     if (req == get_val) {
2066.         Sprintf(opts, "%s", to_be_done);
2067.         return optn_ok;
2068.     }
2069.     if (req == get_cnf_val) {
2070.         opts[0] = '\0';
2071.         return optn_ok;
2072.     }
2073.     return optn_ok;
2074. }
2075. 
2076. staticfn int
2077. optfn_menu_deselect_all(
2078.     int optidx, int req, boolean negated,
2079.     char *opts, char *op)
2080. {
2081.     return shared_menu_optfn(optidx, req, negated, opts, op);
2082. }
2083. 
2084. staticfn int
2085. optfn_menu_deselect_page(
2086.     int optidx, int req, boolean negated,
2087.     char *opts, char *op)
2088. {
2089.     return shared_menu_optfn(optidx, req, negated, opts, op);
2090. }
2091. 
2092. staticfn int
2093. optfn_menu_first_page(
2094.     int optidx, int req, boolean negated,
2095.     char *opts, char *op)
2096. {
2097.     return shared_menu_optfn(optidx, req, negated, opts, op);
2098. }
2099. 
2100. staticfn int
2101. optfn_menu_invert_all(
2102.     int optidx, int req, boolean negated,
2103.     char *opts, char *op)
2104. {
2105.     return shared_menu_optfn(optidx, req, negated, opts, op);
2106. }
2107. 
2108. staticfn int
2109. optfn_menu_invert_page(
2110.     int optidx, int req, boolean negated,
2111.     char *opts, char *op)
2112. {
2113.     return shared_menu_optfn(optidx, req, negated, opts, op);
2114. }
2115. 
2116. staticfn int
2117. optfn_menu_last_page(
2118.     int optidx, int req, boolean negated,
2119.     char *opts, char *op)
2120. {
2121.     return shared_menu_optfn(optidx, req, negated, opts, op);
2122. }
2123. 
2124. staticfn int
2125. optfn_menu_next_page(
2126.     int optidx , int req, boolean negated,
2127.     char *opts, char *op)
2128. {
2129.     return shared_menu_optfn(optidx, req, negated, opts, op);
2130. }
2131. 
2132. staticfn int
2133. optfn_menu_previous_page(
2134.     int optidx, int req, boolean negated,
2135.     char *opts, char *op)
2136. {
2137.     return shared_menu_optfn(optidx, req, negated, opts, op);
2138. }
2139. 
2140. staticfn int
2141. optfn_menu_search(
2142.     int optidx, int req, boolean negated,
2143.     char *opts, char *op)
2144. {
2145.     return shared_menu_optfn(optidx, req, negated, opts, op);
2146. }
2147. 
2148. staticfn int
2149. optfn_menu_select_all(
2150.     int optidx, int req, boolean negated,
2151.     char *opts, char *op)
2152. {
2153.     return shared_menu_optfn(optidx, req, negated, opts, op);
2154. }
2155. 
2156. staticfn int
2157. optfn_menu_select_page(
2158.     int optidx, int req, boolean negated,
2159.     char *opts, char *op)
2160. {
2161.     return shared_menu_optfn(optidx, req, negated, opts, op);
2162. }
2163. 
2164. staticfn int
2165. optfn_menu_shift_left(
2166.     int optidx, int req, boolean negated,
2167.     char *opts, char *op)
2168. {
2169.     return shared_menu_optfn(optidx, req, negated, opts, op);
2170. }
2171. 
2172. staticfn int
2173. optfn_menu_shift_right(
2174.     int optidx, int req, boolean negated,
2175.     char *opts, char *op)
2176. {
2177.     return shared_menu_optfn(optidx, req, negated, opts, op);
2178. }
2179. 
2180. /* end of shared key assignments for menu commands */
2181. 
2182. staticfn int
2183. optfn_menu_headings(
2184.     int optidx,
2185.     int req, boolean negated,
2186.     char *opts, char *op)
2187. {
2188.     if (req == do_init) {
2189.         return optn_ok;
2190.     }
2191.     if (req == do_set) {
2192.         color_attr ca;
2193. 
2194.         if (op == empty_optstr) {
2195.             /* OPTIONS=menu_headings w/o value => no-color&inverse;
2196.                OPTIONS=!menu_headings => no-color&none */
2197.             iflags.menu_headings.attr = negated ? ATR_NONE : ATR_INVERSE;
2198.             iflags.menu_headings.color = NO_COLOR;
2199.             return optn_ok;
2200.         } else if (negated) { /* 'op != empty_optstr' to get here */
2201.             bad_negation(allopt[optidx].name, TRUE);
2202.             return optn_silenterr;
2203.         }
2204.         if (!color_attr_parse_str(&ca, op))
2205.             return optn_err;
2206.         iflags.menu_headings = ca;
2207.         return optn_ok;
2208.     }
2209.     if (req == get_val || req == get_cnf_val) {
2210.         char ca_buf[BUFSZ];
2211. 
2212.         Strcpy(ca_buf, color_attr_to_str(&iflags.menu_headings));
2213.         /* change "no color" to "no-color" or "light blue" to "light-blue" */
2214.         (void) strNsubst(ca_buf, " ", "-", 0);
2215.         Strcpy(opts, ca_buf);
2216.         return optn_ok;
2217.     }
2218.     if (req == do_handler) {
2219.         return handler_menu_headings();
2220.     }
2221.     return optn_ok;
2222. }
2223. 
2224. staticfn int
2225. optfn_menu_objsyms(
2226.     int optidx, int req,
2227.     boolean negated,
2228.     char *opts, char *op)
2229. {
2230.     if (req == do_init) {
2231.         /* set iflags.menu_objsyms to 4, "conditional"; also sets
2232.            iflags.menu_head_objsym to False and
2233.            iflags.use_menu_glyphs True */
2234.         set_menuobjsyms_flags(4);
2235.         return optn_ok;
2236.     }
2237.     if (req == do_set) {
2238.         unsigned k, l;
2239.         int i, osyms;
2240. 
2241.         if (negated) {
2242.             /* allow '!menu_objsyms' (and '!use_menu_glyphs') as
2243.                'menu_objsyms:none' (0) */
2244.             osyms = 0;
2245.         } else if (op == empty_optstr) {
2246.             /* treat boolean 'menu_objsyms' as 'menu_objsyms:headers' (1)
2247.                accept obsolete boolean 'use_menu_glyphs' as a synonym
2248.                for 'menu_objsyms:entries' (2) */
2249.             osyms = !strncmp(opts, "use_menu_glyphs", 15) ? 2 : 1;
2250.         } else if (digit(*op)) {
2251.             i = atoi(op);
2252.             if (i >= SIZE(objsymvals)) {
2253.                 config_error_add("Illegal %s parameter '%s'",
2254.                                  allopt[optidx].name, op);
2255.                 return optn_err;
2256.             }
2257.             osyms = i;
2258.         } else {
2259.             /* stilted "one-or-other" is used to compress the menu width */
2260.             static const char alt5[] = "one-or-the-other";
2261.             unsigned l5 = (unsigned) (sizeof alt5 - sizeof "");
2262. 
2263.             osyms = 0;
2264.             k = (unsigned) strlen(op);
2265.             for (i = 0; i < SIZE(objsymvals); ++i) {
2266.                 l = (unsigned) strlen(objsymvals[i].nam);
2267.                 if (k >= 4)
2268.                     l = k;
2269.                 if (!strncmpi(objsymvals[i].nam, op, l)
2270.                     || (i == 5 && !strncmpi(alt5, op, l5))) {
2271.                     osyms = i;
2272.                     break;
2273.                 }
2274.             }
2275.         }
2276.         set_menuobjsyms_flags(osyms);
2277.         return optn_ok;
2278.     }
2279.     if (req == get_val || req == get_cnf_val) {
2280.         Sprintf(opts, "%s", objsymvals[iflags.menuobjsyms].nam);
2281.         return optn_ok;
2282.     }
2283.     if (req == do_handler) {
2284.         return handler_menu_objsyms();
2285.     }
2286.     return optn_ok;
2287. }
2288. 
2289. staticfn int
2290. optfn_menuinvertmode(
2291.     int optidx, int req,
2292.     boolean negated UNUSED,
2293.     char *opts, char *op)
2294. {
2295.     if (req == do_init) {
2296.         return optn_ok;
2297.     }
2298.     if (req == do_set) {
2299.         /* menuinvertmode=0 or 1 or 2 (2 is experimental) */
2300.         if (op != empty_optstr) {
2301.             int mode = atoi(op);
2302. 
2303.             if (mode < 0 || mode > 2) {
2304.                 config_error_add("Illegal %s parameter '%s'",
2305.                                  allopt[optidx].name, op);
2306.                 return optn_err;
2307.             }
2308.             iflags.menuinvertmode = mode;
2309.         }
2310.         return optn_ok;
2311.     }
2312.     if (req == get_val || req == get_cnf_val) {
2313.         Sprintf(opts, "%d", iflags.menuinvertmode);
2314.         return optn_ok;
2315.     }
2316.     return optn_ok;
2317. }
2318. 
2319. staticfn int
2320. optfn_menustyle(
2321.     int optidx, int req, boolean negated,
2322.     char *opts, char *op)
2323. {
2324.     int tmp;
2325.     boolean val_required; /* no initializer based on opts because this can be
2326.                              called with init and invalid opts and op */
2327. 
2328.     if (req == do_init) {
2329.         return optn_ok;
2330.     }
2331.     if (req == do_set) {
2332.         /* menustyle:traditional or combination or full or partial */
2333. 
2334.         val_required = (strlen(opts) > 5 && !negated);
2335.         if ((op = string_for_opt(opts, !val_required)) == empty_optstr) {
2336.             if (val_required)
2337.                 return optn_err; /* string_for_opt gave feedback */
2338.             tmp = negated ? 'n' : 'f';
2339.         } else {
2340.             tmp = lowc(*op);
2341.         }
2342.         switch (tmp) {
2343.         case 'n': /* none */
2344.         case 't': /* traditional: prompt for class(es) by symbol,
2345.                      prompt for each item within class(es) one at a time */
2346.             flags.menu_style = MENU_TRADITIONAL;
2347.             break;
2348.         case 'c': /* combination: prompt for class(es) by symbol,
2349.                      choose items within selected class(es) by menu */
2350.             flags.menu_style = MENU_COMBINATION;
2351.             break;
2352.         case 'f': /* full: choose class(es) by first menu,
2353.                      choose items within selected class(es) by second menu */
2354.             flags.menu_style = MENU_FULL;
2355.             break;
2356.         case 'p': /* partial: skip class filtering, choose items among all
2357.                      classes by menu */
2358.             flags.menu_style = MENU_PARTIAL;
2359.             break;
2360.         default:
2361.             config_error_add("Unknown %s parameter '%s'", allopt[optidx].name,
2362.                              op);
2363.             return optn_err;
2364.         }
2365.         return optn_ok;
2366.     }
2367.     if (req == get_val || req == get_cnf_val) {
2368.         Sprintf(opts, "%s", menutype[(int) flags.menu_style][0]);
2369.         return optn_ok;
2370.     }
2371.     if (req == do_handler) {
2372.         return handler_menustyle();
2373.     }
2374.     return optn_ok;
2375. }
2376. 
2377. staticfn int
2378. optfn_monsters(
2379.     int optidx UNUSED, int req, boolean negated UNUSED,
2380.     char *opts, char *op UNUSED)
2381. {
2382.     if (req == do_init) {
2383.         return optn_ok;
2384.     }
2385.     if (req == do_set) {
2386.         return optn_ok;
2387.     }
2388.     if (req == get_val || req == get_cnf_val) {
2389.         opts[0] = '\0';
2390.         return optn_ok;
2391.     }
2392.     return optn_ok;
2393. }
2394. 
2395. staticfn int
2396. optfn_mouse_support(
2397.     int optidx, int req, boolean negated,
2398.     char *opts, char *op)
2399. {
2400.     boolean compat;
2401. 
2402.     if (req == do_init) {
2403.         return optn_ok;
2404.     }
2405.     if (req == do_set) {
2406.         compat = (strlen(opts) <= 13);
2407.         op = string_for_opt(opts, (compat || !go.opt_initial));
2408.         if (op == empty_optstr) {
2409.             if (compat || negated || go.opt_initial) {
2410.                 /* for backwards compatibility, "mouse_support" without a
2411.                    value is a synonym for mouse_support:1 */
2412.                 iflags.wc_mouse_support = !negated;
2413.             }
2414.         } else {
2415.             int mode = atoi(op);
2416. 
2417.             if (mode < 0 || mode > 2 || (mode == 0 && *op != '0')) {
2418.                 config_error_add("Illegal %s parameter '%s'",
2419.                                  allopt[optidx].name, op);
2420.                 return optn_err;
2421.             } else { /* mode >= 0 */
2422.                 iflags.wc_mouse_support = mode;
2423.             }
2424.         }
2425.         return optn_ok;
2426.     }
2427.     if (req == get_val) {
2428. #ifdef WIN32
2429. #define MOUSEFIX1 ", QuickEdit off"
2430. #define MOUSEFIX2 ", QuickEdit unchanged"
2431. #else
2432. #define MOUSEFIX1 ", O/S adjusted"
2433. #define MOUSEFIX2 ", O/S unchanged"
2434. #endif
2435.         static const char *const mousemodes[][2] = {
2436.             { "0=off", "" },
2437.             { "1=on",  MOUSEFIX1 },
2438.             { "2=on",  MOUSEFIX2 },
2439.         };
2440. #undef MOUSEFIX1
2441. #undef MOUSEFIX2
2442.         int ms = iflags.wc_mouse_support;
2443. 
2444.         if (ms >= 0 && ms <= 2)
2445.             Sprintf(opts, "%s%s", mousemodes[ms][0], mousemodes[ms][1]);
2446.         return optn_ok;
2447.     }
2448.     if (req == get_cnf_val) {
2449.         Sprintf(opts, "%i", iflags.wc_mouse_support);
2450.         return optn_ok;
2451.     }
2452.     return optn_ok;
2453. }
2454. 
2455. staticfn int
2456. optfn_msg_window(
2457.     int optidx, int req, boolean negated,
2458.     char *opts, char *op)
2459. {
2460.     int retval = optn_ok;
2461. #if PREV_MSGS
2462.     int tmp;
2463. #else
2464.     nhUse(optidx);
2465.     nhUse(negated);
2466.     nhUse(op);
2467. #endif
2468. 
2469.     if (req == do_init) {
2470.         return optn_ok;
2471.     }
2472.     if (req == do_set) {
2473.         /* msg_window:single, combo, full or reversed */
2474. 
2475.         /* allow option to be silently ignored by non-tty ports */
2476. #if PREV_MSGS
2477.         if (op == empty_optstr) {
2478.             tmp = negated ? 's' : 'f';
2479.         } else {
2480.             if (negated) {
2481.                 bad_negation(allopt[optidx].name, TRUE);
2482.                 return optn_err;
2483.             }
2484.             tmp = lowc(*op);
2485.         }
2486.         switch (tmp) {
2487.         case 's': /* single message history cycle (default if negated) */
2488.         case 'c': /* combination: first two as singles, then full page */
2489.         case 'f': /* full page (default if specified without argument) */
2490.         case 'r': /* full page in reverse order (LIFO; default for curses) */
2491.             iflags.prevmsg_window = (char) tmp;
2492.             break;
2493.         default:
2494.             config_error_add("Unknown %s parameter '%s'", allopt[optidx].name,
2495.                              op);
2496.             retval = optn_err;
2497.         }
2498. #endif
2499.         return retval;
2500.     }
2501.     if (req == get_val || req == get_cnf_val) {
2502.         opts[0] = '\0';
2503. #if PREV_MSGS
2504.         tmp = iflags.prevmsg_window;
2505.         if (WINDOWPORT(curses)) {
2506.             if (tmp == 's' || tmp == 'c')
2507.                 tmp = iflags.prevmsg_window = 'r';
2508.         }
2509.         Sprintf(opts, "%s", (tmp == 's') ? "single"
2510.                             : (tmp == 'c') ? "combination"
2511.                               : (tmp == 'f') ? "full"
2512.                                 : "reversed");
2513. #endif
2514.         return optn_ok;
2515.     }
2516.     if (req == do_handler) {
2517.         return handler_msg_window();
2518.     }
2519.     return optn_ok;
2520. }
2521. 
2522. staticfn int
2523. optfn_msghistory(
2524.     int optidx, int req, boolean negated,
2525.     char *opts, char *op)
2526. {
2527.     if (req == do_init) {
2528.         return optn_ok;
2529.     }
2530.     if (req == do_set) {
2531.         op = string_for_env_opt(allopt[optidx].name, opts, negated);
2532.         if ((negated && op == empty_optstr)
2533.             || (!negated && op != empty_optstr)) {
2534.             iflags.msg_history = negated ? 0 : atoi(op);
2535.         } else if (negated) {
2536.             bad_negation(allopt[optidx].name, TRUE);
2537.             return optn_err;
2538.         }
2539.         return optn_ok;
2540.     }
2541.     if (req == get_val || req == get_cnf_val) {
2542.         Sprintf(opts, "%u", iflags.msg_history);
2543.         return optn_ok;
2544.     }
2545.     return optn_ok;
2546. }
2547. 
2548. staticfn int
2549. optfn_name(
2550.     int optidx, int req, boolean negated UNUSED,
2551.     char *opts, char *op)
2552. {
2553.     if (req == do_init) {
2554.         return optn_ok;
2555.     }
2556.     if (req == do_set) {
2557.         /* name:string */
2558. 
2559.         if ((op = string_for_env_opt(allopt[optidx].name, opts, FALSE))
2560.             != empty_optstr) {
2561.             nmcpy(svp.plname, op, PL_NSIZ);
2562.         } else
2563.             return optn_err;
2564.         return optn_ok;
2565.     }
2566.     if (req == get_val || req == get_cnf_val) {
2567.         Sprintf(opts, "%s", svp.plname);
2568.         return optn_ok;
2569.     }
2570.     return optn_ok;
2571. }
2572. 
2573. staticfn int
2574. optfn_number_pad(
2575.     int optidx, int req, boolean negated,
2576.     char *opts, char *op)
2577. {
2578.     boolean compat;
2579. 
2580.     if (req == do_init) {
2581.         return optn_ok;
2582.     }
2583.     if (req == do_set) {
2584.         compat = (strlen(opts) <= 10);
2585.         op = string_for_opt(opts, (compat || !go.opt_initial));
2586.         if (op == empty_optstr) {
2587.             if (compat || negated || go.opt_initial) {
2588.                 /* for backwards compatibility, "number_pad" without a
2589.                    value is a synonym for number_pad:1 */
2590.                 iflags.num_pad = !negated;
2591.                 iflags.num_pad_mode = 0;
2592.             }
2593.         } else if (negated) {
2594.             bad_negation(allopt[optidx].name, TRUE);
2595.             return optn_err;
2596.         } else {
2597.             int mode = atoi(op);
2598. 
2599.             if (mode < -1 || mode > 4 || (mode == 0 && *op != '0')) {
2600.                 config_error_add("Illegal %s parameter '%s'",
2601.                                  allopt[optidx].name, op);
2602.                 return optn_err;
2603.             } else if (mode <= 0) {
2604.                 iflags.num_pad = FALSE;
2605.                 /* German keyboard; y and z keys swapped */
2606.                 iflags.num_pad_mode = (mode < 0); /* 0 or 1 */
2607.             } else {                              /* mode > 0 */
2608.                 iflags.num_pad = TRUE;
2609.                 iflags.num_pad_mode = 0;
2610.                 /* PC Hack / MSDOS compatibility */
2611.                 if (mode == 2 || mode == 4)
2612.                     iflags.num_pad_mode |= 1;
2613.                 /* phone keypad layout */
2614.                 if (mode == 3 || mode == 4)
2615.                     iflags.num_pad_mode |= 2;
2616.             }
2617.         }
2618.         reset_commands(FALSE);
2619.         number_pad(iflags.num_pad ? 1 : 0);
2620.         return optn_ok;
2621.     }
2622.     if (req == get_val || req == get_cnf_val) {
2623.         static const char *const numpadmodes[] = {
2624.             "0=off", "1=on", "2=on, MSDOS compatible",
2625.             "3=on, phone-style layout",
2626.             "4=on, phone layout, MSDOS compatible",
2627.             "-1=off, y & z swapped", /*[5]*/
2628.         };
2629.         int indx = gc.Cmd.num_pad
2630.                        ? (gc.Cmd.phone_layout ? (gc.Cmd.pcHack_compat ? 4 : 3)
2631.                                            : (gc.Cmd.pcHack_compat ? 2 : 1))
2632.                        : gc.Cmd.swap_yz ? 5 : 0;
2633. 
2634.         if (req == get_val)
2635.             Strcpy(opts, numpadmodes[indx]);
2636.         else {
2637.             Sprintf(opts, "%i", (indx == 5) ? -1 : indx);
2638.         }
2639.         return optn_ok;
2640.     }
2641.     if (req == do_handler) {
2642.         return handler_number_pad();
2643.     }
2644.     return optn_ok;
2645. }
2646. 
2647. staticfn int
2648. optfn_objects(
2649.     int optidx UNUSED, int req, boolean negated UNUSED,
2650.     char *opts, char *op UNUSED)
2651. {
2652.     if (req == do_init) {
2653.         return optn_ok;
2654.     }
2655.     if (req == do_set) {
2656.         return optn_ok;
2657.     }
2658.     if (req == get_val) {
2659.         Sprintf(opts, "%s", to_be_done);
2660.         return optn_ok;
2661.     }
2662.     if (req == get_cnf_val) {
2663.         opts[0] = '\0';
2664.         return optn_ok;
2665.     }
2666.     return optn_ok;
2667. }
2668. 
2669. staticfn int
2670. optfn_packorder(
2671.     int optidx UNUSED, int req, boolean negated UNUSED,
2672.     char *opts, char *op)
2673. {
2674.     if (req == do_init) {
2675.         return optn_ok;
2676.     }
2677.     if (req == do_set) {
2678.         if (op == empty_optstr)
2679.             return optn_err;
2680.         if (!change_inv_order(op))
2681.             return optn_err;
2682.         return optn_ok;
2683.     }
2684.     if (req == get_val || req == get_cnf_val) {
2685.         char ocl[MAXOCLASSES + 1];
2686. 
2687.         oc_to_str(flags.inv_order, ocl);
2688.         Sprintf(opts, "%s", ocl);
2689.         return optn_ok;
2690.     }
2691.     return optn_ok;
2692. }
2693. 
2694. #ifdef CHANGE_COLOR
2695. 
2696. DISABLE_WARNING_FORMAT_NONLITERAL
2697. 
2698. staticfn int
2699. optfn_palette(
2700.     int optidx UNUSED, int req, boolean negated UNUSED,
2701.     char *opts, char *op)
2702. {
2703.     if (req == do_init) {
2704.         return optn_ok;
2705.     }
2706.     if (req == do_set) {
2707.         if (op == empty_optstr)
2708.             return optn_err;
2709. 
2710.         if (match_optname(opts, "palette", 3, TRUE)) {
2711.             /*
2712.              *  palette (adjust an RGB color in palette (color/R-G-B)
2713.              */
2714.             if (!alternative_palette(op)) {
2715.                 config_error_add("Error in palette parameter '%s'", op);
2716.                 return optn_err;
2717.             }
2718.             if (!go.opt_initial)
2719.                 go.opt_update_basic_palette = TRUE;
2720.         }
2721.         return optn_ok;
2722.     }
2723.     if (req == get_val || req == get_cnf_val) {
2724.         if (!opts)
2725.             return optn_err;
2726.         Sprintf(opts, n_currently_set, count_alt_palette());
2727.         return optn_ok;
2728.     }
2729.     return optn_ok;
2730. }
2731. 
2732. #if 0
2733. /* old MACOS9 OS9 code */
2734. staticfn int
2735. optfn_palette(
2736.     int optidx UNUSED, int req, boolean negated UNUSED,
2737.     char *opts, char *op)
2738. {
2739.     int cnt, tmp, reverse;
2740.     char *pt = op;
2741.     long rgb;
2742. 
2743.      * Mac OS9 variant
2744.      *        palette (00c/880/-fff is blue/yellow/reverse white)
2745.      */
2746.     if (req == do_init) {
2747.         return optn_ok;
2748.     }
2749.     if (req == do_set) {
2750.         if (op == empty_optstr)
2751.             return optn_err;
2752. 
2753.         if (match_optname(opts, "palette", 3, TRUE)
2754.             || match_optname(opts, "hicolor", 3, TRUE)) {
2755.             int color_number, color_incr;
2756. 
2757.             if (duplicate)
2758.                 complain_about_duplicate(optidx);
2759.             if (match_optname(opts, "hicolor", 3, TRUE)) {
2760.                 color_number = CLR_MAX + 4; /* HARDCODED inverse number */
2761.                 color_incr = -1;
2762.             } else {
2763.                 color_number = 0;
2764.                 color_incr = 1;
2765.             }
2766.             /* ----------- Mac OS 9 code -------------------------*/
2767.             while (*pt && color_number >= 0) {
2768.                 cnt = 3;
2769.                 rgb = 0L;
2770.                 if (*pt == '-') {
2771.                     reverse = 1;
2772.                     pt++;
2773.                 } else {
2774.                     reverse = 0;
2775.                 }
2776.                 while (cnt-- > 0) {
2777.                     if (*pt && *pt != '/') {
2778.                         rgb <<= 8;
2779.                         tmp = *pt++;
2780.                         if (isalpha((uchar) tmp)) {
2781.                             tmp = (tmp + 9) & 0xf; /* Assumes ASCII... */
2782.                         } else {
2783.                             tmp &= 0xf; /* Digits in ASCII too... */
2784.                         }
2785.                         /* Add an extra so we fill f -> ff and 0 -> 00 */
2786.                         rgb += tmp << 4;
2787.                         rgb += tmp;
2788.                     }
2789.                 }
2790.                 if (*pt == '/')
2791.                     pt++;
2792.                 change_color(color_number, rgb, reverse);
2793.                 color_number += color_incr;
2794.             }
2795. 
2796.             if (!go.opt_initial)
2797.                 go.opt_update_basic_palette = TRUE;
2798.         }
2799.         return optn_ok;
2800.     }
2801.     if (req == get_val || req == get_cnf_val) {
2802.         if (!opts)
2803.             return optn_err;
2804.         Sprintf(opts, n_currently_set, count_alt_palette());
2805.         return optn_ok;
2806.     }
2807.     return optn_ok;
2808. 
2809. }
2810. #endif  /* 0 */
2811. 
2812. RESTORE_WARNING_FORMAT_NONLITERAL
2813. 
2814. #endif /* CHANGE_COLOR */
2815. 
2816. /* for "paranoid_confirmation:foo" and alias "[!]prayconfirm" */
2817. staticfn int
2818. optfn_paranoid_confirmation(
2819.     int optidx, int req, boolean opt_negated,
2820.     char *opts, char *op)
2821. {
2822.     boolean fld_negated;
2823.     int i;
2824.     /*
2825.      * Player can change required response for some prompts (quit, die,
2826.      * attack, save-bones, continue-eating, break-wand, Were-change to
2827.      * need to be "yes<return>" instead of just 'y' keystroke to accept.
2828.      *
2829.      * For paranoid_confirm:Confirm, these prompts also need "no<return>"
2830.      * instead of 'n' or <space> or <return> to reject.  (<escape> always
2831.      * works as a way to reject.)
2832.      *
2833.      * Player can add an extra prompt (pray, AutoAll) that isn't
2834.      * ordinarily there.  (They ask for 'y' keystroke unless Confirm is
2835.      * also set, then they'll switch to "yes<return>", "no<return>".)
2836.      *
2837.      * Player can also change game's behavior.  paranoid_confirm:swim
2838.      * can be used to prevent accidentally stepping into water or lava;
2839.      * player must use the 'm' movement prefix to do that intentionally.
2840.      * paranoid_confirm:Remove [with synonym parnoid_confirm:Takeoff]
2841.      * changes the 'R' and 'T' commands [which have differing criteria
2842.      * for "only one candidate item"] to prompt for inventory item to
2843.      * remove/takeoff when there is only one candidate, so allows player
2844.      * a chance to cancel at the pick-an-item prompt or menu.
2845.      */
2846. 
2847.     if (req == do_init) {
2848.         return optn_ok;
2849.     }
2850.     if (req == do_set) {
2851.         char prayconfirm[1 + sizeof "pray"];
2852.         char *pp;
2853.         boolean plus_or_minus = FALSE;
2854. 
2855.         /*
2856.          * "prayconfirm" used to be a separate boolean option,
2857.          * now it is a synonym for paranoid_confirm:+pray and
2858.          * "!prayconfirm" has become one for paranoid_confirm:-pray.
2859.          */
2860.         if (!strncmpi(opts, "prayconfirm", 4)) {
2861.             if (*op) {
2862.                 /* presence of any value is treated as an error whether
2863.                    complaining about the 'prayconfirm' deprecation or not;
2864.                    this will erroneously reject "prayconfirm:true"; too
2865.                    bad; back when prayconfirm was in active use, tacking on
2866.                    an explicit value to a boolean option wasn't supported */
2867.                 config_error_add(
2868.            "deprecated %sprayconfirm option takes no parameters (found '%s')",
2869.                                  opt_negated ? "!" : "", op);
2870.                 return optn_silenterr;
2871.             }
2872. #ifdef COMPLAIN_ABOUT_PRAYCONFIRM
2873.             /* config file summary of complaints includes this in the count
2874.                of errors; we'd prefer that it be described as a warning but
2875.                that isn't supported [not important since this is considered
2876.                temporary until 'prayconfirm' gets removed altogether] */
2877.             config_error_add(
2878.                  "%sprayconfirm option is deprecated; switching to %s:%cpray",
2879.                              opt_negated ? "!" : "",
2880.                              allopt[optidx].name,
2881.                              opt_negated ? '-' : '+');
2882.             /* keep going */
2883. #endif
2884.             /* convert prayconfirm to paranoid_confirm:+pray and
2885.                !prayconfirm to paranoid_confirm:-pray */
2886.             Sprintf(prayconfirm, "%cpray", opt_negated ? '-' : '+');
2887.             op = prayconfirm;
2888.             /* possibly changing !prayconfirm to paranoid_confirm:-pray
2889.                which clears a paranoia bit but isn't a negated option */
2890.             opt_negated = FALSE;
2891.         /*
2892.          * end of 'prayconfirm' processing
2893.          */
2894. 
2895.         } else if (opt_negated) {
2896.             /* "!paranoid_confirm" w/o args is same as paranoid_confirm:none;
2897.                "!paranoid_confirm:anything" is disallowed */
2898.             if (!*op) {
2899.                 flags.paranoia_bits = 0;
2900.                 return optn_ok;
2901.             } else {
2902.                 config_error_add("!%s does not accept a value",
2903.                                  allopt[optidx].name);
2904.                 return optn_silenterr;
2905.             }
2906.         } else if (!*op) {
2907.             /* "paranoid_confirm" without any arguments is disallowed */
2908.             config_error_add("%s requires a value; use 'none' to cancel all",
2909.                              allopt[optidx].name);
2910.             return optn_silenterr;
2911.         }
2912. 
2913.         /*
2914.          * Multiple settings for paranoid_confirmation are allowed.
2915.          * When a new instance is processed, the behavior depends on the
2916.          * first character of its value:
2917.          *
2918.          * paranoid_confirm:foo bar
2919.          *   clears all confirmation bits (from previous settings, including
2920.          *   default), then sets the bits for foo and bar;
2921.          *
2922.          * paranoid_confirm:+foo bar
2923.          *   existing bits are kept, plus those for foo and bar are set;
2924.          *
2925.          * paranoid_confirm:-foo bar
2926.          *   existing bits are kept except those for foo and bar get cleared;
2927.          *
2928.          * paranoid_confirm:+foo !bar
2929.          *   combination of paranoid_confirm:+foo,paranoid_confirm:-bar;
2930.          *
2931.          * paranoid_confirm:-foo !bar
2932.          *   the negation in '!bar' is ignored, treated as if '-foo bar';
2933.          *
2934.          * !paranoid_confirm
2935.          *   without a value is treated as paranoid_confirm:none and clears
2936.          *   all bits;
2937.          * !paranoid_confirm:anything
2938.          *   (including +anything_else or -anything_else) is disallowed;
2939.          *
2940.          * paranoid_confirm:+all is the same as paranoid_confirm:all;
2941.          * paranoid_confirm:-all is the same as paranoid_confirm:none;
2942.          * paranoid_confirm:+none and paranoid_confirm:-none are no-ops.
2943.          */
2944.         (void) mungspaces(op);
2945.         if (*op != '+' && *op != '-') {
2946.             /* new value; first clear all old bits */
2947.             flags.paranoia_bits = 0;
2948.         } else {
2949.             /* augmenting existing value; keep old bits */
2950.             plus_or_minus = TRUE; /* only used for "+none" and "-none" */
2951.             opt_negated = (*op == '-'); /* context is changed */
2952.             if (*++op == ' ') /* skip '+' or '-', maybe whitespace */
2953.                 ++op;
2954.         }
2955. 
2956.         for (;;) {
2957.             fld_negated = (*op == '!');
2958.             if (fld_negated) {
2959.                 /* there shouldn't be a space after '!' because then
2960.                    "! foo bar" looks like it might be intended to mean
2961.                    "!foo !bar" but if there is one, skip it to prevent
2962.                    a lookup attempt for "" which will fail and result in
2963.                    an unhelpful error message; accepting the space is
2964.                    simpler than another special case error message */
2965.                 if (*++op == ' ') /* skip '!', maybe whitespace */
2966.                     ++op;
2967.             } else {
2968.                 /* accept "nofoo" to be same as "!foo", unless "no" is
2969.                    followed by a space or 'foo' begins with "n" (to avoid
2970.                    confusion for "none" */
2971.                 if (lowc(op[0]) == 'n' && lowc(op[1]) == 'o'
2972.                        && lowc(op[2] != 'n' && lowc(op[2]) != '\0')) {
2973.                     fld_negated = TRUE;
2974.                     op += 2; /* skip "no"; we know next char isn't space  */
2975.                 }
2976.             }
2977.             /* We're looking to parse
2978.                "paranoid_confirm:whichone wheretwo whothree"
2979.                and "paranoid_confirm:" prefix has already
2980.                been stripped off by the time we get here */
2981.             pp = strchr(op, ' ');
2982.             if (pp)
2983.                 *pp = '\0';
2984.             /* we aren't matching option names but match_optname()
2985.                does what we want once we've broken the space
2986.                delimited aggregate into separate tokens */
2987.             for (i = 0; i < SIZE(paranoia); ++i) {
2988.                 if (match_optname(op, paranoia[i].argname,
2989.                                   paranoia[i].argMinLen, FALSE)
2990.                     || (paranoia[i].synonym
2991.                         && match_optname(op, paranoia[i].synonym,
2992.                                          paranoia[i].synMinLen, FALSE))) {
2993.                     if (!paranoia[i].flagmask) {
2994.                         /* flagmask==0 is "none", clear all bits
2995.                            but "+none" and "-none" are no-ops */
2996.                         if (!plus_or_minus)
2997.                             flags.paranoia_bits = 0; /* clear all */
2998.                     } else if (opt_negated || fld_negated) {
2999.                         flags.paranoia_bits &= ~paranoia[i].flagmask;
3000.                     } else {
3001.                         flags.paranoia_bits |= paranoia[i].flagmask;
3002.                     }
3003.                     break;
3004.                 }
3005.             }
3006.             if (i == SIZE(paranoia)) {
3007.                 /* didn't match anything, so arg is bad;
3008.                    any flags already modified will stay modified */
3009.                 config_error_add("Unknown %s parameter '%s'",
3010.                                  allopt[optidx].name, op);
3011.                 return optn_silenterr;
3012.             }
3013.             /* move on to next token */
3014.             if (pp)
3015.                 op = pp + 1;
3016.             else
3017.                 break; /* no next token */
3018.         } /* for(;;) */
3019.         return optn_ok;
3020.     }
3021.     if (req == get_val || req == get_cnf_val) {
3022.         char tmpbuf[BUFSZ];
3023. 
3024.         tmpbuf[0] = '\0';
3025.         for (i = 0; paranoia[i].flagmask != 0; ++i) {
3026.             if ((flags.paranoia_bits & paranoia[i].flagmask) != 0
3027.                 /* hide paranoid_confirm:bones during play except for wizard
3028.                    mode; keep it for any mode if rewriting the config file */
3029.                 && (paranoia[i].flagmask != PARANOID_BONES
3030.                     || wizard || req == get_cnf_val))
3031.                 Snprintf(eos(tmpbuf), sizeof tmpbuf - strlen(tmpbuf),
3032.                          " %s", paranoia[i].argname);
3033.         }
3034.         /* note: always leaves enough room for caller to tack on '\n' */
3035.         opts[0] = '\0';
3036.         (void) strncat(opts, tmpbuf[0] ? &tmpbuf[1] : "none", BUFSZ - 1);
3037.         return optn_ok;
3038.     }
3039.     if (req == do_handler) {
3040.         return handler_paranoid_confirmation();
3041.     }
3042.     return optn_ok;
3043. }
3044. 
3045. staticfn int
3046. optfn_perminv_mode(
3047.     int optidx, int req, boolean negated,
3048.     char *opts, char *op)
3049. {
3050.     boolean old_perm_invent = iflags.perm_invent;
3051.     uchar old_perminv_mode = iflags.perminv_mode;
3052.     int retval = optn_ok;
3053. 
3054.     if (req == do_init) {
3055. #if 0
3056.         /* old, TEMPORARY method of controlling 'perm_invent';
3057.            note: the bits used now have been changed, hence 'n << 1' */
3058.         char *envtmp = nh_getenv("TTYINV") : 0;
3059.         int invmode = envtmp ? (atoi(envtmp) << 1) : 0;
3060. 
3061.         iflags.perminv_mode = (uchar) invmode;
3062.         iflags.perm_invent = iflags.perminv_mode != 0;
3063. #endif
3064.         return optn_ok;
3065.     } else if (req == do_set) {
3066.         op = string_for_opt(opts, negated);
3067.         if (op != empty_optstr && negated) { /* reject "!perminv_mode=foo" */
3068.             bad_negation(allopt[optidx].name, TRUE);
3069.             retval = optn_silenterr;
3070.         } else if (op != empty_optstr) { /* "perminv_mode=foo" */
3071.             const char *pi0, *pi1;
3072.             int i;
3073.             unsigned ln = (unsigned) strlen(op); /* guaranteed > 0 */
3074. 
3075.             for (i = 0; i < SIZE(perminv_modes); ++i) {
3076.                 if (!(pi0 = perminv_modes[i][0]))
3077.                     continue;
3078.                 pi1 = perminv_modes[i][1];
3079.                 if (!strncmpi(op, pi0, ln) || !strncmpi(op, pi1, ln)
3080.                     || op[0] == i + '0') { /* also accept '0'..'8' */
3081. #if 1 /*#ifdef TTY_PERM_INVENT*/
3082.                     if (strstri(pi0, "+grid") && !WINDOWPORT(tty)) {
3083.                         i &= ~InvSparse;
3084.                         config_error_add(
3085.                           "%s: unavailable perm_invent mode '%s', using '%s'",
3086.                                          allopt[optidx].name, pi0,
3087.                                          perminv_modes[i][0]);
3088.                     }
3089. #endif
3090.                     iflags.perminv_mode = (uchar) i;
3091.                     iflags.perm_invent = TRUE;
3092.                     break;
3093.                 }
3094.             }
3095.             if (i == SIZE(perminv_modes)) {
3096.                 config_error_add("Unknown %s parameter '%s'",
3097.                                  allopt[optidx].name, op);
3098.                 iflags.perminv_mode = InvOptNone;
3099.                 iflags.perm_invent = FALSE;
3100.                 retval = optn_silenterr;
3101.             }
3102.         } else if (negated) { /* "!perminv_mode" */
3103.             iflags.perminv_mode = InvOptNone;
3104.             iflags.perm_invent = FALSE;
3105.         }
3106.         if (!go.opt_initial) {
3107.             if (iflags.perminv_mode != old_perminv_mode
3108.                 || iflags.perm_invent != old_perm_invent)
3109.                 go.opt_need_redraw = TRUE;
3110.         }
3111.     } else if (req == do_handler) {
3112.         /* use a menu to choose new value for perminv_mode */
3113.         retval = handler_perminv_mode();
3114.     } else if (req == get_val) {
3115.         /* value shown when examining current option settings; enclosed
3116.            within square brackets for 'O', shown as-is when setting value */
3117.         Sprintf(opts, "%s", perminv_modes[iflags.perminv_mode][2]);
3118.         if (iflags.perminv_mode != InvOptNone && !iflags.perm_invent
3119.             /* 'op' is Null when called by handler_perminv_mode() while
3120.                setting, non-Null when 'm O' shows current option values */
3121.             && op) {
3122.             /* perminv_mode is set but isn't useful because perm_invent is
3123.                Off; say so after squeezing out enough for it to barely fit */
3124.             if (iflags.perminv_mode == InvOptInUse)
3125.                 (void) strsubst(opts, " currently", "");
3126.             else
3127.                 (void) strsubst(opts, " inventory", " invent");
3128.             Strcat(opts, (((iflags.perminv_mode & InvSparse) != 0) ? " (Off)"
3129.                           : " ('perm_invent' is Off)"));
3130.         }
3131.     } else if (req == get_cnf_val) {
3132.         Sprintf(opts, "%s", perminv_modes[iflags.perminv_mode][0]);
3133.     }
3134.     return retval;
3135. }
3136. 
3137. staticfn int
3138. optfn_petattr(
3139.     int optidx, int req, boolean negated,
3140.     char *opts, char *op)
3141. {
3142.     int retval = optn_ok;
3143. 
3144.     if (req == do_init) {
3145.         return optn_ok;
3146.     }
3147.     if (req == do_set) {
3148.         /* WINCAP2 petattr:string */
3149. 
3150.         op = string_for_opt(opts, negated);
3151.         if (op != empty_optstr && negated) {
3152.             bad_negation(allopt[optidx].name, TRUE);
3153.             retval = optn_err;
3154.         } else if (op != empty_optstr) {
3155. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS)
3156.             int itmp = match_str2attr(op, FALSE);
3157. 
3158.             if (itmp == -1) {
3159.                 config_error_add("Unknown %s parameter '%s'",
3160.                                  allopt[optidx].name, opts);
3161.                 retval = optn_err;
3162.             } else
3163.                 iflags.wc2_petattr = itmp;
3164. #else
3165.             iflags.wc2_petattr = ATR_INVERSE;
3166. #endif
3167.         } else if (negated) {
3168.             iflags.wc2_petattr = ATR_NONE;
3169.         }
3170.         if (retval != optn_err) {
3171.             iflags.hilite_pet = (iflags.wc2_petattr != ATR_NONE);
3172.             if (!go.opt_initial)
3173.                 go.opt_need_redraw = TRUE;
3174.         }
3175.         return retval;
3176.     }
3177.     if (req == get_val || req == get_cnf_val) {
3178. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS)
3179.         if (WINDOWPORT(tty) || WINDOWPORT(curses)) {
3180.             Strcpy(opts, attr2attrname(iflags.wc2_petattr));
3181.         } else
3182. #endif
3183.         if (iflags.wc2_petattr != 0)
3184.             Sprintf(opts, "0x%08x", iflags.wc2_petattr);
3185.         else if (req == get_cnf_val)
3186.             opts[0] = '\0';
3187.         else
3188.             Strcpy(opts, defopt);
3189.     }
3190.     if (req == do_handler) {
3191.         return handler_petattr();
3192.     }
3193.     return optn_ok;
3194. }
3195. 
3196. staticfn int
3197. optfn_pettype(
3198.     int optidx, int req, boolean negated,
3199.     char *opts, char *op)
3200. {
3201.     if (req == do_init) {
3202.         return optn_ok;
3203.     }
3204.     if (req == do_set) {
3205.         if ((op = string_for_env_opt(allopt[optidx].name, opts, negated))
3206.             != empty_optstr) {
3207.             switch (lowc(*op)) {
3208.             case 'd': /* dog */
3209.                 gp.preferred_pet = 'd';
3210.                 break;
3211.             case 'c': /* cat */
3212.             case 'f': /* feline */
3213.                 gp.preferred_pet = 'c';
3214.                 break;
3215.             case 'h': /* horse */
3216.             case 'q': /* quadruped */
3217.                 /* avoids giving "unrecognized type of pet" but
3218.                    pet_type(dog.c) won't actually honor this */
3219.                 gp.preferred_pet = 'h';
3220.                 break;
3221.             case 'n': /* no pet */
3222.                 gp.preferred_pet = 'n';
3223.                 break;
3224.             case 'r': /* random */
3225.             case '*': /* random */
3226.                 gp.preferred_pet = '\0';
3227.                 break;
3228.             default:
3229.                 config_error_add("Unrecognized pet type '%s'.", op);
3230.                 return optn_err;
3231.                 break;
3232.             }
3233.         } else if (negated)
3234.             gp.preferred_pet = 'n';
3235.         return optn_ok;
3236.     }
3237.     if (req == get_val) {
3238.         Sprintf(opts, "%s", (gp.preferred_pet == 'c') ? "cat"
3239.                            : (gp.preferred_pet == 'd') ? "dog"
3240.                              : (gp.preferred_pet == 'h') ? "horse"
3241.                                : (gp.preferred_pet == 'n') ? "none"
3242.                                  : "random");
3243.         return optn_ok;
3244.     }
3245.     if (req == get_cnf_val) {
3246.         if (gp.preferred_pet)
3247.             Sprintf(opts, "%c", gp.preferred_pet);
3248.         else
3249.             opts[0] = '\0';
3250.         return optn_ok;
3251.     }
3252.     return optn_ok;
3253. }
3254. 
3255. staticfn int
3256. optfn_pickup_burden(
3257.     int optidx, int req, boolean negated UNUSED,
3258.     char *opts, char *op)
3259. {
3260.     if (req == do_init) {
3261.         return optn_ok;
3262.     }
3263.     if (req == do_set) {
3264.         /* maximum burden picked up before prompt (Warren Cheung) */
3265. 
3266.         if ((op = string_for_env_opt(allopt[optidx].name, opts, FALSE))
3267.             != empty_optstr) {
3268.             switch (lowc(*op)) {
3269.             case 'u': /* Unencumbered */
3270.                 flags.pickup_burden = UNENCUMBERED;
3271.                 break;
3272.             case 'b': /* Burdened (slight encumbrance) */
3273.                 flags.pickup_burden = SLT_ENCUMBER;
3274.                 break;
3275.             case 's': /* streSsed (moderate encumbrance) */
3276.                 flags.pickup_burden = MOD_ENCUMBER;
3277.                 break;
3278.             case 'n': /* straiNed (heavy encumbrance) */
3279.                 flags.pickup_burden = HVY_ENCUMBER;
3280.                 break;
3281.             case 'o': /* OverTaxed (extreme encumbrance) */
3282.             case 't':
3283.                 flags.pickup_burden = EXT_ENCUMBER;
3284.                 break;
3285.             case 'l': /* overLoaded */
3286.                 flags.pickup_burden = OVERLOADED;
3287.                 break;
3288.             default:
3289.                 config_error_add("Unknown %s parameter '%s'",
3290.                                  allopt[optidx].name, op);
3291.                 return optn_err;
3292.             }
3293.         } else
3294.             return optn_err;
3295.         return optn_ok;
3296.     }
3297.     if (req == get_val || req == get_cnf_val) {
3298.         Sprintf(opts, "%s", burdentype[flags.pickup_burden]);
3299.         return optn_ok;
3300.     }
3301.     if (req == do_handler) {
3302.         return handler_pickup_burden();
3303.     }
3304.     return optn_ok;
3305. }
3306. 
3307. staticfn int
3308. optfn_pickup_types(
3309.     int optidx, int req, boolean negated,
3310.     char *opts, char *op)
3311. {
3312.     char ocl[MAXOCLASSES + 1], tbuf[MAXOCLASSES + 1], qbuf[QBUFSZ],
3313.         abuf[BUFSZ];
3314.     int oc_sym;
3315.     unsigned num;
3316.     boolean badopt = FALSE, compat = (strlen(opts) <= 6), use_menu;
3317. 
3318.     if (req == do_init) {
3319.         return optn_ok;
3320.     }
3321.     if (req == do_set) {
3322.         /* types of objects to pick up automatically */
3323. 
3324.         oc_to_str(flags.pickup_types, tbuf);
3325.         flags.pickup_types[0] = '\0'; /* all */
3326.         op = string_for_opt(opts, (compat || !go.opt_initial));
3327.         if (op == empty_optstr) {
3328.             if (compat || negated || go.opt_initial) {
3329.                 /* for backwards compatibility, "pickup" without a
3330.                    value is a synonym for autopickup of all types
3331.                    (and during initialization, we can't prompt yet) */
3332.                 flags.pickup = !negated;
3333.                 return optn_ok;
3334.             }
3335.             oc_to_str(flags.inv_order, ocl);
3336.             use_menu = TRUE;
3337.             if (flags.menu_style == MENU_TRADITIONAL
3338.                 || flags.menu_style == MENU_COMBINATION) {
3339.                 boolean wasspace;
3340. 
3341.                 use_menu = FALSE;
3342.                 Sprintf(qbuf, "New %s: [%s am] (%s)", allopt[optidx].name,
3343.                         ocl, *tbuf ? tbuf : "all");
3344.                 abuf[0] = '\0';
3345.                 getlin(qbuf, abuf);
3346.                 wasspace = (abuf[0] == ' '); /* before mungspaces */
3347.                 op = mungspaces(abuf);
3348.                 if (wasspace && !abuf[0])
3349.                     ; /* one or more spaces will remove old value */
3350.                 else if (!abuf[0] || abuf[0] == '\033')
3351.                     op = tbuf; /* restore */
3352.                 else if (abuf[0] == 'm')
3353.                     use_menu = TRUE;
3354.                 /* note: abuf[0]=='a' is already handled via clearing
3355.                    the old value (above) as a default action */
3356.             }
3357.             if (use_menu) {
3358.                 if (wizard && !strchr(ocl, VENOM_SYM))
3359.                     strkitten(ocl, VENOM_SYM);
3360.                 (void) choose_classes_menu("Autopickup what?",
3361.                                            1, TRUE, ocl, tbuf);
3362.                 op = tbuf;
3363.             }
3364.         }
3365.         if (negated) {
3366.             bad_negation(allopt[optidx].name, TRUE);
3367.             return optn_err;
3368.         }
3369.         while (*op == ' ')
3370.             op++;
3371.         if (*op != 'a' && *op != 'A') {
3372.             num = 0;
3373.             while (*op) {
3374.                 oc_sym = def_char_to_objclass(*op);
3375.                 /* make sure all are valid obj symbols occurring once */
3376.                 if (oc_sym != MAXOCLASSES
3377.                     && !strchr(flags.pickup_types, oc_sym)) {
3378.                     flags.pickup_types[num] = (char) oc_sym;
3379.                     flags.pickup_types[++num] = '\0';
3380.                 } else
3381.                     badopt = TRUE;
3382.                 op++;
3383.             }
3384.             if (badopt) {
3385.                 config_error_add("Unknown %s parameter '%s'",
3386.                                  allopt[optidx].name, op);
3387.                 return optn_err;
3388.             }
3389.         }
3390.         return optn_ok;
3391.     }
3392.     if (req == get_val || req == get_cnf_val) {
3393.         oc_to_str(flags.pickup_types, ocl);
3394.         Sprintf(opts, "%s", ocl[0] ? ocl : "all");
3395.         return optn_ok;
3396.     }
3397.     if (req == do_handler) {
3398.         return handler_pickup_types();
3399.     }
3400.     return optn_ok;
3401. }
3402. 
3403. staticfn int
3404. optfn_pile_limit(
3405.     int optidx, int req, boolean negated,
3406.     char *opts, char *op)
3407. {
3408.     if (req == do_init) {
3409.         return optn_ok;
3410.     }
3411.     if (req == do_set) {
3412.         /* pile limit: when walking over objects, number which triggers
3413.            "there are several/many objects here" instead of listing them
3414.          */
3415. 
3416.         op = string_for_opt(opts, negated);
3417.         if ((negated && op == empty_optstr)
3418.             || (!negated && op != empty_optstr))
3419.             flags.pile_limit = negated ? 0 : atoi(op);
3420.         else if (negated) {
3421.             bad_negation(allopt[optidx].name, TRUE);
3422.             return optn_err;
3423.         } else /* op == empty_optstr */
3424.             flags.pile_limit = PILE_LIMIT_DFLT;
3425.         /* sanity check */
3426.         if (flags.pile_limit < 0)
3427.             flags.pile_limit = PILE_LIMIT_DFLT;
3428.         return optn_ok;
3429.     }
3430.     if (req == get_val || req == get_cnf_val) {
3431.         Sprintf(opts, "%d", flags.pile_limit);
3432.         return optn_ok;
3433.     }
3434.     return optn_ok;
3435. }
3436. 
3437. staticfn int
3438. optfn_player_selection(
3439.     int optidx, int req, boolean negated,
3440.     char *opts, char *op)
3441. {
3442.     if (req == do_init) {
3443.         return optn_ok;
3444.     }
3445.     if (req == do_set) {
3446.         /* WINCAP player_selection: dialog | prompt/prompts/prompting */
3447. 
3448.         op = string_for_opt(opts, negated);
3449.         if (op != empty_optstr && !negated) {
3450.             if (!strncmpi(op, "dialog", sizeof "dialog" - 1)) {
3451.                 iflags.wc_player_selection = VIA_DIALOG;
3452.             } else if (!strncmpi(op, "prompt", sizeof "prompt" - 1)) {
3453.                 iflags.wc_player_selection = VIA_PROMPTS;
3454.             } else {
3455.                 config_error_add("Unknown %s parameter '%s'",
3456.                                  allopt[optidx].name, op);
3457.                 return optn_err;
3458.             }
3459.         }
3460.         return optn_ok;
3461.     }
3462.     if (req == get_val || req == get_cnf_val) {
3463.         Sprintf(opts, "%s",
3464.                 iflags.wc_player_selection ? "prompts" : "dialog");
3465.         return optn_ok;
3466.     }
3467.     return optn_ok;
3468. }
3469. 
3470. staticfn int
3471. optfn_playmode(
3472.     int optidx, int req, boolean negated,
3473.     char *opts, char *op)
3474. {
3475.     if (req == do_init) {
3476.         return optn_ok;
3477.     }
3478.     if (req == do_set) {
3479.         /* play mode: normal, explore/discovery, or debug/wizard */
3480. 
3481.         if (duplicate || negated)
3482.             return optn_err;
3483.         if (op == empty_optstr)
3484.             return optn_err;
3485.         if (!strncmpi(op, "normal", 6) || !strcmpi(op, "play")) {
3486.             wizard = discover = FALSE;
3487.         } else if (!strncmpi(op, "explore", 6)
3488.                    || !strncmpi(op, "discovery", 6)) {
3489.             wizard = FALSE, discover = TRUE;
3490.         } else if (!strncmpi(op, "debug", 5) || !strncmpi(op, "wizard", 6)) {
3491.             wizard = TRUE, discover = FALSE;
3492.         } else {
3493.             config_error_add("Invalid value for \"%s\":%s",
3494.                              allopt[optidx].name, op);
3495.             return optn_err;
3496.         }
3497.         return optn_ok;
3498.     }
3499.     if (req == get_val || req == get_cnf_val) {
3500.         Strcpy(opts, wizard ? "debug" : discover ? "explore" : "normal");
3501.         return optn_ok;
3502.     }
3503.     return optn_ok;
3504. }
3505. 
3506. staticfn int
3507. optfn_race(
3508.     int optidx,
3509.     int req,
3510.     boolean negated,
3511.     char *opts,
3512.     char *op)
3513. {
3514.     if (req == do_init) {
3515.         return optn_ok;
3516.     }
3517.     if (req == do_set) {
3518.         /* race:string */
3519.         if (!parse_role_opt(optidx, negated, allopt[optidx].name, opts, &op))
3520.             return optn_silenterr;
3521. 
3522.         if (*op != '!') {
3523.             if ((flags.initrace = str2race(op)) == ROLE_NONE) {
3524.                 config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
3525.                 return optn_err;
3526.             }
3527.             gp.pl_race = *op; /* Backwards compatibility */
3528.             saveoptstr(optidx, rolestring(flags.initrace, races, noun));
3529.         }
3530.         return optn_ok;
3531.     }
3532.     if (req == get_val) {
3533.         Sprintf(opts, "%s", rolestring(flags.initrace, races, noun));
3534.         return optn_ok;
3535.     }
3536.     if (req == get_cnf_val) {
3537.         op = get_cnf_role_opt(optidx);
3538.         Strcpy(opts, op ? op : "none");
3539.         return optn_ok;
3540.     }
3541.     return optn_ok;
3542. }
3543. 
3544. staticfn int
3545. optfn_roguesymset(
3546.     int optidx, int req, boolean negated UNUSED,
3547.     char *opts, char *op)
3548. {
3549.     if (req == do_init) {
3550.         return optn_ok;
3551.     }
3552.     if (req == do_set) {
3553.         if (op != empty_optstr) {
3554.             if (gs.symset[ROGUESET].name)
3555.                 free((genericptr_t) gs.symset[ROGUESET].name),
3556.                     gs.symset[ROGUESET].name = 0;
3557.             gs.symset[ROGUESET].name = dupstr(op);
3558.             if (!read_sym_file(ROGUESET)) {
3559.                 clear_symsetentry(ROGUESET, TRUE);
3560.                 config_error_add(
3561.                     "Unable to load symbol set \"%s\" from \"%s\"", op,
3562.                     SYMBOLS);
3563.                 return optn_err;
3564.             } else {
3565.                 if (!go.opt_initial && Is_rogue_level(&u.uz))
3566.                     assign_graphics(ROGUESET);
3567.                 go.opt_need_redraw = go.opt_need_glyph_reset = TRUE;
3568.                 go.opt_symset_changed = TRUE;
3569.             }
3570.         } else
3571.             return optn_err;
3572.         return optn_ok;
3573.     }
3574.     if (req == get_val || req == get_cnf_val) {
3575.         Sprintf(opts, "%s",
3576.                 gs.symset[ROGUESET].name ? gs.symset[ROGUESET].name
3577.                                          : "default");
3578.         if (gc.currentgraphics == ROGUESET && gs.symset[ROGUESET].name)
3579.             Strcat(opts, ", active");
3580.         return optn_ok;
3581.     }
3582.     if (req == do_handler) {
3583.         return handler_symset(optidx);
3584.     }
3585.     return optn_ok;
3586. }
3587. 
3588. staticfn int
3589. optfn_role(
3590.     int optidx,
3591.     int req,
3592.     boolean negated,
3593.     char *opts,
3594.     char *op)
3595. {
3596.     if (req == do_init) {
3597.         return optn_ok;
3598.     }
3599.     if (req == do_set) {
3600.         /* role:string */
3601.         if (!parse_role_opt(optidx, negated, allopt[optidx].name, opts, &op))
3602.             return optn_silenterr;
3603. 
3604.         if (*op != '!') {
3605.             if ((flags.initrole = str2role(op)) == ROLE_NONE) {
3606.                 config_error_add("Unknown %s '%s'", allopt[optidx].name, op);
3607.                 return optn_err;
3608.             }
3609.             nmcpy(svp.pl_character, op, PL_NSIZ); /* Backwards compat */
3610.             saveoptstr(optidx, rolestring(flags.initrole, roles, name.m));
3611.         }
3612.         return optn_ok;
3613.     }
3614.     if (req == get_val) {
3615.         Sprintf(opts, "%s", rolestring(flags.initrole, roles, name.m));
3616.         return optn_ok;
3617.     }
3618.     if (req == get_cnf_val) {
3619.         op = get_cnf_role_opt(optidx);
3620.         Strcpy(opts, op ? op : "none");
3621.         return optn_ok;
3622.     }
3623.     return optn_ok;
3624. }
3625. 
3626. staticfn int
3627. optfn_runmode(
3628.     int optidx, int req, boolean negated,
3629.     char *opts, char *op)
3630. {
3631.     if (req == do_init) {
3632.         return optn_ok;
3633.     }
3634.     if (req == do_set) {
3635.         if (negated) {
3636.             flags.runmode = RUN_TPORT;
3637.         } else if (op != empty_optstr) {
3638.             if (str_start_is("teleport", op, TRUE))
3639.                 flags.runmode = RUN_TPORT;
3640.             else if (str_start_is("run", op, TRUE))
3641.                 flags.runmode = RUN_LEAP;
3642.             else if (str_start_is("walk", op, TRUE))
3643.                 flags.runmode = RUN_STEP;
3644.             else if (str_start_is("crawl", op, TRUE))
3645.                 flags.runmode = RUN_CRAWL;
3646.             else {
3647.                 config_error_add("Unknown %s parameter '%s'",
3648.                                  allopt[optidx].name, op);
3649.                 return optn_err;
3650.             }
3651.         } else {
3652.             config_error_add("Value is mandatory for %s",
3653.                              allopt[optidx].name);
3654.             return optn_err;
3655.         }
3656.         return optn_ok;
3657.     }
3658.     if (req == get_val || req == get_cnf_val) {
3659.         Sprintf(opts, "%s", runmodes[flags.runmode]);
3660.         return optn_ok;
3661.     }
3662.     if (req == do_handler) {
3663.         return handler_runmode();
3664.     }
3665.     return optn_ok;
3666. }
3667. 
3668. staticfn int
3669. optfn_scores(
3670.     int optidx, int req, boolean negated,
3671.     char *opts, char *op)
3672. {
3673.     if (req == do_init) {
3674.         return optn_ok;
3675.     }
3676.     if (req == do_set) {
3677.         /* scores:5t[op] 5a[round] o[wn] */
3678. 
3679.         if ((op = string_for_opt(opts, FALSE)) == empty_optstr)
3680.             return optn_err;
3681. 
3682.         /* 5.0: earlier versions left old values for unspecified arguments
3683.            if player's scores:foo option only specified some of the three;
3684.            in particular, attempting to use 'scores:own' rather than
3685.            'scores:0 top/0 around/own' didn't work as intended */
3686.         flags.end_top = flags.end_around = 0, flags.end_own = FALSE;
3687. 
3688.         if (negated)
3689.             op = eos(op);
3690. 
3691.         while (*op) {
3692.             int inum = 1;
3693. 
3694.             negated = (*op == '!') || !strncmpi(op, "no", 2);
3695.             if (negated)
3696.                 op += (*op == '!') ? 1 : (op[2] != '-') ? 2 : 3;
3697. 
3698.             if (digit(*op)) {
3699.                 inum = atoi(op);
3700.                 while (digit(*op))
3701.                     op++;
3702.             }
3703.             while (*op == ' ')
3704.                 op++;
3705. 
3706.             switch (lowc(*op)) {
3707.             case 't':
3708.                 flags.end_top = negated ? 0 : inum;
3709.                 break;
3710.             case 'a':
3711.                 flags.end_around = negated ? 0 : inum;
3712.                 break;
3713.             case 'o':
3714.                 flags.end_own = (negated || !inum) ? FALSE : TRUE;
3715.                 break;
3716.             case 'n': /* none */
3717.                 flags.end_top = flags.end_around = 0, flags.end_own = FALSE;
3718.                 break;
3719.             case '-':
3720.                 if (digit(*(op + 1))) {
3721.                     config_error_add(
3722.                        "Values for %s:top and %s:around must not be negative",
3723.                                      allopt[optidx].name,
3724.                                      allopt[optidx].name);
3725.                     return optn_silenterr;
3726.                 }
3727.                 FALLTHROUGH;
3728.                 /*FALLTHRU*/
3729.             default:
3730.                 config_error_add("Unknown %s parameter '%s'",
3731.                                  allopt[optidx].name, op);
3732.                 return optn_silenterr;
3733.             }
3734.             /* "3a" is sufficient but accept "3around" (or "3abracadabra") */
3735.             while (letter(*op))
3736.                 op++;
3737.             /* t, a, and o can be separated by space(s) or slash or both */
3738.             while (*op == ' ')
3739.                 op++;
3740.             if (*op == '/')
3741.                 op++;
3742.         }
3743.         return optn_ok;
3744.     }
3745.     if (req == get_val || req == get_cnf_val) {
3746.         *opts = '\0';
3747.         if (flags.end_top > 0)
3748.             Sprintf(opts, "%d top", flags.end_top);
3749.         if (flags.end_around > 0)
3750.             Sprintf(eos(opts), "%s%d around",
3751.                     (flags.end_top > 0) ? "/" : "", flags.end_around);
3752.         if (flags.end_own)
3753.             Sprintf(eos(opts), "%sown",
3754.                     (flags.end_top > 0 || flags.end_around > 0) ? "/" : "");
3755.         if (!*opts)
3756.             Strcpy(opts, "none");
3757.         return optn_ok;
3758.     }
3759.     return optn_ok;
3760. }
3761. 
3762. staticfn int
3763. optfn_scroll_amount(
3764.     int optidx, int req, boolean negated,
3765.     char *opts, char *op)
3766. {
3767.     if (req == do_init) {
3768.         return optn_ok;
3769.     }
3770.     if (req == do_set) {
3771.         /* WINCAP scroll_amount:nn */
3772. 
3773.         op = string_for_opt(opts, negated);
3774.         if ((negated && op == empty_optstr)
3775.             || (!negated && op != empty_optstr)) {
3776.             iflags.wc_scroll_amount = negated ? 1 : atoi(op);
3777.         } else if (negated) {
3778.             bad_negation(allopt[optidx].name, TRUE);
3779.             return optn_err;
3780.         }
3781.         return optn_ok;
3782.     }
3783.     if (req == get_val || req == get_cnf_val) {
3784.         if (iflags.wc_scroll_amount)
3785.             Sprintf(opts, "%d", iflags.wc_scroll_amount);
3786.         else
3787.             Strcpy(opts, defopt);
3788.         return optn_ok;
3789.     }
3790.     return optn_ok;
3791. }
3792. 
3793. staticfn int
3794. optfn_scroll_margin(
3795.     int optidx, int req, boolean negated,
3796.     char *opts, char *op)
3797. {
3798.     if (req == do_init) {
3799.         return optn_ok;
3800.     }
3801.     if (req == do_set) {
3802.         /* WINCAP scroll_margin:nn */
3803.         op = string_for_opt(opts, negated);
3804.         if ((negated && op == empty_optstr)
3805.             || (!negated && op != empty_optstr)) {
3806.             iflags.wc_scroll_margin = negated ? 5 : atoi(op);
3807.         } else if (negated) {
3808.             bad_negation(allopt[optidx].name, TRUE);
3809.             return optn_err;
3810.         }
3811.         return optn_ok;
3812.     }
3813.     if (req == get_val || req == get_cnf_val) {
3814.         if (iflags.wc_scroll_margin)
3815.             Sprintf(opts, "%d", iflags.wc_scroll_margin);
3816.         else
3817.             Strcpy(opts, defopt);
3818.         return optn_ok;
3819.     }
3820.     return optn_ok;
3821. }
3822. 
3823. staticfn int
3824. optfn_soundlib(
3825.     int optidx, int req, boolean negated UNUSED,
3826.     char *opts, char *op)
3827. {
3828.     char soundlibbuf[WINTYPELEN];
3829. 
3830.     if (req == do_init) {
3831.         return optn_ok;
3832.     }
3833.     if (req == do_set) {
3834.         /*
3835.          * soundlib:  option to choose the interface for binaries built
3836.          * with support for more than the default interface (nosound).
3837.          *
3838.          * Option processing sets gc.chosen_soundlib. A later call
3839.          * to activate_chosen_soundlib() actually activates it, and
3840.          * sets gc.active_soundlib.
3841.          */
3842.         if ((op = string_for_env_opt(allopt[optidx].name, opts, FALSE))
3843.             != empty_optstr) {
3844.             enum soundlib_ids option_id;
3845. 
3846.             get_soundlib_name(soundlibbuf, WINTYPELEN);
3847.             option_id = soundlib_id_from_opt(op);
3848.             gc.chosen_soundlib = option_id;
3849.             assign_soundlib(gc.chosen_soundlib);
3850.         } else
3851.             return optn_err;
3852.         return optn_ok;
3853.     }
3854.     if (req == get_val || req == get_cnf_val) {
3855.         get_soundlib_name(soundlibbuf, WINTYPELEN);
3856.         Sprintf(opts, "%s", soundlibbuf);
3857.         return optn_ok;
3858.     }
3859.     return optn_ok;
3860. }
3861. 
3862. staticfn int
3863. optfn_sortdiscoveries(
3864.     int optidx, int req, boolean negated,
3865.     char *opts, char *op)
3866. {
3867.     if (req == do_init) {
3868.         flags.discosort = 'o';
3869.         return optn_ok;
3870.     }
3871.     if (req == do_set) {
3872.         op = string_for_env_opt(allopt[optidx].name, opts, FALSE);
3873.         if (negated) {
3874.             flags.discosort = 'o';
3875.         } else if (op != empty_optstr) {
3876.             switch (lowc(*op)) {
3877.             case '0':
3878.             case 'o': /* order of discovery */
3879.                 flags.discosort = 'o';
3880.                 break;
3881.             case '1':
3882.             case 's': /* sortloot order (subclasses for some classes) */
3883.                 flags.discosort = 's';
3884.                 break;
3885.             case '2':
3886.             case 'c': /* alphabetical within each class */
3887.                 flags.discosort = 'c';
3888.                 break;
3889.             case '3':
3890.             case 'a': /* alphabetical across all classes */
3891.                 flags.discosort = 'a';
3892.                 break;
3893.             default:
3894.                 config_error_add("Unknown %s parameter '%s'",
3895.                                  allopt[optidx].name, op);
3896.                 return optn_silenterr;
3897.             }
3898.         } else
3899.             return optn_err;
3900.         return optn_ok;
3901.     }
3902.     if (req == get_val || req == get_cnf_val) {
3903.         get_sortdisco(opts, (req == get_cnf_val) ? TRUE : FALSE);
3904.         return optn_ok;
3905.     }
3906.     if (req == do_handler) {
3907.         /* return handler_sortdiscoveries(); */
3908.         (void) choose_disco_sort(0); /* o_init.c */
3909.     }
3910.     return optn_ok;
3911. }
3912. 
3913. staticfn int
3914. optfn_sortloot(
3915.     int optidx, int req, boolean negated UNUSED,
3916.     char *opts, char *op)
3917. {
3918.     int i;
3919. 
3920.     if (req == do_init) {
3921.         return optn_ok;
3922.     }
3923.     if (req == do_set) {
3924.         op = string_for_env_opt(allopt[optidx].name, opts, FALSE);
3925.         if (op != empty_optstr) {
3926.             char c = lowc(*op);
3927. 
3928.             switch (c) {
3929.             case 'n': /* none */
3930.             case 'l': /* loot (pickup) */
3931.             case 'f': /* full (pickup + invent) */
3932.                 flags.sortloot = c;
3933.                 break;
3934.             default:
3935.                 config_error_add("Unknown %s parameter '%s'",
3936.                                  allopt[optidx].name, op);
3937.                 return optn_err;
3938.             }
3939.         } else
3940.             return optn_err;
3941.         return optn_ok;
3942.     }
3943.     if (req == get_val || req == get_cnf_val) {
3944.         for (i = 0; i < SIZE(sortltype); i++)
3945.             if (flags.sortloot == sortltype[i][0]) {
3946.                 Strcpy(opts, sortltype[i]);
3947.                 break;
3948.             }
3949.         return optn_ok;
3950.     }
3951.     if (req == do_handler) {
3952.         return handler_sortloot();
3953.     }
3954.     return optn_ok;
3955. }
3956. 
3957. staticfn int
3958. optfn_sortvanquished(
3959.     int optidx, int req, boolean negated,
3960.     char *opts, char *op)
3961. {
3962.     extern const char *const vanqorders[][3]; /* insight.c */
3963.     static const char vanqmodes[] = "tdaACcnz";
3964.     const char *optname = allopt[optidx].name;
3965. 
3966.     if (req == do_init) {
3967.         flags.vanq_sortmode = VANQ_MLVL_MNDX; /* 0 => 't' */
3968.         return optn_ok;
3969.     }
3970.     if (req == do_set) {
3971.         op = string_for_env_opt(allopt[optidx].name, opts, FALSE);
3972.         if (negated) {
3973.             flags.vanq_sortmode = VANQ_MLVL_MNDX; /* 0 => 't' */
3974.         } else if (op != empty_optstr) {
3975.             const char *p;
3976.             int vndx = 0;
3977. 
3978.             if ((p = strchr(vanqmodes, *op)) != 0) {
3979.                 vndx = (int) (p - vanqmodes);
3980.             } else if (strchr("01234567", *op)) {
3981.                 vndx = *op - '0';
3982.             } else {
3983.                 config_error_add("Unknown %s parameter '%s'", optname, op);
3984.                 return optn_silenterr;
3985.             }
3986.             flags.vanq_sortmode = (uchar) vndx;
3987.         } else
3988.             return optn_err;
3989.         return optn_ok;
3990.     }
3991.     if (req == get_val || req == get_cnf_val) {
3992.         Strcpy(opts, vanqorders[flags.vanq_sortmode][0]);
3993.         if (req == get_val)
3994.             Sprintf(eos(opts), ": %s", vanqorders[flags.vanq_sortmode][1]);
3995.         return optn_ok;
3996.     }
3997.     if (req == do_handler) {
3998.         uchar prev_sortmode = flags.vanq_sortmode;
3999. 
4000.         /* return handler_sortvanquished(); */
4001.         (void) set_vanq_order(TRUE); /* insight.c */
4002.         pline("'%s' %s \"%s: %s\".", optname,
4003.               (flags.vanq_sortmode == prev_sortmode)
4004.                  ? "not changed, still"
4005.                  : "changed to",
4006.               vanqorders[flags.vanq_sortmode][0],
4007.               vanqorders[flags.vanq_sortmode][1]);
4008.     }
4009.     return optn_ok;
4010. }
4011. 
4012. staticfn int
4013. optfn_statushilites(
4014.     int optidx UNUSED, int req, boolean negated,
4015.     char *opts, char *op)
4016. {
4017.     if (req == do_init) {
4018.         return optn_ok;
4019.     }
4020.     if (req == do_set) {
4021.         /* control over whether highlights should be displayed (non-zero), and
4022.            also for how long to show temporary ones (N turns; default 3) */
4023. 
4024. #ifdef STATUS_HILITES
4025.         if (negated) {
4026.             iflags.hilite_delta = 0L;
4027.         } else {
4028.             op = string_for_opt(opts, TRUE);
4029.             iflags.hilite_delta = (op == empty_optstr || !*op) ? 3L
4030.                                                                : atol(op);
4031.             if (iflags.hilite_delta < 0L)
4032.                 iflags.hilite_delta = 1L;
4033.         }
4034.         if (!go.opt_from_file)
4035.             reset_status_hilites();
4036.         return optn_ok;
4037. #else
4038.         nhUse(negated);
4039.         nhUse(op);
4040.         config_error_add("'%s' is not supported", allopt[optidx].name);
4041.         return optn_err;
4042. #endif
4043.     }
4044.     if (req == get_val) {
4045. #ifdef STATUS_HILITES
4046.         if (!iflags.hilite_delta)
4047.             Strcpy(opts, "0 (off: don't highlight status fields)");
4048.         else
4049.             Sprintf(opts, "%ld (on: highlight status for %ld turns)",
4050.                     iflags.hilite_delta, iflags.hilite_delta);
4051. #else
4052.         Strcpy(opts, "unsupported");
4053. #endif
4054.         return optn_ok;
4055.     }
4056.     if (req == get_cnf_val) {
4057. #ifdef STATUS_HILITES
4058.         Sprintf(opts, "%ld", iflags.hilite_delta);
4059. #else
4060.         opts[0] = '\0';
4061. #endif
4062.     }
4063.     return optn_ok;
4064. }
4065. 
4066. staticfn int
4067. optfn_statuslines(
4068.     int optidx, int req, boolean negated,
4069.     char *opts, char *op)
4070. {
4071.     int retval = optn_ok, itmp = 0;
4072. 
4073.     if (req == do_init) {
4074.         return optn_ok;
4075.     }
4076.     if (req == do_set) {
4077.         /* WINCAP2
4078.          * statuslines:n */
4079. 
4080.         op = string_for_opt(opts, negated);
4081.         if (negated) {
4082.             bad_negation(allopt[optidx].name, TRUE);
4083.             itmp = 2;
4084.             retval = optn_err;
4085.         } else if (op != empty_optstr) {
4086.             itmp = atoi(op);
4087.         }
4088.         if (itmp < 2 || itmp > 3) {
4089.             config_error_add("'%s:%s' is invalid; must be 2 or 3",
4090.                              allopt[optidx].name, op);
4091.             retval = optn_silenterr;
4092.         } else {
4093.             iflags.wc2_statuslines = itmp;
4094.             if (!go.opt_initial)
4095.                 go.opt_need_redraw = TRUE;
4096.         }
4097.         return retval;
4098.     }
4099.     if (req == get_val || req == get_cnf_val) {
4100.         if (wc2_supported(allopt[optidx].name))
4101.             Strcpy(opts, (iflags.wc2_statuslines < 3) ? "2" : "3");
4102.         else
4103.             Strcpy(opts, "unknown");
4104.         return optn_ok;
4105.     }
4106.     return optn_ok;
4107. }
4108. 
4109. #ifdef WIN32CON
4110. staticfn int
4111. optfn_subkeyvalue(
4112.     int optidx UNUSED, int req, boolean negated UNUSED,
4113.     char *opts, char *op UNUSED)
4114. {
4115.     if (req == do_init) {
4116.         return optn_ok;
4117.     }
4118.     if (req == do_set) {
4119.         if (op == empty_optstr)
4120.             return optn_err;
4121. #ifdef TTY_GRAPHICS
4122.         map_subkeyvalue(op);
4123. #endif
4124.         return optn_ok;
4125.     }
4126.     if (req == get_val || req == get_cnf_val) {
4127.         opts[0] = '\0';
4128.         return optn_ok;
4129.     }
4130.     return optn_ok;
4131. }
4132. #endif /* WIN32CON */
4133. 
4134. staticfn int
4135. optfn_suppress_alert(
4136.     int optidx, int req, boolean negated,
4137.     char *opts, char *op)
4138. {
4139.     if (req == do_init) {
4140.         return optn_ok;
4141.     }
4142.     if (req == do_set) {
4143.         if (negated) {
4144.             bad_negation(allopt[optidx].name, FALSE);
4145.             return optn_err;
4146.         } else if (op != empty_optstr)
4147.             (void) feature_alert_opts(op, allopt[optidx].name);
4148.         return optn_ok;
4149.     }
4150.     if (req == get_val || req == get_cnf_val) {
4151.         if (req == get_cnf_val && flags.suppress_alert == 0L)
4152.             opts[0] = '\0';
4153.         else if (flags.suppress_alert == 0L)
4154.             Strcpy(opts, none);
4155.         else
4156.             Sprintf(opts, "%lu.%lu.%lu", FEATURE_NOTICE_VER_MAJ,
4157.                     FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH);
4158.         return optn_ok;
4159.     }
4160.     return optn_ok;
4161. }
4162. 
4163. extern const char *const known_handling[];     /* symbols.c */
4164. extern const char *const known_restrictions[]; /* symbols.c */
4165. 
4166. staticfn int
4167. optfn_symset(
4168.     int optidx, int req, boolean negated UNUSED,
4169.     char *opts, char *op)
4170. {
4171.     if (req == do_init) {
4172.         return optn_ok;
4173.     }
4174.     if (req == do_set) {
4175.         if (op != empty_optstr) {
4176.             if (gs.symset[PRIMARYSET].name)
4177.                 free((genericptr_t) gs.symset[PRIMARYSET].name),
4178.                      gs.symset[PRIMARYSET].name = 0;
4179.             gs.symset[PRIMARYSET].name = dupstr(op);
4180.             if (!read_sym_file(PRIMARYSET)) {
4181.                 clear_symsetentry(PRIMARYSET, TRUE);
4182.                 config_error_add(
4183.                     "Unable to load symbol set \"%s\" from \"%s\"", op,
4184.                     SYMBOLS);
4185.                 return optn_err;
4186.             } else {
4187.                 if (gs.symset[PRIMARYSET].handling) {
4188. #ifndef ENHANCED_SYMBOLS
4189.                     if (gs.symset[PRIMARYSET].handling == H_UTF8) {
4190.                         config_error_add(
4191.                                    "Unavailable symset handler \"%s\" for %s",
4192.                                          known_handling[H_UTF8], op);
4193.                         load_symset("default", PRIMARYSET);
4194.                     }
4195. #endif
4196.                 }
4197.                 switch_symbols(gs.symset[PRIMARYSET].name != (char *) 0);
4198.                 go.opt_need_redraw = go.opt_need_glyph_reset = TRUE;
4199.                 go.opt_symset_changed = TRUE;
4200.             }
4201.         } else
4202.             return optn_err;
4203.         return optn_ok;
4204.     }
4205.     if (req == get_val) {
4206.         Sprintf(opts, "%s",
4207.                 gs.symset[PRIMARYSET].name ? gs.symset[PRIMARYSET].name
4208.                                           : "default");
4209.         if (gc.currentgraphics == PRIMARYSET && gs.symset[PRIMARYSET].name)
4210.             Strcat(opts, ", active");
4211.         if (gs.symset[PRIMARYSET].handling) {
4212.             Sprintf(eos(opts), ", handler=%s",
4213.                     known_handling[gs.symset[PRIMARYSET].handling]);
4214.         }
4215.         return optn_ok;
4216.     }
4217.     if (req == get_cnf_val) {
4218.         Sprintf(opts, "%s",
4219.                 gs.symset[PRIMARYSET].name ? gs.symset[PRIMARYSET].name
4220.                                           : "default");
4221.         return optn_ok;
4222.     }
4223.     if (req == do_handler) {
4224.         int reslt;
4225. 
4226.         if (!glyphid_cache_status())
4227.             fill_glyphid_cache();
4228.         reslt = handler_symset(optidx);
4229.         if (glyphid_cache_status())
4230.             free_glyphid_cache();
4231.         /* apply_customizations(gc.currentgraphics,
4232.                         (do_custom_colors | do_custom_symbols)); */
4233.         return reslt;
4234.     }
4235.     return optn_ok;
4236. }
4237. 
4238. staticfn int
4239. optfn_term_cols(
4240.     int optidx, int req, boolean negated,
4241.     char *opts, char *op)
4242. {
4243.     int retval = optn_ok;
4244.     long ltmp;
4245. 
4246.     if (req == do_init) {
4247.         return optn_ok;
4248.     }
4249.     if (req == do_set) {
4250.         /* WINCAP2
4251.          * term_cols:amount */
4252. 
4253.         if ((op = string_for_opt(opts, negated)) != empty_optstr) {
4254.             ltmp = atol(op);
4255.             /* just checks atol() sanity, not logical window size sanity
4256.              */
4257.             if (ltmp <= 0L || ltmp >= (long) LARGEST_INT) {
4258.                 config_error_add("Invalid %s: %ld", allopt[optidx].name,
4259.                                  ltmp);
4260.                 retval = optn_err;
4261.             } else {
4262.                 iflags.wc2_term_cols = (int) ltmp;
4263.             }
4264.         }
4265.         return retval;
4266.     }
4267.     if (req == get_val || req == get_cnf_val) {
4268.         if (iflags.wc2_term_cols)
4269.             Sprintf(opts, "%d", iflags.wc2_term_cols);
4270.         else if (req == get_cnf_val)
4271.             opts[0] = '\0';
4272.         else
4273.             Strcpy(opts, defopt);
4274.         return optn_ok;
4275.     }
4276.     return optn_ok;
4277. }
4278. 
4279. staticfn int
4280. optfn_term_rows(
4281.     int optidx, int req, boolean negated,
4282.     char *opts, char *op)
4283. {
4284.     int retval = optn_ok;
4285.     long ltmp;
4286. 
4287.     if (req == do_init) {
4288.         return optn_ok;
4289.     }
4290.     if (req == do_set) {
4291.         /* WINCAP2
4292.          * term_rows:amount */
4293. 
4294.         if ((op = string_for_opt(opts, negated)) != empty_optstr) {
4295.             ltmp = atol(op);
4296.             /* just checks atol() sanity, not logical window size sanity
4297.              */
4298.             if (ltmp <= 0L || ltmp >= (long) LARGEST_INT) {
4299.                 config_error_add("Invalid %s: %ld", allopt[optidx].name,
4300.                                  ltmp);
4301.                 retval = optn_err;
4302.             } else {
4303.                 iflags.wc2_term_rows = (int) ltmp;
4304.             }
4305.         }
4306.         return retval;
4307.     }
4308.     if (req == get_val || req == get_cnf_val) {
4309.         if (iflags.wc2_term_rows)
4310.             Sprintf(opts, "%d", iflags.wc2_term_rows);
4311.         else if (req == get_cnf_val)
4312.             opts[0] = '\0';
4313.         else
4314.             Strcpy(opts, defopt);
4315.         return optn_ok;
4316.     }
4317.     return optn_ok;
4318. }
4319. 
4320. staticfn int
4321. optfn_tile_file(
4322.     int optidx UNUSED, int req, boolean negated UNUSED,
4323.     char *opts, char *op)
4324. {
4325.     if (req == do_init) {
4326.         return optn_ok;
4327.     }
4328.     if (req == do_set) {
4329.         /* WINCAP tile_file:name */
4330.         if (op != empty_optstr) {
4331.             if (iflags.wc_tile_file)
4332.                 free(iflags.wc_tile_file);
4333.             iflags.wc_tile_file = dupstr(op);
4334.         } else
4335.             return optn_err;
4336.         return optn_ok;
4337.     }
4338.     if (req == get_val) {
4339.         Sprintf(opts, "%s",
4340.                 iflags.wc_tile_file ? iflags.wc_tile_file : defopt);
4341.         return optn_ok;
4342.     }
4343.     if (req == get_cnf_val) {
4344.         if (iflags.wc_tile_file)
4345.             Sprintf(opts, "%s", iflags.wc_tile_file);
4346.         else
4347.             opts[0] = '\0';
4348.         return optn_ok;
4349.     }
4350.     return optn_ok;
4351. }
4352. 
4353. staticfn int
4354. optfn_tile_height(
4355.     int optidx, int req, boolean negated,
4356.     char *opts, char *op)
4357. {
4358.     if (req == do_init) {
4359.         return optn_ok;
4360.     }
4361.     if (req == do_set) {
4362.         /* WINCAP tile_height:nn */
4363.         op = string_for_opt(opts, negated);
4364.         if ((negated && op == empty_optstr)
4365.             || (!negated && op != empty_optstr)) {
4366.             iflags.wc_tile_height = negated ? 0 : atoi(op);
4367.         } else if (negated) {
4368.             bad_negation(allopt[optidx].name, TRUE);
4369.             return optn_err;
4370.         }
4371.         return optn_ok;
4372.     }
4373.     if (req == get_val || req == get_cnf_val) {
4374.         if (iflags.wc_tile_height)
4375.             Sprintf(opts, "%d", iflags.wc_tile_height);
4376.         else if (req == get_cnf_val)
4377.             opts[0] = '\0';
4378.         else
4379.             Strcpy(opts, defopt);
4380.         return optn_ok;
4381.     }
4382.     return optn_ok;
4383. }
4384. 
4385. staticfn int
4386. optfn_tile_width(
4387.     int optidx, int req, boolean negated,
4388.     char *opts, char *op)
4389. {
4390.     if (req == do_init) {
4391.         return optn_ok;
4392.     }
4393.     if (req == do_set) {
4394.         /* WINCAP tile_width:nn */
4395.         op = string_for_opt(opts, negated);
4396.         if ((negated && op == empty_optstr)
4397.             || (!negated && op != empty_optstr)) {
4398.             iflags.wc_tile_width = negated ? 0 : atoi(op);
4399.         } else if (negated) {
4400.             bad_negation(allopt[optidx].name, TRUE);
4401.             return optn_err;
4402.         }
4403.         return optn_ok;
4404.     }
4405.     if (req == get_val || req == get_cnf_val) {
4406.         if (iflags.wc_tile_width)
4407.             Sprintf(opts, "%d", iflags.wc_tile_width);
4408.         else if (req == get_cnf_val)
4409.             opts[0] = '\0';
4410.         else
4411.             Strcpy(opts, defopt);
4412.         return optn_ok;
4413.     }
4414.     return optn_ok;
4415. }
4416. 
4417. staticfn int
4418. optfn_traps(
4419.     int optidx UNUSED, int req, boolean negated UNUSED,
4420.     char *opts, char *op UNUSED)
4421. {
4422.     if (req == do_init) {
4423.         return optn_ok;
4424.     }
4425.     if (req == do_set) {
4426.         return optn_ok;
4427.     }
4428.     if (req == get_val) {
4429.         Sprintf(opts, "%s", to_be_done);
4430.         return optn_ok;
4431.     }
4432.     if (req == get_cnf_val) {
4433.         opts[0] = '\0';
4434.         return optn_ok;
4435.     }
4436.     return optn_ok;
4437. }
4438. 
4439. staticfn int
4440. optfn_vary_msgcount(
4441.     int optidx, int req, boolean negated,
4442.     char *opts, char *op)
4443. {
4444.     if (req == do_init) {
4445.         return optn_ok;
4446.     }
4447.     if (req == do_set) {
4448.         /* WINCAP vary_msgcount:nn */
4449.         op = string_for_opt(opts, negated);
4450.         if ((negated && op == empty_optstr)
4451.             || (!negated && op != empty_optstr)) {
4452.             iflags.wc_vary_msgcount = negated ? 0 : atoi(op);
4453.         } else if (negated) {
4454.             bad_negation(allopt[optidx].name, TRUE);
4455.             return optn_err;
4456.         }
4457.         return optn_ok;
4458.     }
4459.     if (req == get_val || req == get_cnf_val) {
4460.         if (iflags.wc_vary_msgcount)
4461.             Sprintf(opts, "%d", iflags.wc_vary_msgcount);
4462.         else if (req == get_cnf_val)
4463.             opts[0] = '\0';
4464.         else
4465.             Strcpy(opts, defopt);
4466.         return optn_ok;
4467.     }
4468.     return optn_ok;
4469. }
4470. 
4471. staticfn int
4472. optfn_versinfo(
4473.     int optidx, int req, boolean negated,
4474.     char *opts, char *op)
4475. {
4476.     const char *optname = allopt[optidx].name;
4477.     unsigned vi = flags.versinfo;
4478. 
4479.     if (req == do_init) {
4480.         return optn_ok;
4481.     }
4482.     if (req == do_set) {
4483.         /* versinfo: what to include when 'showvers' displays version
4484.            on status lines; bitmask with up to three bits:
4485.            (1) x.y.z number, (2) program name, (4) git branch if available.
4486.            If branch is requested but unavailable, status_version will
4487.            treat 4 as 1.
4488.          */
4489.         boolean have_branch = (nomakedefs.git_branch
4490.                                && *nomakedefs.git_branch);
4491.         int val, dflt = have_branch ? VI_BRANCH : VI_NUMBER;
4492. 
4493.         if (negated) {
4494.             bad_negation(allopt[optidx].name, TRUE);
4495.             return optn_silenterr;
4496.         }
4497.         op = string_for_opt(opts, FALSE);
4498.         if (op == empty_optstr) {
4499.             config_error_add("'%s' requires a value; defaulting to %d",
4500.                              optname, dflt);
4501.             return optn_silenterr;
4502.         }
4503.         val = atoi(op);
4504.         if (!val || (val & ~7) != 0) {
4505.             config_error_add("'%s' must be one of 1, 2, 4, or"
4506.                              " the sum of two or all three of those",
4507.                              optname);
4508.             return optn_silenterr;
4509.         }
4510.         flags.versinfo = (unsigned) val;
4511.     } else if (req == do_handler) {
4512.         /* return handler_versinfo(); */
4513.         (void) handler_versinfo();
4514.         pline("'%s' %s %u.", optname,
4515.               (flags.versinfo == vi) ? "not changed, still" : "changed to",
4516.               flags.versinfo);
4517.     } else if (req == get_val) {
4518.         char vbuf[QBUFSZ];
4519.         boolean g = (vi & VI_NAME) != 0,
4520.                 b = (vi & VI_BRANCH) != 0,
4521.                 n = (vi & VI_NUMBER) != 0;
4522. 
4523.         Sprintf(opts, "%u: %s%s%s%s%s (%.99s)", flags.versinfo,
4524.                 g ? "name" : "", (b && g) ? "+" : "", b ? "branch" : "",
4525.                 (n && (b || g)) ? "+" : "", n ? "number" : "",
4526.                 status_version(vbuf, sizeof vbuf, FALSE));
4527.     } else if (req == get_cnf_val) {
4528.         Sprintf(opts, "%u", flags.versinfo);
4529.     }
4530.     if (flags.versinfo != vi && !go.opt_initial)
4531.         go.opt_need_redraw = TRUE; /* context.botlx = TRUE ought to suffice
4532.                                     * but doesn't for X11 fancy status */
4533.     return optn_ok;
4534. }
4535. 
4536. #ifdef VIDEOSHADES
4537. staticfn int
4538. optfn_videocolors(
4539.     int optidx, int req, boolean negated UNUSED,
4540.     char *opts, char *op UNUSED)
4541. {
4542.     if (req == do_init) {
4543.         return optn_ok;
4544.     }
4545.     if (req == do_set) {
4546.         /* videocolors:string */
4547. 
4548.         if ((opts = string_for_env_opt(allopt[optidx].name, opts, FALSE))
4549.             == empty_optstr) {
4550.             return optn_err;
4551.         }
4552.         if (!assign_videocolors(opts)) {
4553.             config_error_add("Unknown error handling '%s'",
4554.                              allopt[optidx].name);
4555.             return optn_err;
4556.         }
4557.         return optn_ok;
4558.     }
4559.     if (req == get_val || req == get_cnf_val) {
4560.         Sprintf(opts, "%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d",
4561.                 ttycolors[CLR_RED], ttycolors[CLR_GREEN],
4562.                 ttycolors[CLR_BROWN], ttycolors[CLR_BLUE],
4563.                 ttycolors[CLR_MAGENTA], ttycolors[CLR_CYAN],
4564.                 ttycolors[CLR_ORANGE], ttycolors[CLR_BRIGHT_GREEN],
4565.                 ttycolors[CLR_YELLOW], ttycolors[CLR_BRIGHT_BLUE],
4566.                 ttycolors[CLR_BRIGHT_MAGENTA], ttycolors[CLR_BRIGHT_CYAN]);
4567.         return optn_ok;
4568.     }
4569.     return optn_ok;
4570. }
4571. 
4572. staticfn int
4573. optfn_videoshades(
4574.     int optidx, int req, boolean negated UNUSED,
4575.     char *opts, char *op UNUSED)
4576. {
4577.     if (req == do_init) {
4578.         return optn_ok;
4579.     }
4580.     if (req == do_set) {
4581.         /* videoshades:string */
4582. 
4583.         if ((opts = string_for_env_opt(allopt[optidx].name, opts, FALSE))
4584.             == empty_optstr) {
4585.             return optn_err;
4586.         }
4587.         if (!assign_videoshades(opts)) {
4588.             config_error_add("Unknown error handling '%s'",
4589.                              allopt[optidx].name);
4590.             return optn_err;
4591.         }
4592.         return optn_ok;
4593.     }
4594.     if (req == get_val || req == get_cnf_val) {
4595.         Sprintf(opts, "%s-%s-%s", shade[0], shade[1], shade[2]);
4596.         return optn_ok;
4597.     }
4598.     return optn_ok;
4599. }
4600. #endif /* VIDEOSHADES */
4601. 
4602. #ifdef MSDOS
4603. staticfn int
4604. optfn_video_width(
4605.     int optidx UNUSED, int req, boolean negated,
4606.     char *opts, char *op)
4607. {
4608.     if (req == do_init) {
4609.         return optn_ok;
4610.     }
4611.     if (req == do_set) {
4612.         if ((op = string_for_opt(opts, negated)) != empty_optstr)
4613.             iflags.wc_video_width = strtol(op, NULL, 10);
4614.         else
4615.             return optn_err;
4616.         return optn_ok;
4617.     }
4618.     if (req == get_val || req == get_cnf_val) {
4619.         opts[0] = '\0';
4620.     }
4621.     return optn_ok;
4622. }
4623. 
4624. staticfn int
4625. optfn_video_height(
4626.     int optidx UNUSED, int req, boolean negated,
4627.     char *opts, char *op)
4628. {
4629.     if (req == do_init) {
4630.         return optn_ok;
4631.     }
4632.     if (req == do_set) {
4633.         if ((op = string_for_opt(opts, negated)) != empty_optstr)
4634.             iflags.wc_video_height = strtol(op, NULL, 10);
4635.         else
4636.             return optn_err;
4637.         return optn_ok;
4638.     }
4639.     if (req == get_val || req == get_cnf_val) {
4640.         opts[0] = '\0';
4641.     }
4642.     return optn_ok;
4643. }
4644. 
4645. #ifdef NO_TERMS
4646. staticfn int
4647. optfn_video(
4648.     int optidx, int req, boolean negated UNUSED,
4649.     char *opts, char *op UNUSED)
4650. {
4651.     if (req == do_init) {
4652.         return optn_ok;
4653.     }
4654.     if (req == do_set) {
4655.         /* video:string */
4656.         if ((opts = string_for_env_opt(allopt[optidx].name, opts, FALSE))
4657.             == empty_optstr) {
4658.             return optn_err;
4659.         }
4660.         if (!assign_video(opts)) {
4661.             config_error_add("Unknown error handling '%s'",
4662.                              allopt[optidx].name);
4663.             return optn_err;
4664.         }
4665.         return optn_ok;
4666.     }
4667.     if (req == get_val) {
4668.         Sprintf(opts, "%s", to_be_done);
4669.         return optn_ok;
4670.     }
4671.     if (req == get_cnf_val) {
4672.         opts[0] = '\0';
4673.         return optn_ok;
4674.     }
4675.     return optn_ok;
4676. }
4677. 
4678. #endif /* NO_TERMS */
4679. #endif /* MSDOS */
4680. 
4681. staticfn int
4682. optfn_warnings(
4683.     int optidx, int req, boolean negated UNUSED,
4684.     char *opts, char *op UNUSED)
4685. {
4686.     int reslt;
4687. 
4688.     if (req == do_init) {
4689.         return optn_ok;
4690.     }
4691.     if (req == do_set) {
4692.         reslt = warning_opts(opts, allopt[optidx].name);
4693.         return reslt ? optn_ok : optn_err;
4694.     }
4695.     if (req == get_val || req == get_cnf_val) {
4696.         opts[0] = '\0';
4697.         return optn_ok;
4698.     }
4699.     return optn_ok;
4700. }
4701. 
4702. staticfn int
4703. optfn_whatis_coord(
4704.     int optidx, int req, boolean negated,
4705.     char *opts, char *op)
4706. {
4707.     if (req == do_init) {
4708.         return optn_ok;
4709.     }
4710.     if (req == do_set) {
4711.         if (negated) {
4712.             iflags.getpos_coords = GPCOORDS_NONE;
4713.             return optn_ok;
4714.         } else if ((op = string_for_env_opt(allopt[optidx].name, opts, FALSE))
4715.                    != empty_optstr) {
4716.             static char gpcoords[] = { GPCOORDS_NONE,    GPCOORDS_COMPASS,
4717.                                        GPCOORDS_COMFULL, GPCOORDS_MAP,
4718.                                        GPCOORDS_SCREEN,  '\0' };
4719.             char c = lowc(*op);
4720. 
4721.             if (c && strchr(gpcoords, c))
4722.                 iflags.getpos_coords = c;
4723.             else {
4724.                 config_error_add("Unknown %s parameter '%s'",
4725.                                  allopt[optidx].name, op);
4726.                 return optn_err;
4727.             }
4728.         } else
4729.             return optn_err;
4730.         return optn_ok;
4731.     }
4732.     if (req == get_val || req == get_cnf_val) {
4733.         Sprintf(opts, "%s",
4734.                 (iflags.getpos_coords == GPCOORDS_MAP) ? "map"
4735.                 : (iflags.getpos_coords == GPCOORDS_COMPASS) ? "compass"
4736.                 : (iflags.getpos_coords == GPCOORDS_COMFULL) ? "full compass"
4737.                 : (iflags.getpos_coords == GPCOORDS_SCREEN) ? "screen"
4738.                 : "none");
4739.         return optn_ok;
4740.     }
4741.     if (req == do_handler) {
4742.         return handler_whatis_coord();
4743.     }
4744.     return optn_ok;
4745. }
4746. 
4747. staticfn int
4748. optfn_whatis_filter(
4749.     int optidx, int req, boolean negated,
4750.     char *opts, char *op)
4751. {
4752.     if (req == do_init) {
4753.         return optn_ok;
4754.     }
4755.     if (req == do_set) {
4756.         if (negated) {
4757.             iflags.getloc_filter = GFILTER_NONE;
4758.             return optn_ok;
4759.         } else if ((op = string_for_env_opt(allopt[optidx].name, opts, FALSE))
4760.                    != empty_optstr) {
4761.             char c = lowc(*op);
4762. 
4763.             switch (c) {
4764.             case 'n':
4765.                 iflags.getloc_filter = GFILTER_NONE;
4766.                 break;
4767.             case 'v':
4768.                 iflags.getloc_filter = GFILTER_VIEW;
4769.                 break;
4770.             case 'a':
4771.                 iflags.getloc_filter = GFILTER_AREA;
4772.                 break;
4773.             default: {
4774.                 config_error_add("Unknown %s parameter '%s'",
4775.                                  allopt[optidx].name, op);
4776.                 return optn_err;
4777.             }
4778.             }
4779.         } else
4780.             return optn_err;
4781.         return optn_ok;
4782.     }
4783.     if (req == get_val || req == get_cnf_val) {
4784.         Sprintf(opts, "%s",
4785.                 (iflags.getloc_filter == GFILTER_VIEW) ? "view"
4786.                 : (iflags.getloc_filter == GFILTER_AREA) ? "area"
4787.                 : "none");
4788.         return optn_ok;
4789.     }
4790.     if (req == do_handler) {
4791.         return handler_whatis_filter();
4792.     }
4793.     return optn_ok;
4794. }
4795. 
4796. staticfn int
4797. optfn_windowborders(
4798.     int optidx, int req, boolean negated,
4799.     char *opts, char *op)
4800. {
4801.     int retval = optn_ok;
4802. 
4803.     if (req == do_init) {
4804.         return optn_ok;
4805.     }
4806.     if (req == do_set) {
4807.         op = string_for_opt(opts, negated);
4808.         if (negated && op != empty_optstr) {
4809.             bad_negation(allopt[optidx].name, TRUE);
4810.             retval = optn_err;
4811.         } else {
4812.             int itmp;
4813. 
4814.             if (negated)
4815.                 itmp = 0; /* Off */
4816.             else if (op == empty_optstr)
4817.                 itmp = 1; /* On */
4818.             else /* Value supplied; expect 0 (off), 1 (on), 2 (auto)
4819.                   * or 3 (on for most windows, off for perm_invent)
4820.                   * or 4 (auto for most windows, off for perm_invent) */
4821.                 itmp = atoi(op);
4822. 
4823.             if (itmp < 0 || itmp > 4) {
4824.                 config_error_add("Invalid %s (should be within 0 to 4): %s",
4825.                                  allopt[optidx].name, opts);
4826.                 retval = optn_silenterr;
4827.             } else {
4828.                 iflags.wc2_windowborders = itmp;
4829.             }
4830.         }
4831.         return retval;
4832.     }
4833.     if (req == get_val) {
4834.         Sprintf(opts, "%s",
4835.                 (iflags.wc2_windowborders == 0) ? "0=off"
4836.                 : (iflags.wc2_windowborders == 1) ? "1=on"
4837.                   : (iflags.wc2_windowborders == 2) ? "2=auto"
4838.                     : (iflags.wc2_windowborders == 3)
4839.                       ? "3=on, except off for perm_invent"
4840.                       : (iflags.wc2_windowborders == 4)
4841.                         ? "4=auto, except off for perm_invent"
4842.                         : defopt);
4843.         return optn_ok;
4844.     }
4845.     if (req == get_cnf_val) {
4846.         Sprintf(opts, "%i", iflags.wc2_windowborders);
4847.         return optn_ok;
4848.     }
4849.     if (req == do_handler) {
4850.         return handler_windowborders();
4851.     }
4852.     return optn_ok;
4853. }
4854. 
4855. #ifdef WINCHAIN
4856. staticfn int
4857. optfn_windowchain(
4858.     int optidx, int req,
4859.     boolean negated UNUSED,
4860.     char *opts, char *op)
4861. {
4862.     if (req == do_init) {
4863.         return optn_ok;
4864.     }
4865.     if (req == do_set) {
4866.         if ((op = string_for_env_opt(allopt[optidx].name, opts, FALSE))
4867.             != empty_optstr) {
4868.             char buf[WINTYPELEN];
4869. 
4870.             nmcpy(buf, op, WINTYPELEN);
4871.             addto_windowchain(buf);
4872.         } else
4873.             return optn_err;
4874.         return optn_ok;
4875.     }
4876.     if (req == get_val || req == get_cnf_val) {
4877.         opts[0] = '\0';
4878.         return optn_ok;
4879.     }
4880.     return optn_ok;
4881. }
4882. #endif
4883. 
4884. /* Win GUI and curses */
4885. static const char *const wcnames[WC_COUNT] = {
4886.     "menu", "message", "status", "text"
4887. };
4888. static const char *const wcshortnames[WC_COUNT] = {
4889.     "mnu", "msg", "sts", "txt"
4890. };
4891. int wcolors_opt[WC_COUNT];
4892. 
4893. staticfn int
4894. optfn_windowcolors(
4895.     int optidx, int req,
4896.     boolean negated UNUSED,
4897.     char *opts, char *op)
4898. {
4899.     int wccount;
4900. 
4901.     if (req == do_init) {
4902.         for (wccount = 0; wccount < WC_COUNT; ++wccount) {
4903.             wcolors_opt[wccount] = 0;
4904.         }
4905.         return optn_ok;
4906.     }
4907.     if (req == do_set) {
4908.         /* WINCAP
4909.          * setting window colors
4910.          * syntax: windowcolors=menu foregrnd/backgrnd text foregrnd/backgrnd
4911.          */
4912.         if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
4913.             if (!wc_set_window_colors(op)) {
4914.                 config_error_add("Could not set %s '%s'", allopt[optidx].name,
4915.                                  op);
4916.                 return optn_err;
4917.             }
4918.         }
4919.         return optn_ok;
4920.     }
4921.     if (req == get_val || req == get_cnf_val) {
4922.         const char *fg, *bg;
4923. 
4924.         /* TODO: wide 'get_val' may need to be wrapped in the menu display */
4925.         opts[0] = '\0';
4926.         for (wccount = 0; wccount < WC_COUNT; ++wccount) {
4927.             fg = iflags.wcolors[wccount].fg;
4928.             bg = iflags.wcolors[wccount].bg;
4929.             if (fg && (!*fg || !strcmp(fg, defbrief)))
4930.                 fg = 0;
4931.             if (bg && (!*bg || !strcmp(bg, defbrief)))
4932.                 bg = 0;
4933.             Sprintf(eos(opts), "%s%s %s/%s", !wccount ? "" : " ",
4934.                     (fg || bg) ? wcnames[wccount] : wcshortnames[wccount],
4935.                     fg ? fg : defbrief, bg ? bg : defbrief);
4936.         }
4937.         return optn_ok;
4938.     }
4939.     return optn_ok;
4940. }
4941. 
4942. staticfn int
4943. optfn_windowtype(
4944.     int optidx, int req,
4945.     boolean negated UNUSED,
4946.     char *opts, char *op)
4947. {
4948.     if (req == do_init) {
4949.         return optn_ok;
4950.     }
4951.     if (req == do_set) {
4952.         /*
4953.          * windowtype:  option to choose the interface for binaries built
4954.          * with support for more than one interface (tty + X11, for
4955.          * instance).
4956.          *
4957.          * Ideally, 'windowtype' should be processed first, because it
4958.          * causes the wc_ and wc2_ flags to be set up.
4959.          * For user, making it be first in a config file is trivial, use
4960.          * OPTIONS=windowtype:Foo
4961.          * as the first non-comment line of the file.
4962.          * Making it first in NETHACKOPTIONS requires it to be at the
4963.          * _end_ because comma-separated option strings are processed from
4964.          * right to left.
4965.          */
4966.         if (!iflags.window_inited) {
4967.             if (iflags.windowtype_locked)
4968.                 return optn_ok;
4969. 
4970.             if ((op = string_for_env_opt(allopt[optidx].name, opts, FALSE))
4971.                 != empty_optstr) {
4972.                 nmcpy(gc.chosen_windowtype, op, WINTYPELEN);
4973.                 if (!iflags.windowtype_deferred) {
4974.                     choose_windows(gc.chosen_windowtype);
4975.                 }
4976.             } else {
4977.                 return optn_err;
4978.             }
4979.         }
4980.         return optn_ok;
4981.     }
4982.     if (req == get_val || req == get_cnf_val) {
4983.         Sprintf(opts, "%s", windowprocs.name);
4984.         return optn_ok;
4985.     }
4986.     return optn_ok;
4987. }
4988. 
4989. /*
4990.  *    Prefix-handling functions
4991.  */
4992. 
4993. staticfn int
4994. pfxfn_cond_(
4995.     int optidx UNUSED,
4996.     int req,
4997.     boolean negated,
4998.     char *opts,
4999.     char *op UNUSED)
5000. {
5001.     if (req == do_init) {
5002.         condopt(0, (boolean *) 0, 0); /* make the choices match defaults */
5003.         return optn_ok;
5004.     }
5005.     if (req == do_set) {
5006.         int reslt = parse_cond_option(negated, opts);
5007. 
5008.         switch (reslt) {
5009.         case 0:
5010.             opt_set_in_config[pfx_cond_] = TRUE;
5011.             break;
5012.         case 3:
5013.             config_error_add("Ambiguous condition option %s", opts);
5014.             break;
5015.         case 1:
5016.         case 2:
5017.         default:
5018.             config_error_add("Unknown condition option %s (%d)", opts, reslt);
5019.             break;
5020.         }
5021.         if (reslt != 0)
5022.             return optn_err;
5023.         /* [FIXME?  redraw seems like overkill; botl update should suffice] */
5024.         go.opt_need_redraw = TRUE;
5025.         return optn_ok;
5026.     }
5027.     if (req == get_val || req == get_cnf_val) {
5028.         opts[0] = '\0';
5029.         return optn_ok;
5030.     }
5031.     if (req == do_handler) { /* not used */
5032.         (void) cond_menu();    /* in botl.c */
5033.         return optn_ok;
5034.     }
5035.     return optn_ok;
5036. }
5037. 
5038. staticfn int
5039. pfxfn_font(int optidx, int req, boolean negated, char *opts, char *op)
5040. {
5041.     int opttype = -1;
5042. 
5043.     if (req == do_init) {
5044.         return optn_ok;
5045.     }
5046. 
5047.     if (req == do_set) {
5048.         /* WINCAP setting font options  */
5049.         if (optidx == opt_font_map)
5050.             opttype = MAP_OPTION;
5051.         else if (optidx == opt_font_message)
5052.             opttype = MESSAGE_OPTION;
5053.         else if (optidx == opt_font_text)
5054.             opttype = TEXT_OPTION;
5055.         else if (optidx == opt_font_menu)
5056.             opttype = MENU_OPTION;
5057.         else if (optidx == opt_font_status)
5058.             opttype = STATUS_OPTION;
5059.         else if (optidx == opt_font_size_map
5060.                 || optidx == opt_font_size_message
5061.                 || optidx == opt_font_size_text
5062.                 || optidx == opt_font_size_menu
5063.                 || optidx == opt_font_size_status) {
5064.             if (optidx == opt_font_size_map)
5065.                 opttype = MAP_OPTION;
5066.             else if (optidx == opt_font_size_message)
5067.                 opttype = MESSAGE_OPTION;
5068.             else if (optidx == opt_font_size_text)
5069.                 opttype = TEXT_OPTION;
5070.             else if (optidx == opt_font_size_menu)
5071.                 opttype = MENU_OPTION;
5072.             else if (optidx == opt_font_size_status)
5073.                 opttype = STATUS_OPTION;
5074.             else {
5075.                 config_error_add("Unknown %s parameter '%s'",
5076.                              allopt[optidx].name, opts);
5077.                 return optn_err;
5078.             }
5079.             if (duplicate)
5080.                 complain_about_duplicate(optidx);
5081.             if (opttype > 0 && !negated
5082.                 && (op = string_for_opt(opts, FALSE)) != empty_optstr) {
5083.                 switch (opttype) {
5084.                 case MAP_OPTION:
5085.                     iflags.wc_fontsiz_map = atoi(op);
5086.                     break;
5087.                 case MESSAGE_OPTION:
5088.                     iflags.wc_fontsiz_message = atoi(op);
5089.                     break;
5090.                 case TEXT_OPTION:
5091.                     iflags.wc_fontsiz_text = atoi(op);
5092.                     break;
5093.                 case MENU_OPTION:
5094.                     iflags.wc_fontsiz_menu = atoi(op);
5095.                     break;
5096.                 case STATUS_OPTION:
5097.                     iflags.wc_fontsiz_status = atoi(op);
5098.                     break;
5099.                 }
5100.             }
5101.             return optn_ok;
5102.         } else {
5103.             config_error_add("Unknown %s parameter '%s'",
5104.                              "font", opts);
5105.             return FALSE;
5106.         }
5107.         if (opttype > 0
5108.             && (op = string_for_opt(opts, FALSE)) != empty_optstr) {
5109.             wc_set_font_name(opttype, op);
5110. #ifdef MACOS9
5111.             set_font_name(opttype, op);
5112. #endif
5113.             return optn_ok;
5114.         } else if (negated) {
5115.             bad_negation(allopt[optidx].name, TRUE);
5116.             return optn_err;
5117.         }
5118.         return optn_ok;
5119.     }
5120.     if (req == get_val || req == get_cnf_val) {
5121.         if (optidx == opt_font_map) {
5122.             Sprintf(opts, "%s",
5123.                     iflags.wc_font_map ? iflags.wc_font_map : defopt);
5124.         } else if (optidx == opt_font_message) {
5125.             Sprintf(opts, "%s",
5126.                 iflags.wc_font_message ? iflags.wc_font_message : defopt);
5127.         } else if (optidx == opt_font_status) {
5128.             Sprintf(opts, "%s",
5129.                 iflags.wc_font_status ? iflags.wc_font_status : defopt);
5130.         } else if (optidx == opt_font_menu) {
5131.             Sprintf(opts, "%s",
5132.                 iflags.wc_font_menu ? iflags.wc_font_menu : defopt);
5133.         } else if (optidx == opt_font_text) {
5134.             Sprintf(opts, "%s",
5135.                 iflags.wc_font_text ? iflags.wc_font_text : defopt);
5136.         } else if (optidx == opt_font_size_map) {
5137.             if (iflags.wc_fontsiz_map)
5138.                 Sprintf(opts, "%d", iflags.wc_fontsiz_map);
5139.             else
5140.                 Strcpy(opts, defopt);
5141.         } else if (optidx == opt_font_size_message) {
5142.             if (iflags.wc_fontsiz_message)
5143.                 Sprintf(opts, "%d", iflags.wc_fontsiz_message);
5144.             else
5145.                 Strcpy(opts, defopt);
5146.         } else if (optidx == opt_font_size_status) {
5147.             if (iflags.wc_fontsiz_status)
5148.                 Sprintf(opts, "%d", iflags.wc_fontsiz_status);
5149.             else
5150.                 Strcpy(opts, defopt);
5151.         } else if (optidx == opt_font_size_menu) {
5152.             if (iflags.wc_fontsiz_menu)
5153.                 Sprintf(opts, "%d", iflags.wc_fontsiz_menu);
5154.             else
5155.                 Strcpy(opts, defopt);
5156.         } else if (optidx == opt_font_size_text) {
5157.             if (iflags.wc_fontsiz_text)
5158.                 Sprintf(opts, "%d", iflags.wc_fontsiz_text);
5159.             else
5160.                 Strcpy(opts, defopt);
5161.         }
5162.         return optn_ok;
5163.     }
5164.     return optn_ok;
5165. }
5166. 
5167. #if defined(MICRO) && !defined(AMIGA)
5168. int
5169. pfxfn_IBM_(int optidx UNUSED, int req, boolean negated UNUSED,
5170.            char *opts, char *op UNUSED)
5171. {
5172.     if (req == do_init) {
5173.         return optn_ok;
5174.     }
5175.     if (req == do_set) {
5176.         return optn_ok;
5177.     }
5178.     if (req == get_val || req == get_cnf_val) {
5179.         opts[0] = '\0';
5180.         return optn_ok;
5181.     }
5182.     return optn_ok;
5183. }
5184. #endif
5185. 
5186. /*
5187.  *    General boolean option handler
5188.  *    (Use optidx to reference the specific option)
5189.  */
5190. 
5191. int
5192. optfn_boolean(
5193.     int optidx, int req, boolean negated,
5194.     char *opts, char *op)
5195. {
5196.     if (req == do_init) {
5197.         return optn_ok;
5198.     }
5199.     if (req == do_set) {
5200.         boolean nosexchange = FALSE;
5201.         int ln = 0;
5202. 
5203.         if (!allopt[optidx].addr)
5204.             return optn_ok; /* silent retreat */
5205. 
5206.         /* option that must come from config file? */
5207.         if (!go.opt_initial && (allopt[optidx].setwhere == set_in_config))
5208.             return optn_err;
5209. 
5210.         /* options that must NOT come from config file */
5211.         if (go.opt_initial && allopt[optidx].setwhere == set_wiznofuz)
5212.             return optn_err;
5213. 
5214.         op = string_for_opt(opts, TRUE);
5215.         if (op != empty_optstr) {
5216.             if (negated) {
5217.                 config_error_add(
5218.                            "Negated boolean '%s' should not have a parameter",
5219.                                  allopt[optidx].name);
5220.                 return optn_silenterr;
5221.             }
5222.             /* length is greater than 0 or we wouldn't have gotten here */
5223.             ln = (int) strlen(op);
5224.             if (!strncmpi(op, "true", ln)
5225.                 || !strncmpi(op, "yes", ln)
5226.                 || !strcmpi(op, "on")
5227.                 || (digit(*op) && atoi(op) == 1)) {
5228.                 negated = FALSE;
5229.             } else if (!strncmpi(op, "false", ln)
5230.                        || !strncmpi(op, "no", ln)
5231.                        || !strcmpi(op, "off")
5232.                        || (digit(*op) && atoi(op) == 0)) {
5233.                 negated = TRUE;
5234.             } else if (!allopt[optidx].valok) {
5235.                 config_error_add("'%s' is not valid for a boolean", opts);
5236.                 return optn_silenterr;
5237.             }
5238.         }
5239.         if (iflags.debug_fuzzer && !go.opt_initial) {
5240.             /* don't randomly toggle this/these */
5241.             if ((optidx == opt_silent)
5242.                 || (optidx == opt_perm_invent))
5243.                 return optn_ok;
5244.         }
5245.         /* Before the change */
5246.         switch (optidx) {
5247.         case opt_female:
5248.             if (!strncmpi(opts, "female", max(ln, 3))) {
5249.                 if (!go.opt_initial && flags.female == negated) {
5250.                     nosexchange = TRUE;
5251.                 } else {
5252.                     flags.initgend = flags.female = !negated;
5253.                     return optn_ok;
5254.                 }
5255.             }
5256.             if (!strncmpi(opts, "male", max(ln, 3))) {
5257.                 if (!go.opt_initial && flags.female != negated) {
5258.                     nosexchange = TRUE;
5259.                 } else {
5260.                     flags.initgend = flags.female = negated;
5261.                     return optn_ok;
5262.                 }
5263.             }
5264.             break;
5265.         case opt_perm_invent:
5266.             if (!negated && !go.opt_initial && !can_set_perm_invent())
5267.                 return optn_silenterr;
5268.             break;
5269.         default:
5270.             break;
5271.         }
5272.         /* this dates from when 'O' prompted for a line of options text
5273.            rather than use a menu to control access to which options can
5274.            be modified during play; it was possible to attempt to use
5275.            'O' to specify female or negate male when playing as male or
5276.            to specify male or negate female when playing as female;
5277.            options processing rejects that for !opt_initial; not possible
5278.            now but kept in case someone brings the old 'O' behavior back */
5279.         if (nosexchange) {
5280.             /* can't arbitrarily change sex after game has started;
5281.                magic (amulet or polymorph) is required for that */
5282.             config_error_add("'%s' is not anatomically possible.", opts);
5283.             return optn_silenterr;
5284.         }
5285. 
5286.         *(allopt[optidx].addr) = !negated;    /* <==== SET IT HERE */
5287. 
5288.         /* After the change */
5289.         switch (optidx) {
5290.         case opt_pauper:
5291.             /* pauper implies nudist */
5292.             u.uroleplay.nudist = u.uroleplay.pauper;
5293.             break;
5294.         case opt_ascii_map:
5295.             iflags.wc_tiled_map = negated;
5296.             break;
5297.         case opt_tiled_map:
5298.             iflags.wc_ascii_map = negated;
5299.             break;
5300.         case opt_hilite_pet:
5301. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS)
5302.             if (WINDOWPORT(tty) || WINDOWPORT(curses)) {
5303.                 /* if we're enabling hilite_pet and petattr isn't set,
5304.                    set it to Inverse; if we're disabling, leave petattr
5305.                    alone so that re-enabling will get current value back
5306.                  */
5307.                 if (iflags.hilite_pet && !iflags.wc2_petattr)
5308.                     iflags.wc2_petattr = ATR_INVERSE;
5309.             }
5310. #endif
5311.             go.opt_need_redraw = TRUE;
5312.             break;
5313. #ifndef IDLECHECKPOINT
5314.         case opt_idlecheckpoint:
5315.             pline("There is no underlying support for 'idlecheckpoint'"
5316.                   " compiled in."); 
5317.             iflags.idlecheckpoint = FALSE;
5318.             give_opt_msg = FALSE;
5319.             break;
5320. #endif
5321.         default:
5322.             break;
5323.         }
5324. 
5325.         /* only do processing below if setting with doset() */
5326. 
5327.         if (go.opt_initial)
5328.             return optn_ok;
5329. 
5330.         switch (optidx) {
5331.         case opt_terrainstatus:
5332.             classify_terrain(); /* bring iflags.terrain_typ up to date */
5333.             FALLTHROUGH;
5334.             /*FALLTHRU*/
5335.         case opt_weaponstatus:
5336.         case opt_armorstatus:
5337.             if (!wc2_supported(allopt[optidx].name)) {
5338.                 /* not actually an error */
5339.                 config_error_add("'%s' is not supported.",
5340.                                  allopt[optidx].name);
5341.                 return optn_ok;
5342.             }
5343.             FALLTHROUGH;
5344.             /*FALLTHRU*/
5345.         case opt_showscore:
5346.         case opt_showvers:
5347.         case opt_showexp:
5348.         case opt_time:
5349.             if (VIA_WINDOWPORT())
5350.                 status_initialize(REASSESS_ONLY);
5351.             disp.botl = TRUE;
5352.             break;
5353.         case opt_fixinv:
5354.         case opt_price_quotes:
5355.         case opt_sortpack:
5356.         case opt_implicit_uncursed:
5357.         case opt_wizweight:
5358.             if (!flags.invlet_constant)
5359.                 reassign();
5360.             update_inventory();
5361.             break;
5362.         case opt_lit_corridor:
5363.         case opt_dark_room:
5364.             /*
5365.              * All corridor squares seen via night vision or
5366.              * candles & lamps change.  Update them by calling
5367.              * newsym() on them.  Don't do this if we are
5368.              * initializing the options --- the vision system
5369.              * isn't set up yet.
5370.              */
5371.             vision_recalc(2);         /* shut down vision */
5372.             gv.vision_full_recalc = 1; /* delayed recalc */
5373.             if (iflags.use_color)
5374.                 go.opt_need_redraw = TRUE; /* darkroom refresh */
5375.             break;
5376.         case opt_wizmgender:
5377.         case opt_showrace:
5378.         case opt_use_inverse:
5379.         case opt_hilite_pile:
5380.         case opt_perm_invent:
5381.         case opt_ascii_map:
5382.         case opt_tiled_map:
5383.             go.opt_need_redraw = TRUE;
5384.             go.opt_need_glyph_reset = TRUE;
5385.             break;
5386.         case opt_hitpointbar:
5387.             if (VIA_WINDOWPORT()) {
5388.                 /* [is reassessment really needed here?] */
5389.                 status_initialize(REASSESS_ONLY);
5390.                 go.opt_need_redraw = TRUE;
5391. #ifdef QT_GRAPHICS
5392.             } else if (WINDOWPORT(Qt)) {
5393.                 /* Qt doesn't support HILITE_STATUS or FLUSH_STATUS so fails
5394.                    VIA_WINDOWPORT(), but it does support WC2_HITPOINTBAR */
5395.                 disp.botlx = TRUE;
5396. #endif
5397.             }
5398.             break;
5399.         case opt_color:
5400. #ifdef TOS
5401.             if (iflags.BIOS) {
5402.                 if (colors_changed)
5403.                     restore_colors();
5404.                 else
5405.                     set_colors();
5406.             }
5407. #endif
5408.             go.opt_need_redraw = TRUE;
5409.             go.opt_need_glyph_reset = TRUE;
5410.             break;
5411.         case opt_customcolors:
5412.             go.opt_reset_customcolors = TRUE;
5413.             break;
5414.         case opt_customsymbols:
5415.             go.opt_reset_customsymbols = TRUE;
5416.             break;
5417.         case opt_menucolors:
5418.         case opt_guicolor:
5419.             update_inventory();
5420.             go.opt_need_promptstyle = TRUE;
5421.             break;
5422.         case opt_mention_decor:
5423.             iflags.prev_decor = STONE;
5424.             break;
5425.         case opt_rest_on_space:
5426.             update_rest_on_space();
5427.             break;
5428.         case opt_accessiblemsg:
5429.             a11y.msg_loc.x = a11y.msg_loc.y = 0;
5430.             break;
5431.         default:
5432.             break;
5433.         }
5434. 
5435.         /* boolean value has been toggled but some option changes can
5436.            still be pending at this point (mainly for opt_need_redraw);
5437.            give the toggled message now regardless */
5438.         if (give_opt_msg)
5439.             pline("'%s' option toggled %s.", allopt[optidx].name,
5440.                   !negated ? "on" : "off");
5441. 
5442.         return optn_ok;
5443.     }
5444.     if (req == get_val || req == get_cnf_val) {
5445.         opts[0] = '\0';
5446.         return optn_ok;
5447.     }
5448.     return optn_ok;
5449. }
5450. 
5451. staticfn int
5452. spcfn_misc_menu_cmd(int midx, int req, boolean negated, char *opts, char *op)
5453. {
5454.     if (req == do_init) {
5455.         return optn_ok;
5456.     }
5457.     if (req == do_set) {
5458.         if (negated) {
5459.             bad_negation(default_menu_cmd_info[midx].name, FALSE);
5460.             return optn_err;
5461.         } else if ((op = string_for_opt(opts, FALSE)) != empty_optstr) {
5462.             char c = txt2key(op);
5463. 
5464.             if (illegal_menu_cmd_key((uchar) c))
5465.                 return optn_err;
5466.             add_menu_cmd_alias(c, default_menu_cmd_info[midx].cmd);
5467.         }
5468.         return optn_ok;
5469.     }
5470.     if (req == get_val || req == get_cnf_val) {
5471.         opts[0] = '\0';
5472.         return optn_ok;
5473.     }
5474.     return optn_ok;
5475. }
5476. 
5477. 
5478. /*
5479.  **********************************
5480.  *
5481.  *   Special per-option handlers
5482.  *
5483.  **********************************
5484.  */
5485. 
5486. /* test whether 'perm_invent' can be toggled On */
5487. staticfn boolean
5488. can_set_perm_invent(void)
5489. {
5490.     /*
5491.      * Assumption: only called when iflags.perm_invent is False
5492.      * and is about to be changed to True.
5493.      */
5494.     uchar old_perminv_mode = iflags.perminv_mode;
5495. 
5496.     if (!(windowprocs.wincap & WC_PERM_INVENT)) {
5497. #ifdef TTY_GRAPHICS
5498. #ifdef TTY_PERM_INVENT
5499.         /* check tty, not necessarily the active window port;
5500.            windows early startup can still be set to safeprocs */
5501.         if (!check_tty_wincap(WC_PERM_INVENT))
5502. #endif
5503. #endif
5504.             return FALSE;
5505.     }
5506. 
5507.     if (iflags.perminv_mode == InvOptNone)
5508.         iflags.perminv_mode = InvOptOn;
5509. 
5510. #ifdef TTY_PERM_INVENT
5511.     if ((WINDOWPORT(tty)
5512.          ) && !go.opt_initial) {
5513.         perm_invent_toggled(FALSE);
5514.         /* perm_invent_toggled()
5515.            -> sync_perminvent()
5516.               -> tty_create_nhwindow(NHW_PERMINVENT)
5517.            gives feedback for failure (terminal too small) */
5518.         if (WIN_INVEN == WIN_ERR) {
5519.             iflags.perminv_mode = old_perminv_mode;
5520.             return FALSE;
5521.         }
5522.     }
5523. #else
5524.     nhUse(old_perminv_mode);
5525. #endif
5526.     return TRUE;
5527. }
5528. 
5529. 
5530. #ifdef TTY_PERM_INVENT
5531. void
5532. check_perm_invent_again(void)
5533. {
5534.     if (iflags.perm_invent_pending) {
5535.         iflags.perm_invent = FALSE;
5536.         if (can_set_perm_invent())
5537.            iflags.perm_invent = TRUE;
5538.         iflags.perm_invent_pending = FALSE;
5539.     }
5540. }
5541. #endif
5542. 
5543. staticfn int
5544. handler_menustyle(void)
5545. {
5546.     winid tmpwin;
5547.     anything any;
5548.     boolean chngd;
5549.     int i, n, old_menu_style = flags.menu_style;
5550.     char buf[BUFSZ], sep = iflags.menu_tab_sep ? '\t' : ' ';
5551.     menu_item *style_pick = (menu_item *) 0;
5552.     int clr = NO_COLOR;
5553. 
5554.     tmpwin = create_nhwindow(NHW_MENU);
5555.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5556.     any = cg.zeroany;
5557.     for (i = 0; i < SIZE(menutype); i++) {
5558.         Sprintf(buf, "%-12.12s%c%.60s", menutype[i][0], sep, menutype[i][1]);
5559.         any.a_int = i + 1;
5560.         add_menu(tmpwin, &nul_glyphinfo, &any, *buf, 0, ATR_NONE, clr, buf,
5561.                  (i == flags.menu_style) ? MENU_ITEMFLAGS_SELECTED
5562.                                          : MENU_ITEMFLAGS_NONE);
5563.         /* second line is prefixed by spaces that "c - " would use */
5564.         Sprintf(buf, "%4s%-12.12s%c%.60s", "", "", sep, menutype[i][2]);
5565.         add_menu_str(tmpwin, buf);
5566.     }
5567.     end_menu(tmpwin, "Select menustyle:");
5568.     n = select_menu(tmpwin, PICK_ONE, &style_pick);
5569.     if (n > 0) {
5570.         i = style_pick[0].item.a_int - 1;
5571.         /* if there are two picks, use the one that wasn't pre-selected */
5572.         if (n > 1 && i == old_menu_style)
5573.             i = style_pick[1].item.a_int - 1;
5574.         flags.menu_style = i;
5575.         free((genericptr_t) style_pick);
5576.     }
5577.     destroy_nhwindow(tmpwin);
5578.     chngd = (flags.menu_style != old_menu_style);
5579.     if (chngd || flags.verbose)
5580.         pline("'menustyle' %s \"%s\".", chngd ? "changed to" : "is still",
5581.               menutype[(int) flags.menu_style][0]);
5582.     return optn_ok;
5583. }
5584. 
5585. staticfn int
5586. handler_align_misc(int optidx)
5587. {
5588.     winid tmpwin;
5589.     anything any;
5590.     menu_item *window_pick = (menu_item *) 0;
5591.     char abuf[BUFSZ];
5592.     int clr = NO_COLOR;
5593. 
5594.     tmpwin = create_nhwindow(NHW_MENU);
5595.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5596.     any = cg.zeroany;
5597.     any.a_int = ALIGN_TOP;
5598.     add_menu(tmpwin, &nul_glyphinfo, &any, 't', 0, ATR_NONE, clr, "top",
5599.              MENU_ITEMFLAGS_NONE);
5600.     any.a_int = ALIGN_BOTTOM;
5601.     add_menu(tmpwin, &nul_glyphinfo, &any, 'b', 0, ATR_NONE, clr, "bottom",
5602.              MENU_ITEMFLAGS_NONE);
5603.     any.a_int = ALIGN_LEFT;
5604.     add_menu(tmpwin, &nul_glyphinfo, &any, 'l', 0, ATR_NONE, clr, "left",
5605.              MENU_ITEMFLAGS_NONE);
5606.     any.a_int = ALIGN_RIGHT;
5607.     add_menu(tmpwin, &nul_glyphinfo, &any, 'r', 0, ATR_NONE, clr, "right",
5608.              MENU_ITEMFLAGS_NONE);
5609.     Sprintf(abuf, "Select %s window placement relative to the map:",
5610.             (optidx == opt_align_message) ? "message" : "status");
5611.     end_menu(tmpwin, abuf);
5612.     if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) {
5613.         if (optidx == opt_align_message)
5614.             iflags.wc_align_message = window_pick->item.a_int;
5615.         else
5616.             iflags.wc_align_status = window_pick->item.a_int;
5617.         free((genericptr_t) window_pick);
5618.     }
5619.     destroy_nhwindow(tmpwin);
5620.     return optn_ok;
5621. }
5622. 
5623. staticfn int
5624. handler_autounlock(int optidx)
5625. {
5626.     winid tmpwin;
5627.     anything any;
5628.     boolean chngd;
5629.     unsigned oldflags = flags.autounlock;
5630.     const char *optname = allopt[optidx].name;
5631.     char buf[BUFSZ], sep = iflags.menu_tab_sep ? '\t' : ' ';
5632.     menu_item *window_pick = (menu_item *) 0;
5633.     int i, n, presel, res = optn_ok;
5634.     int clr = NO_COLOR;
5635. 
5636.     tmpwin = create_nhwindow(NHW_MENU);
5637.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5638.     any = cg.zeroany;
5639.     for (i = 0; i < SIZE(unlocktypes); ++i) {
5640.         Sprintf(buf, "%-10.10s%c%.40s",
5641.                 unlocktypes[i][0], sep, unlocktypes[i][1]);
5642.         presel = (flags.autounlock & (1 << i));
5643.         any.a_int = i + 1;
5644.         add_menu(tmpwin, &nul_glyphinfo, &any, *unlocktypes[i][0], 0,
5645.                  ATR_NONE, clr, buf,
5646.                  (presel ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE));
5647.     }
5648.     Sprintf(buf, "Select '%.20s' actions:", optname);
5649.     end_menu(tmpwin, buf);
5650.     n = select_menu(tmpwin, PICK_ANY, &window_pick);
5651.     if (n > 0) {
5652.         unsigned newflags = 0;
5653. 
5654.         for (i = 0; i < n; ++i)
5655.             newflags |= (1 << (window_pick[i].item.a_int - 1));
5656.         flags.autounlock = newflags;
5657.         free((genericptr_t) window_pick);
5658.     } else if (n == 0) { /* nothing was picked but menu wasn't cancelled */
5659.         /* something that was preselected got unselected, leaving nothing;
5660.            treat that as picking 'none' (even though 'none' is no longer
5661.            among the choices) */
5662.         flags.autounlock = 0;
5663.     }
5664.     destroy_nhwindow(tmpwin);
5665.     chngd = (flags.autounlock != oldflags);
5666.     if ((chngd || flags.verbose) && give_opt_msg) {
5667.         optfn_autounlock(optidx, get_val, FALSE, buf, (char *) NULL);
5668.         pline("'%s' %s '%s'.", optname,
5669.               chngd ? "changed to" : "is still", buf);
5670.     }
5671.     return res;
5672. }
5673. 
5674. staticfn int
5675. handler_disclose(void)
5676. {
5677.     winid tmpwin;
5678.     anything any;
5679.     int i, n;
5680.     char buf[BUFSZ];
5681.     /* order of disclose_names[] must correspond to
5682.        disclosure_options in decl.c */
5683.     static const char *const disclosure_names[] = {
5684.         "inventory", "attributes", "vanquished",
5685.         "genocides", "conduct",    "overview",
5686.     };
5687.     int disc_cat[NUM_DISCLOSURE_OPTIONS];
5688.     int pick_cnt, pick_idx, opt_idx;
5689.     char c;
5690.     menu_item *disclosure_pick = (menu_item *) 0;
5691.     int clr = NO_COLOR;
5692. 
5693.     tmpwin = create_nhwindow(NHW_MENU);
5694.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5695.     any = cg.zeroany;
5696.     for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
5697.         Sprintf(buf, "%-12s[%c%c]", disclosure_names[i],
5698.                 flags.end_disclose[i], disclosure_options[i]);
5699.         any.a_int = i + 1;
5700.         add_menu(tmpwin, &nul_glyphinfo, &any, disclosure_options[i],
5701.                  0, ATR_NONE, clr, buf, MENU_ITEMFLAGS_NONE);
5702.         disc_cat[i] = 0;
5703.     }
5704.     end_menu(tmpwin, "Change which disclosure options categories:");
5705.     pick_cnt = select_menu(tmpwin, PICK_ANY, &disclosure_pick);
5706.     if (pick_cnt > 0) {
5707.         for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
5708.             opt_idx = disclosure_pick[pick_idx].item.a_int - 1;
5709.             disc_cat[opt_idx] = 1;
5710.         }
5711.         free((genericptr_t) disclosure_pick);
5712.         disclosure_pick = (menu_item *) 0;
5713.     }
5714.     destroy_nhwindow(tmpwin);
5715. 
5716.     for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
5717.         if (disc_cat[i]) {
5718.             c = flags.end_disclose[i];
5719.             Sprintf(buf, "Disclosure options for %s:",
5720.                     disclosure_names[i]);
5721.             tmpwin = create_nhwindow(NHW_MENU);
5722.             start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5723.             any = cg.zeroany;
5724.             /* 'y','n',and '+' work as alternate selectors; '-' doesn't */
5725.             any.a_char = DISCLOSE_NO_WITHOUT_PROMPT;
5726.             add_menu(tmpwin, &nul_glyphinfo, &any, 0,
5727.                      any.a_char, ATR_NONE, clr,
5728.                      "Never disclose, without prompting",
5729.                      (c == any.a_char) ? MENU_ITEMFLAGS_SELECTED
5730.                                        : MENU_ITEMFLAGS_NONE);
5731.             any.a_char = DISCLOSE_YES_WITHOUT_PROMPT;
5732.             add_menu(tmpwin, &nul_glyphinfo, &any, 0,
5733.                      any.a_char, ATR_NONE, clr,
5734.                      "Always disclose, without prompting",
5735.                      (c == any.a_char) ? MENU_ITEMFLAGS_SELECTED
5736.                                        : MENU_ITEMFLAGS_NONE);
5737.             if (*disclosure_names[i] == 'v' || *disclosure_names[i] == 'g') {
5738.                 any.a_char = DISCLOSE_SPECIAL_WITHOUT_PROMPT; /* '#' */
5739.                 add_menu(tmpwin, &nul_glyphinfo, &any, 0,
5740.                          any.a_char, ATR_NONE, clr,
5741.                          "Always disclose, pick sort order from menu",
5742.                          (c == any.a_char) ? MENU_ITEMFLAGS_SELECTED
5743.                                            : MENU_ITEMFLAGS_NONE);
5744.             }
5745.             any.a_char = DISCLOSE_PROMPT_DEFAULT_NO;
5746.             add_menu(tmpwin, &nul_glyphinfo, &any, 0,
5747.                      any.a_char, ATR_NONE, clr,
5748.                      "Prompt, with default answer of \"No\"",
5749.                      (c == any.a_char) ? MENU_ITEMFLAGS_SELECTED
5750.                                        : MENU_ITEMFLAGS_NONE);
5751.             any.a_char = DISCLOSE_PROMPT_DEFAULT_YES;
5752.             add_menu(tmpwin, &nul_glyphinfo, &any, 0,
5753.                      any.a_char, ATR_NONE, clr,
5754.                      "Prompt, with default answer of \"Yes\"",
5755.                      (c == any.a_char) ? MENU_ITEMFLAGS_SELECTED
5756.                                        : MENU_ITEMFLAGS_NONE);
5757.             if (*disclosure_names[i] == 'v' || *disclosure_names[i] == 'g') {
5758.                 any.a_char = DISCLOSE_PROMPT_DEFAULT_SPECIAL; /* '?' */
5759.                 add_menu(tmpwin, &nul_glyphinfo, &any, 0,
5760.                          any.a_char, ATR_NONE, clr,
5761.                 "Prompt, with default answer of \"Ask\" to request sort menu",
5762.                          (c == any.a_char) ? MENU_ITEMFLAGS_SELECTED
5763.                                            : MENU_ITEMFLAGS_NONE);
5764.             }
5765.             end_menu(tmpwin, buf);
5766.             n = select_menu(tmpwin, PICK_ONE, &disclosure_pick);
5767.             if (n > 0) {
5768.                 flags.end_disclose[i] = disclosure_pick[0].item.a_char;
5769.                 if (n > 1 && flags.end_disclose[i] == c)
5770.                     flags.end_disclose[i] = disclosure_pick[1].item.a_char;
5771.                 free((genericptr_t) disclosure_pick);
5772.             }
5773.             destroy_nhwindow(tmpwin);
5774.         }
5775.     }
5776.     return optn_ok;
5777. }
5778. 
5779. staticfn int
5780. handler_menu_headings(void)
5781. {
5782.     boolean gotca = query_color_attr(&iflags.menu_headings,
5783.                                      "How to highlight menu headings:");
5784. 
5785.     if (gotca) {
5786.         /* header highlighting affects persistent inventory display */
5787.         if (iflags.perm_invent)
5788.             update_inventory();
5789.     }
5790.     adjust_menu_promptstyle(WIN_INVEN, &iflags.menu_headings);
5791.     return optn_ok;
5792. }
5793. 
5794. staticfn int
5795. handler_menu_objsyms(void)
5796. {
5797.     winid tmpwin;
5798.     anything any;
5799.     char buf[BUFSZ];
5800.     menu_item *picklist = (menu_item *) 0;
5801.     const char sep = iflags.menu_tab_sep ? '\t' : ' ';
5802.     int i, j, n, clr = NO_COLOR;
5803. 
5804.     tmpwin = create_nhwindow(NHW_MENU);
5805.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5806.     any = cg.zeroany;
5807.     for (i = 0; i < SIZE(objsymvals); ++i) {
5808.         Snprintf(buf, sizeof buf, "%-12.12s%c%.60s",
5809.                  objsymvals[i].nam, sep, objsymvals[i].descr);
5810.         any.a_int = i + 1;
5811.         j = objsymvals[i].num;
5812.         add_menu(tmpwin, &nul_glyphinfo, &any, '0' + i, *buf,
5813.                  ATR_NONE, clr, buf,
5814.                  (j == iflags.menuobjsyms) ? MENU_ITEMFLAGS_SELECTED
5815.                                            : MENU_ITEMFLAGS_NONE);
5816.     }
5817.     end_menu(tmpwin, "Set object symbols in menus to what?");
5818.     n = select_menu(tmpwin, PICK_ONE, &picklist);
5819.     if (n > 0) {
5820.         i = picklist[0].item.a_int - 1;
5821.         /* if there are two picks, use the one that wasn't pre-selected */
5822.         if (n > 1 && i == iflags.menuobjsyms)
5823.             i = picklist[1].item.a_int - 1;
5824.         set_menuobjsyms_flags(i);
5825.         free((genericptr_t) picklist);
5826.     }
5827.     destroy_nhwindow(tmpwin);
5828.     return optn_ok;
5829. }
5830. 
5831. staticfn int
5832. handler_msg_window(void)
5833. {
5834. #if PREV_MSGS /* tty or curses */
5835.     winid tmpwin;
5836.     anything any;
5837.     boolean is_tty = WINDOWPORT(tty), is_curses = WINDOWPORT(curses);
5838.     int clr = NO_COLOR;
5839. 
5840.     if (is_tty || is_curses) {
5841.         /* by Christian W. Cooper */
5842.         boolean chngd;
5843.         int i, n;
5844.         char buf[BUFSZ], c,
5845.              sep = iflags.menu_tab_sep ? '\t' : ' ',
5846.              old_prevmsg_window = iflags.prevmsg_window;
5847.         menu_item *window_pick = (menu_item *) 0;
5848. 
5849.         tmpwin = create_nhwindow(NHW_MENU);
5850.         start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5851.         any = cg.zeroany;
5852. 
5853.         for (i = 0; i < SIZE(menutype); i++) {
5854.             if (i < 2 && is_curses)
5855.                 continue;
5856.             Sprintf(buf, "%-12.12s%c%.60s", msgwind[i][0], sep,
5857.                     msgwind[i][1]);
5858.             any.a_char = c = *msgwind[i][0];
5859.             add_menu(tmpwin, &nul_glyphinfo, &any, *buf, 0,
5860.                      ATR_NONE, clr, buf,
5861.                      (c == iflags.prevmsg_window) ? MENU_ITEMFLAGS_SELECTED
5862.                                                   : MENU_ITEMFLAGS_NONE);
5863.             /* second line is prefixed by spaces that "c - " would use */
5864.             Sprintf(buf, "%4s%-12.12s%c%.60s", "", "", sep, msgwind[i][2]);
5865.             add_menu_str(tmpwin, buf);
5866.         }
5867.         end_menu(tmpwin, "Select message history display type:");
5868.         n = select_menu(tmpwin, PICK_ONE, &window_pick);
5869.         if (n > 0) {
5870.             c = window_pick[0].item.a_char;
5871.             /* if there are two picks, use the one that wasn't pre-selected */
5872.             if (n > 1 && c == old_prevmsg_window)
5873.                 c = window_pick[1].item.a_char;
5874.             iflags.prevmsg_window = c;
5875.             free((genericptr_t) window_pick);
5876.         }
5877.         destroy_nhwindow(tmpwin);
5878.         chngd = (iflags.prevmsg_window != old_prevmsg_window);
5879.         if (chngd || flags.verbose) {
5880.             (void) optfn_msg_window(opt_msg_window, get_val,
5881.                                     FALSE, buf, empty_optstr);
5882.             pline("'msg_window' %.20s \"%.20s\".",
5883.                   chngd ? "changed to" : "is still", buf);
5884.         }
5885.     } else
5886. #endif /* PREV_MSGS (for tty or curses) */
5887.         pline("'%s' option is not supported for '%s'.",
5888.               allopt[opt_msg_window].name, windowprocs.name);
5889.     return optn_ok;
5890. }
5891. 
5892. staticfn int
5893. handler_number_pad(void)
5894. {
5895.     winid tmpwin;
5896.     anything any;
5897.     int i;
5898.     static const char *const npchoices[] = {
5899.         " 0 (off)", " 1 (on)", " 2 (on, MSDOS compatible)",
5900.         " 3 (on, phone-style digit layout)",
5901.         " 4 (on, phone-style layout, MSDOS compatible)",
5902.         "-1 (off, 'z' to move upper-left, 'y' to zap wands)"
5903.     };
5904.     menu_item *mode_pick = (menu_item *) 0;
5905.     int clr = NO_COLOR;
5906. 
5907.     tmpwin = create_nhwindow(NHW_MENU);
5908.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5909.     any = cg.zeroany;
5910.     for (i = 0; i < SIZE(npchoices); i++) {
5911.         any.a_int = i + 1;
5912.         add_menu(tmpwin, &nul_glyphinfo, &any, 'a' + i, '0' + i,
5913.                  ATR_NONE, clr, npchoices[i], MENU_ITEMFLAGS_NONE);
5914.     }
5915.     end_menu(tmpwin, "Select number_pad mode:");
5916.     if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) {
5917.         switch (mode_pick->item.a_int - 1) {
5918.         case 0:
5919.             iflags.num_pad = FALSE;
5920.             iflags.num_pad_mode = 0;
5921.             break;
5922.         case 1:
5923.             iflags.num_pad = TRUE;
5924.             iflags.num_pad_mode = 0;
5925.             break;
5926.         case 2:
5927.             iflags.num_pad = TRUE;
5928.             iflags.num_pad_mode = 1;
5929.             break;
5930.         case 3:
5931.             iflags.num_pad = TRUE;
5932.             iflags.num_pad_mode = 2;
5933.             break;
5934.         case 4:
5935.             iflags.num_pad = TRUE;
5936.             iflags.num_pad_mode = 3;
5937.             break;
5938.         /* last menu choice: number_pad == -1 */
5939.         case 5:
5940.             iflags.num_pad = FALSE;
5941.             iflags.num_pad_mode = 1;
5942.             break;
5943.         }
5944.         reset_commands(FALSE);
5945.         number_pad(iflags.num_pad ? 1 : 0);
5946.         free((genericptr_t) mode_pick);
5947.     }
5948.     destroy_nhwindow(tmpwin);
5949.     return optn_ok;
5950. }
5951. 
5952. staticfn int
5953. handler_paranoid_confirmation(void)
5954. {
5955.     winid tmpwin;
5956.     anything any;
5957.     int i;
5958.     char mkey, mbuf[QBUFSZ], ebuf[BUFSZ], cbuf[QBUFSZ];
5959.     const char *explain, *cmdnm;
5960.     menu_item *paranoia_picks = (menu_item *) 0;
5961.     int clr = NO_COLOR;
5962. 
5963.     tmpwin = create_nhwindow(NHW_MENU);
5964.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5965.     any = cg.zeroany;
5966.     for (i = 0; paranoia[i].flagmask != 0; ++i) {
5967.         if (paranoia[i].flagmask == PARANOID_BONES && !wizard)
5968.             continue;
5969.         /* the 'swim' choice mentions the 'm' movement prefix in its
5970.            explanation; if that's been bound to something else or been
5971.            unbound altogether, substitute the replacement in the text */
5972.         explain = paranoia[i].explain;
5973.         if (strstri(explain, "'m'")
5974.             && (mkey = cmd_from_func(do_reqmenu)) != 'm') {
5975.             if (mkey) { /* key for 'm' prefix */
5976.                 Sprintf(mbuf, "'%.9s'", visctrl(mkey)); /* .5 is enough */
5977.             } else { /* extended command name for 'm' prefix */
5978.                 cmdnm = cmdname_from_func(do_reqmenu, cbuf, TRUE);
5979.                 if (!cmdnm)
5980.                     cmdnm = "reqmenu";
5981.                 Sprintf(mbuf, "'%s%.31s'", (*cmdnm != '#') ? "#" : "", cmdnm);
5982.             }
5983.             explain = strsubst(strcpy(ebuf, explain), "'m'", mbuf);
5984.         }
5985.         any.a_int = paranoia[i].flagmask;
5986.         add_menu(tmpwin, &nul_glyphinfo, &any, *paranoia[i].argname,
5987.                  0, ATR_NONE, clr, explain,
5988.                  (flags.paranoia_bits & paranoia[i].flagmask)
5989.                      ? MENU_ITEMFLAGS_SELECTED
5990.                      : MENU_ITEMFLAGS_NONE);
5991.     }
5992.     end_menu(tmpwin, "Actions requiring extra confirmation:");
5993.     i = select_menu(tmpwin, PICK_ANY, &paranoia_picks);
5994.     if (i >= 0) {
5995.         /* player didn't cancel; we reset all the paranoia options
5996.            here even if there were no items picked, since user
5997.            could have toggled off preselected ones to end up with 0 */
5998.         flags.paranoia_bits = 0;
5999.         if (i > 0) {
6000.             /* at least 1 item set, either preselected or newly picked */
6001.             while (--i >= 0)
6002.                 flags.paranoia_bits |= paranoia_picks[i].item.a_int;
6003.             free((genericptr_t) paranoia_picks);
6004.         }
6005.     }
6006.     destroy_nhwindow(tmpwin);
6007.     return optn_ok;
6008. }
6009. 
6010. staticfn int
6011. handler_perminv_mode(void)
6012. {
6013.     winid tmpwin;
6014.     anything any;
6015.     char let, buf[BUFSZ], sepbuf[10];
6016.     const char *pi0, *pi1;
6017.     menu_item *pi_pick = (menu_item *) 0;
6018.     boolean old_perm_invent = iflags.perm_invent;
6019.     int i, n, old_pi = (int) iflags.perminv_mode, new_pi = old_pi,
6020.         widest = !WINDOWPORT(tty) ? 8 : 11; /* "in-use__" or "full+grid__" */
6021. 
6022.     tmpwin = create_nhwindow(NHW_MENU);
6023.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6024.     any = cg.zeroany;
6025.     for (i = 0; i < SIZE(perminv_modes); ++i) {
6026.         if (!(pi0 = perminv_modes[i][0]))
6027.             continue;
6028. #ifdef TTY_PERM_INVENT
6029.         if (strstri(pi0, "+grid") != 0 && !WINDOWPORT(tty))
6030.             continue;
6031. #endif
6032.         pi1 = perminv_modes[i][1];
6033.         if (!iflags.menu_tab_sep) {
6034.             int numspaces = widest - (int) strlen(pi0);
6035. 
6036.             Sprintf(sepbuf, "%*s", max(numspaces, 1), " ");
6037.         } else {
6038.             Strcpy(sepbuf, "\t");
6039.         }
6040.         Sprintf(buf, "%s%s%s", pi0, sepbuf, perminv_modes[i][2]);
6041.         let = ((i & (int) InvSparse) != 0) ? highc(pi1[0]) : pi0[0];
6042.         any.a_int = i + 1;
6043.         add_menu(tmpwin, &nul_glyphinfo, &any, let, '0' + i,
6044.                  ATR_NONE, NO_COLOR,
6045.                  buf, (i == old_pi) ? MENU_ITEMFLAGS_SELECTED
6046.                                     : MENU_ITEMFLAGS_NONE);
6047.     }
6048.     end_menu(tmpwin, "Choose permanent inventory mode:");
6049.     n = select_menu(tmpwin, PICK_ONE, &pi_pick);
6050.     destroy_nhwindow(tmpwin);
6051.     if (n > 0) {
6052.         new_pi = pi_pick[0].item.a_int - 1;
6053.         if (n > 1 && new_pi == old_pi)
6054.             new_pi = pi_pick[1].item.a_int - 1;
6055.         free((genericptr_t) pi_pick);
6056.         iflags.perminv_mode = new_pi;
6057.     }
6058.     if (n >= 0) { /* not ESC */
6059.         buf[0] = '\0';
6060.         (void) optfn_perminv_mode(opt_perm_invent, get_val, FALSE, buf, NULL);
6061.         pline("'perminv_mode' %s '%s' (%s).",
6062.               (new_pi != old_pi) ? "changed to" : "is still",
6063.               perminv_modes[new_pi][0], buf);
6064.         if (new_pi != InvOptNone && !old_perm_invent)
6065.             iflags.perm_invent = can_set_perm_invent();
6066.         else if (new_pi == InvOptNone && old_perm_invent)
6067.             iflags.perm_invent = FALSE;
6068. 
6069.         if (new_pi != old_pi || iflags.perm_invent != old_perm_invent) {
6070. #ifdef TTY_PERM_INVENT
6071.             /* FIXME: TTY_PERM_INVENT will blank WIN_INVEN when changing
6072.                perminv_mode while perm_invent is already on; to remedy that,
6073.                turn it off and then back on when already on */
6074.             if (WINDOWPORT(tty) && iflags.perm_invent && old_perm_invent) {
6075.                 perm_invent_toggled(TRUE);      /*TEMP?*/
6076.                 perm_invent_toggled(FALSE);     /*TEMP?*/
6077.             }
6078. #endif
6079.             go.opt_need_redraw = TRUE;
6080.         }
6081.     }
6082.     return optn_ok;
6083. }
6084. 
6085. staticfn int
6086. handler_pickup_burden(void)
6087. {
6088.     winid tmpwin;
6089.     anything any;
6090.     int i;
6091.     const char *burden_name, *burden_letters = "ubsntl";
6092.     menu_item *burden_pick = (menu_item *) 0;
6093.     int clr = NO_COLOR;
6094. 
6095.     tmpwin = create_nhwindow(NHW_MENU);
6096.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6097.     any = cg.zeroany;
6098.     for (i = 0; i < SIZE(burdentype); i++) {
6099.         burden_name = burdentype[i];
6100.         any.a_int = i + 1;
6101.         add_menu(tmpwin, &nul_glyphinfo, &any, burden_letters[i],
6102.                  0, ATR_NONE, clr, burden_name, MENU_ITEMFLAGS_NONE);
6103.     }
6104.     end_menu(tmpwin, "Select encumbrance level:");
6105.     if (select_menu(tmpwin, PICK_ONE, &burden_pick) > 0) {
6106.         flags.pickup_burden = burden_pick->item.a_int - 1;
6107.         free((genericptr_t) burden_pick);
6108.     }
6109.     destroy_nhwindow(tmpwin);
6110.     return optn_ok;
6111. }
6112. 
6113. staticfn int
6114. handler_pickup_types(void)
6115. {
6116.     char buf[BUFSZ];
6117. 
6118.     /* parseoptions will prompt for the list of types */
6119.     (void) parseoptions(strcpy(buf, "pickup_types"), FALSE, FALSE);
6120.     return optn_ok;
6121. }
6122. 
6123. staticfn int
6124. handler_runmode(void)
6125. {
6126.     winid tmpwin;
6127.     anything any;
6128.     int i;
6129.     const char *mode_name;
6130.     menu_item *mode_pick = (menu_item *) 0;
6131.     int clr = NO_COLOR;
6132. 
6133.     tmpwin = create_nhwindow(NHW_MENU);
6134.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6135.     any = cg.zeroany;
6136.     for (i = 0; i < SIZE(runmodes); i++) {
6137.         mode_name = runmodes[i];
6138.         any.a_int = i + 1;
6139.         add_menu(tmpwin, &nul_glyphinfo, &any, *mode_name,
6140.                  0, ATR_NONE, clr, mode_name, MENU_ITEMFLAGS_NONE);
6141.     }
6142.     end_menu(tmpwin, "Select run/travel display mode:");
6143.     if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) {
6144.         flags.runmode = mode_pick->item.a_int - 1;
6145.         free((genericptr_t) mode_pick);
6146.     }
6147.     destroy_nhwindow(tmpwin);
6148.     return optn_ok;
6149. }
6150. 
6151. staticfn int
6152. handler_petattr(void)
6153. {
6154.     int tmp
6155.         = query_attr("Select pet highlight attribute", iflags.wc2_petattr);
6156. 
6157.     if (tmp != -1) {
6158.         iflags.wc2_petattr = tmp;
6159.         iflags.hilite_pet = (iflags.wc2_petattr != ATR_NONE);
6160.         if (!go.opt_initial)
6161.             go.opt_need_redraw = TRUE;
6162.     }
6163.     return optn_ok;
6164. }
6165. 
6166. staticfn int
6167. handler_sortloot(void)
6168. {
6169.     winid tmpwin;
6170.     anything any;
6171.     int i, n;
6172.     const char *sortl_name;
6173.     menu_item *sortl_pick = (menu_item *) 0;
6174.     int clr = NO_COLOR;
6175. 
6176.     tmpwin = create_nhwindow(NHW_MENU);
6177.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6178.     any = cg.zeroany;
6179.     for (i = 0; i < SIZE(sortltype); i++) {
6180.         sortl_name = sortltype[i];
6181.         any.a_char = *sortl_name;
6182.         add_menu(tmpwin, &nul_glyphinfo, &any, *sortl_name,
6183.                  0, ATR_NONE, clr,
6184.                  sortl_name, (flags.sortloot == *sortl_name)
6185.                                 ? MENU_ITEMFLAGS_SELECTED
6186.                                 : MENU_ITEMFLAGS_NONE);
6187.     }
6188.     end_menu(tmpwin, "Select loot sorting type:");
6189.     n = select_menu(tmpwin, PICK_ONE, &sortl_pick);
6190.     if (n > 0) {
6191.         char c = sortl_pick[0].item.a_char;
6192. 
6193.         if (n > 1 && c == flags.sortloot)
6194.             c = sortl_pick[1].item.a_char;
6195.         flags.sortloot = c;
6196.         /* changing to or from 'f' affects persistent inventory display */
6197.         if (iflags.perm_invent)
6198.             update_inventory();
6199.         free((genericptr_t) sortl_pick);
6200.     }
6201.     destroy_nhwindow(tmpwin);
6202.     return optn_ok;
6203. }
6204. 
6205. staticfn int
6206. handler_whatis_coord(void)
6207. {
6208.     winid tmpwin;
6209.     anything any;
6210.     char buf[BUFSZ];
6211.     menu_item *window_pick = (menu_item *) 0;
6212.     int pick_cnt;
6213.     char gpc = iflags.getpos_coords;
6214.     int clr = NO_COLOR;
6215. 
6216.     tmpwin = create_nhwindow(NHW_MENU);
6217.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6218.     any = cg.zeroany;
6219.     any.a_char = GPCOORDS_COMPASS;
6220.     add_menu(tmpwin, &nul_glyphinfo, &any, GPCOORDS_COMPASS,
6221.              0, ATR_NONE, clr,
6222.              "compass ('east' or '3s' or '2n,4w')",
6223.              (gpc == GPCOORDS_COMPASS)
6224.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6225.     any.a_char = GPCOORDS_COMFULL;
6226.     add_menu(tmpwin, &nul_glyphinfo, &any, GPCOORDS_COMFULL,
6227.              0, ATR_NONE, clr,
6228.              "full compass ('east' or '3south' or '2north,4west')",
6229.              (gpc == GPCOORDS_COMFULL)
6230.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6231.     any.a_char = GPCOORDS_MAP;
6232.     add_menu(tmpwin, &nul_glyphinfo, &any, GPCOORDS_MAP,
6233.              0, ATR_NONE, clr, "map <x,y>",
6234.              (gpc == GPCOORDS_MAP)
6235.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6236.     any.a_char = GPCOORDS_SCREEN;
6237.     add_menu(tmpwin, &nul_glyphinfo, &any, GPCOORDS_SCREEN,
6238.              0, ATR_NONE, clr, "screen [row,column]",
6239.              (gpc == GPCOORDS_SCREEN)
6240.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6241.     any.a_char = GPCOORDS_NONE;
6242.     add_menu(tmpwin, &nul_glyphinfo, &any, GPCOORDS_NONE,
6243.              0, ATR_NONE, clr, "none (no coordinates displayed)",
6244.              (gpc == GPCOORDS_NONE)
6245.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6246.     add_menu_str(tmpwin, "");
6247.     Sprintf(buf, "map: upper-left: <%d,%d>, lower-right: <%d,%d>%s",
6248.             1, 0, COLNO - 1, ROWNO - 1,
6249.             flags.verbose ? "; column 0 unused, off left edge" : "");
6250.     add_menu_str(tmpwin, buf);
6251.     if (strcmp(windowprocs.name, "tty")) /* only show for non-tty */
6252.         add_menu_str(tmpwin,
6253.       "screen: row is offset to accommodate tty interface's use of top line");
6254. #if COLNO == 80
6255. #define COL80ARG flags.verbose ? "; column 80 is not used" : ""
6256. #else
6257. #define COL80ARG ""
6258. #endif
6259.     Sprintf(buf, "screen: upper-left: [%02d,%02d], lower-right: [%d,%d]%s",
6260.             0 + 2, 1, ROWNO - 1 + 2, COLNO - 1, COL80ARG);
6261. #undef COL80ARG
6262.     add_menu_str(tmpwin, buf);
6263.     add_menu_str(tmpwin, "");
6264.     end_menu(tmpwin,
6265.         "Select coordinate display when auto-describing a map position:");
6266.     if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &window_pick)) > 0) {
6267.         iflags.getpos_coords = window_pick[0].item.a_char;
6268.         /* PICK_ONE doesn't unselect preselected entry when
6269.            selecting another one */
6270.         if (pick_cnt > 1 && iflags.getpos_coords == gpc)
6271.             iflags.getpos_coords = window_pick[1].item.a_char;
6272.         free((genericptr_t) window_pick);
6273.     }
6274.     destroy_nhwindow(tmpwin);
6275.     return optn_ok;
6276. }
6277. 
6278. staticfn int
6279. handler_whatis_filter(void)
6280. {
6281.     winid tmpwin;
6282.     anything any;
6283.     menu_item *window_pick = (menu_item *) 0;
6284.     int pick_cnt;
6285.     char gfilt = iflags.getloc_filter;
6286.     int clr = NO_COLOR;
6287. 
6288.     tmpwin = create_nhwindow(NHW_MENU);
6289.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6290.     any = cg.zeroany;
6291.     any.a_char = (GFILTER_NONE + 1);
6292.     add_menu(tmpwin, &nul_glyphinfo, &any, 'n',
6293.              0, ATR_NONE, clr, "no filtering",
6294.              (gfilt == GFILTER_NONE)
6295.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6296.     any.a_char = (GFILTER_VIEW + 1);
6297.     add_menu(tmpwin, &nul_glyphinfo, &any, 'v',
6298.              0, ATR_NONE, clr, "in view only",
6299.              (gfilt == GFILTER_VIEW)
6300.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6301.     any.a_char = (GFILTER_AREA + 1);
6302.     add_menu(tmpwin, &nul_glyphinfo, &any, 'a',
6303.              0, ATR_NONE, clr, "in same area",
6304.              (gfilt == GFILTER_AREA)
6305.                 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6306.     end_menu(tmpwin,
6307.       "Select location filtering when going for next/previous map position:");
6308.     if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &window_pick)) > 0) {
6309.         iflags.getloc_filter = (window_pick[0].item.a_char - 1);
6310.         /* PICK_ONE doesn't unselect preselected entry when
6311.            selecting another one */
6312.         if (pick_cnt > 1 && iflags.getloc_filter == gfilt)
6313.             iflags.getloc_filter = (window_pick[1].item.a_char - 1);
6314.         free((genericptr_t) window_pick);
6315.     }
6316.     destroy_nhwindow(tmpwin);
6317.     return optn_ok;
6318. }
6319. 
6320. staticfn int
6321. handler_symset(int optidx)
6322. {
6323.     int reslt;
6324. 
6325.     reslt = do_symset(optidx == opt_roguesymset);   /* symbols.c */
6326.     go.opt_need_redraw = TRUE;
6327.     return reslt;
6328. }
6329. 
6330. staticfn int
6331. handler_autopickup_exception(void)
6332. {
6333.     winid tmpwin;
6334.     anything any;
6335.     int i;
6336.     int opt_idx, numapes = 0;
6337.     char apebuf[2 + BUFSZ]; /* so &apebuf[1] is BUFSZ long for getlin() */
6338.     struct autopickup_exception *ape;
6339.     int clr = NO_COLOR;
6340. 
6341.  ape_again:
6342.     numapes = count_apes();
6343.     opt_idx = handle_add_list_remove("autopickup exception", numapes);
6344.     if (opt_idx == 3) { /* done */
6345.         return TRUE;
6346.     } else if (opt_idx == 0) { /* add new */
6347.         /* EDIT_GETLIN:  assume user doesn't user want previous
6348.            exception used as default input string for this one... */
6349.         apebuf[0] = apebuf[1] = '\0';
6350.         getlin("What new autopickup exception pattern?", &apebuf[1]);
6351.         mungspaces(&apebuf[1]); /* regularize whitespace */
6352.         if (apebuf[1] == '\033')
6353.             return TRUE;
6354.         if (apebuf[1]) {
6355.             apebuf[0] = '\"';
6356.             /* guarantee room for \" prefix and \"\0 suffix;
6357.                -2 is good enough for apebuf[] but -3 makes
6358.                sure the whole thing fits within normal BUFSZ */
6359.             apebuf[sizeof apebuf - 2] = '\0';
6360.             Strcat(apebuf, "\"");
6361.             add_autopickup_exception(apebuf);
6362.         }
6363.         goto ape_again;
6364.     } else { /* list (1) or remove (2) */
6365.         int pick_idx, pick_cnt;
6366.         menu_item *pick_list = (menu_item *) 0;
6367. 
6368.         tmpwin = create_nhwindow(NHW_MENU);
6369.         start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6370.         if (numapes) {
6371.             ape = ga.apelist;
6372.             any = cg.zeroany;
6373.             add_menu_heading(tmpwin,
6374.                              "Always pickup '<'; never pickup '>'");
6375.             for (i = 0; i < numapes && ape; i++) {
6376.                 any.a_void = (opt_idx == 1) ? 0 : ape;
6377.                 /* length of pattern plus quotes (plus '<'/'>') is
6378.                    less than BUFSZ */
6379.                 Sprintf(apebuf, "\"%c%s\"", ape->grab ? '<' : '>',
6380.                         ape->pattern);
6381.                 add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
6382.                          ATR_NONE, clr, apebuf, MENU_ITEMFLAGS_NONE);
6383.                 ape = ape->next;
6384.             }
6385.         }
6386.         Sprintf(apebuf, "%s autopickup exceptions",
6387.                 (opt_idx == 1) ? "List of" : "Remove which");
6388.         end_menu(tmpwin, apebuf);
6389.         pick_cnt = select_menu(tmpwin,
6390.                                (opt_idx == 1) ? PICK_NONE : PICK_ANY,
6391.                                &pick_list);
6392.         if (pick_cnt > 0) {
6393.             for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx)
6394.                 remove_autopickup_exception(
6395.                                      (struct autopickup_exception *)
6396.                                          pick_list[pick_idx].item.a_void);
6397.             free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
6398.         }
6399.         destroy_nhwindow(tmpwin);
6400.         if (pick_cnt >= 0)
6401.             goto ape_again;
6402.     }
6403.     return optn_ok;
6404. }
6405. 
6406. staticfn int
6407. handler_menu_colors(void)
6408. {
6409.     winid tmpwin;
6410.     anything any;
6411.     char buf[BUFSZ];
6412.     int opt_idx, nmc, mcclr, mcattr;
6413.     char mcbuf[BUFSZ];
6414.     int clr = NO_COLOR;
6415. 
6416.  menucolors_again:
6417.     nmc = count_menucolors();
6418.     opt_idx = handle_add_list_remove("menucolor", nmc);
6419.     if (opt_idx == 3) { /* done */
6420.  menucolors_done:
6421.         /* in case we've made a change which impacts current persistent
6422.            inventory window; we don't track whether an actual changed
6423.            occurred, so just assume there was one and that it matters;
6424.            if we're wrong, a redundant update is cheap... */
6425.         if (iflags.use_menu_color) {
6426.             if (iflags.perm_invent)
6427.                 update_inventory();
6428. 
6429.         }
6430.         return optn_ok;
6431. 
6432.     } else if (opt_idx == 0) { /* add new */
6433.         mcbuf[0] = '\0';
6434.         getlin("What new menucolor pattern?", mcbuf);
6435.         if (*mcbuf == '\033')
6436.             goto menucolors_done;
6437.         if (*mcbuf
6438.             && test_regex_pattern(mcbuf, "MENUCOLORS regex")
6439.             && (mcclr = query_color((char *) 0, NO_COLOR)) != -1
6440.                 && (mcattr = query_attr((char *) 0, ATR_NONE)) != -1
6441.             && !add_menu_coloring_parsed(mcbuf, mcclr, mcattr)) {
6442.             pline("Error adding the menu color.");
6443.             wait_synch();
6444.         }
6445.         goto menucolors_again;
6446. 
6447.     } else { /* list (1) or remove (2) */
6448.         int pick_idx, pick_cnt;
6449.         int mc_idx;
6450.         unsigned ln;
6451.         const char *sattr, *sclr;
6452.         menu_item *pick_list = (menu_item *) 0;
6453.         struct menucoloring *tmp = gm.menu_colorings;
6454.         char clrbuf[QBUFSZ];
6455. 
6456.         tmpwin = create_nhwindow(NHW_MENU);
6457.         start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6458.         any = cg.zeroany;
6459.         mc_idx = 0;
6460.         while (tmp) {
6461.             sattr = attr2attrname(tmp->attr);
6462.             sclr = strcpy(clrbuf, clr2colorname(tmp->color));
6463.             (void) strNsubst(clrbuf, " ", "-", 0);
6464.             any.a_int = ++mc_idx;
6465.             /* construct suffix */
6466.             Sprintf(buf, "\"\"=%s%s%s", sclr,
6467.                     (tmp->attr != ATR_NONE) ? "&" : "",
6468.                     (tmp->attr != ATR_NONE) ? sattr : "");
6469.             /* now main string */
6470.             ln = sizeof buf - Strlen(buf) - 1; /* length available */
6471.             Strcpy(mcbuf, "\"");
6472.             if (strlen(tmp->origstr) > ln)
6473.                 Strcat(strncat(mcbuf, tmp->origstr, ln - 3), "...");
6474.             else
6475.                 Strcat(mcbuf, tmp->origstr);
6476.             /* combine main string and suffix */
6477.             Strcat(mcbuf, &buf[1]); /* skip buf[]'s initial quote */
6478.             add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
6479.                      ATR_NONE, clr, mcbuf, MENU_ITEMFLAGS_NONE);
6480.             tmp = tmp->next;
6481.         }
6482.         Sprintf(mcbuf, "%s menu colors",
6483.                 (opt_idx == 1) ? "List of" : "Remove which");
6484.         end_menu(tmpwin, mcbuf);
6485.         pick_cnt = select_menu(tmpwin,
6486.                                (opt_idx == 1) ? PICK_NONE : PICK_ANY,
6487.                                &pick_list);
6488.         if (pick_cnt > 0) {
6489.             for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx)
6490.                 free_one_menu_coloring(pick_list[pick_idx].item.a_int - 1
6491.                                        - pick_idx);
6492.             free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
6493.         }
6494.         destroy_nhwindow(tmpwin);
6495.         if (pick_cnt >= 0)
6496.             goto menucolors_again;
6497.     }
6498.     return optn_ok;
6499. }
6500. 
6501. staticfn int
6502. handler_msgtype(void)
6503. {
6504.     winid tmpwin;
6505.     anything any;
6506.     int opt_idx, nmt, mttyp;
6507.     char mtbuf[BUFSZ];
6508. 
6509.  msgtypes_again:
6510.     nmt = msgtype_count();
6511.     opt_idx = handle_add_list_remove("message type", nmt);
6512.     if (opt_idx == 3) { /* done */
6513.         return TRUE;
6514.     } else if (opt_idx == 0) { /* add new */
6515.         mtbuf[0] = '\0';
6516.         getlin("What new message pattern?", mtbuf);
6517.         if (*mtbuf == '\033')
6518.             return TRUE;
6519.         if (*mtbuf
6520.             && test_regex_pattern(mtbuf, "MSGTYPE regex")
6521.             && (mttyp = query_msgtype()) != -1
6522.             && !msgtype_add(mttyp, mtbuf)) {
6523.             pline("Error adding the message type.");
6524.             wait_synch();
6525.         }
6526.         goto msgtypes_again;
6527.     } else { /* list (1) or remove (2) */
6528.         int pick_idx, pick_cnt;
6529.         int mt_idx;
6530.         unsigned ln;
6531.         const char *mtype;
6532.         menu_item *pick_list = (menu_item *) 0;
6533.         struct plinemsg_type *tmp = gp.plinemsg_types;
6534.         int clr = NO_COLOR;
6535. 
6536.         tmpwin = create_nhwindow(NHW_MENU);
6537.         start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6538.         any = cg.zeroany;
6539.         mt_idx = 0;
6540.         while (tmp) {
6541.             mtype = msgtype2name(tmp->msgtype);
6542.             any.a_int = ++mt_idx;
6543.             Sprintf(mtbuf, "%-5s \"", mtype);
6544.             ln = sizeof mtbuf - Strlen(mtbuf) - sizeof "\"";
6545.             if (strlen(tmp->pattern) > ln)
6546.                 Strcat(strncat(mtbuf, tmp->pattern, ln - 3), "...\"");
6547.             else
6548.                 Strcat(strcat(mtbuf, tmp->pattern), "\"");
6549.             add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
6550.                      ATR_NONE, clr, mtbuf, MENU_ITEMFLAGS_NONE);
6551.             tmp = tmp->next;
6552.         }
6553.         Sprintf(mtbuf, "%s message types",
6554.                 (opt_idx == 1) ? "List of" : "Remove which");
6555.         end_menu(tmpwin, mtbuf);
6556.         pick_cnt = select_menu(tmpwin,
6557.                                (opt_idx == 1) ? PICK_NONE : PICK_ANY,
6558.                                &pick_list);
6559.         if (pick_cnt > 0) {
6560.             for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx)
6561.                 free_one_msgtype(pick_list[pick_idx].item.a_int - 1
6562.                                        - pick_idx);
6563.             free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
6564.         }
6565.         destroy_nhwindow(tmpwin);
6566.         if (pick_cnt >= 0)
6567.             goto msgtypes_again;
6568.     }
6569.     return optn_ok;
6570. }
6571. 
6572. staticfn int
6573. handler_versinfo(void)
6574. {
6575.     winid tmpwin;
6576.     anything any;
6577.     menu_item *vi_pick = (menu_item *) 0;
6578.     boolean have_branch = (nomakedefs.git_branch && *nomakedefs.git_branch);
6579.     int n, vi = (int) flags.versinfo;
6580. 
6581.     tmpwin = create_nhwindow(NHW_MENU);
6582.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6583.     any = cg.zeroany;
6584. 
6585.     any.a_int = n = VI_NUMBER; /* 1 */
6586.     add_menu(tmpwin, &nul_glyphinfo, &any, 'n', n + '0', ATR_NONE, NO_COLOR,
6587.              "version number",
6588.              (vi & n) ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6589.     any.a_int = n = VI_NAME; /* 2 */
6590.     add_menu(tmpwin, &nul_glyphinfo, &any, 'g', n + '0', ATR_NONE, NO_COLOR,
6591.              "game name",
6592.              (vi & n) ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6593.     any.a_int = n = VI_BRANCH; /* 4 */
6594.     add_menu(tmpwin, &nul_glyphinfo, &any, 'b', n + '0', ATR_NONE, NO_COLOR,
6595.              (have_branch ? "development branch"
6596. #if (NH_DEVEL_STATUS == NH_STATUS_RELEASED)
6597.                           : "(not applicable)"
6598. #else
6599.                           : "(not available)"
6600. #endif
6601.               ), (vi & n) ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
6602. 
6603.     end_menu(tmpwin, "Select version information flags:");
6604.     n = select_menu(tmpwin, PICK_ANY, &vi_pick);
6605.     if (n > 0) {
6606.         int i, newval = 0;
6607. 
6608.         for (i = 0; i < n; ++i)
6609.             newval |= vi_pick[i].item.a_int;
6610.         newval &= 7;
6611.         if (newval)
6612.             flags.versinfo = (unsigned) newval;
6613.         free((genericptr_t) vi_pick);
6614.     }
6615.     destroy_nhwindow(tmpwin);
6616.     return optn_ok;
6617. }
6618. 
6619. staticfn int
6620. handler_windowborders(void)
6621. {
6622.     winid tmpwin;
6623.     anything any;
6624.     int i;
6625.     const char *mode_name;
6626.     menu_item *mode_pick = (menu_item *) 0;
6627.     int clr = NO_COLOR;
6628.     static const char *const windowborders_text[] = {
6629.         "Off, never show borders",
6630.         "On, always show borders",
6631.         "Auto, on if display is at least (24+2)x(80+2)",
6632.         "On, except forced off for perm_invent",
6633.         "Auto, except forced off for perm_invent"
6634.     };
6635. 
6636.     tmpwin = create_nhwindow(NHW_MENU);
6637.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
6638.     any = cg.zeroany;
6639.     for (i = 0; i < SIZE(windowborders_text); i++) {
6640.         mode_name = windowborders_text[i];
6641.         any.a_int = i + 1;
6642.         /* index 'i' matches the numeric setting for windowborders,
6643.            so allow corresponding digit as group accelerator */
6644.         add_menu(tmpwin, &nul_glyphinfo, &any, 'a' + i, '0' + i,
6645.                  ATR_NONE, clr, mode_name, MENU_ITEMFLAGS_NONE);
6646.     }
6647.     end_menu(tmpwin, "Select window borders mode:");
6648.     if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) {
6649.         iflags.wc2_windowborders = mode_pick->item.a_int - 1;
6650.         free((genericptr_t) mode_pick);
6651.     }
6652.     destroy_nhwindow(tmpwin);
6653.     return optn_ok;
6654. }
6655. 
6656. /*
6657.  **********************************
6658.  *
6659.  *   Parsing Support Functions
6660.  *
6661.  **********************************
6662.  */
6663. 
6664. staticfn char *
6665. string_for_opt(char *opts, boolean val_optional)
6666. {
6667.     char *colon, *equals;
6668. 
6669.     colon = strchr(opts, ':');
6670.     equals = strchr(opts, '=');
6671.     if (!colon || (equals && equals < colon))
6672.         colon = equals;
6673. 
6674.     if (!colon || !*++colon) {
6675.         if (!val_optional)
6676.             config_error_add("Missing parameter for '%s'", opts);
6677.         return empty_optstr;
6678.     }
6679.     return colon;
6680. }
6681. 
6682. staticfn char *
6683. string_for_env_opt(const char *optname, char *opts, boolean val_optional)
6684. {
6685.     if (!go.opt_initial) {
6686.         rejectoption(optname);
6687.         return empty_optstr;
6688.     }
6689.     return string_for_opt(opts, val_optional);
6690. }
6691. 
6692. staticfn void
6693. bad_negation(const char *optname, boolean with_parameter)
6694. {
6695.     config_error_add("The %s option may not %sbe negated.", optname,
6696.                      with_parameter ? "both have a value and " : "");
6697. }
6698. 
6699. /* go through all of the options and set the minmatch value
6700.    based on what is needed for uniqueness of each individual
6701.    option. Set a minimum of 3 characters. */
6702. staticfn void
6703. determine_ambiguities(void)
6704. {
6705.     int i, j, len, tmpneeded, needed[SIZE(allopt)];
6706.     const char *p1, *p2;
6707. 
6708.     for (i = 0; i < SIZE(allopt) - 1; ++i) {
6709.         needed[i] = 0;
6710.     }
6711. 
6712.     for (i = 0; i < SIZE(allopt) - 1; ++i) {
6713.         for (j = 0; j < SIZE(allopt) - 1; ++j) {
6714.             if (j == i)
6715.                 continue;
6716. 
6717.             p1 = allopt[i].name; /* back to the start */
6718.             p2 = allopt[j].name;
6719.             tmpneeded = 1;
6720.             while (*p1 && *p2 && lowc(*p1) == lowc(*p2)) {
6721.                 ++tmpneeded;
6722.                 ++p1;
6723.                 ++p2;
6724.             }
6725.             if (tmpneeded > needed[i])
6726.                 needed[i] = tmpneeded;
6727.             if (tmpneeded > needed[j])
6728.                 needed[j] = tmpneeded;
6729.         }
6730.     }
6731.     for (i = 0; i < SIZE(allopt) - 1; ++i) {
6732.         len = Strlen(allopt[i].name);
6733.         allopt[i].minmatch = (needed[i] < 3) ? 3
6734.                                 : (needed[i] <= len) ? needed[i] : len;
6735.     }
6736. }
6737. 
6738. staticfn int
6739. length_without_val(const char *user_string, int len)
6740. {
6741.     const char *p = strchr(user_string, ':'),
6742.                *q = strchr(user_string, '=');
6743. 
6744.     if (!p || (q && q < p))
6745.         p = q;
6746.     if (p) {
6747.         /* 'user_string' hasn't necessarily been through mungspaces()
6748.            so might have tabs or consecutive spaces */
6749.         while (p > user_string && isspace((uchar) *(p - 1)))
6750.             p--;
6751.         len = (int) (p - user_string);
6752.     }
6753.     return len;
6754. }
6755. 
6756. /* check whether a user-supplied option string is a proper leading
6757.    substring of a particular option name; option string might have
6758.    a colon or equals sign and arbitrary value appended to it */
6759. boolean
6760. match_optname(const char *user_string, const char *optn_name,
6761.               int min_length, boolean val_allowed)
6762. {
6763.     int len = (int) strlen(user_string);
6764. 
6765.     if (val_allowed)
6766.         len = length_without_val(user_string, len);
6767. 
6768.     return (boolean) (len >= min_length
6769.                       && !strncmpi(optn_name, user_string, len));
6770. }
6771. 
6772. void
6773. reset_duplicate_opt_detection(void)
6774. {
6775.     int k;
6776. 
6777.     for (k = 0; k < OPTCOUNT; ++k)
6778.         allopt[k].dupdetected = 0;
6779. }
6780. 
6781. staticfn boolean
6782. duplicate_opt_detection(int optidx)
6783. {
6784.     if (go.opt_initial && go.opt_from_file)
6785.         return allopt[optidx].dupdetected++;
6786.     return FALSE;
6787. }
6788. 
6789. staticfn void
6790. complain_about_duplicate(int optidx)
6791. {
6792.     char buf[BUFSZ];
6793. 
6794. #ifdef MACOS9
6795.     /* the Mac has trouble dealing with the output of messages while
6796.      * processing the config file.  That should get fixed one day.
6797.      * For now just return.
6798.      */
6799. #else /* !MACOS9 */
6800.     buf[0] = '\0';
6801.     if (using_alias)
6802.         Sprintf(buf, " (via alias: %s)", allopt[optidx].alias);
6803.     config_error_add("%s option specified multiple times: %s%s",
6804.                      (allopt[optidx].opttyp == CompOpt) ? "compound"
6805.                                                         : "boolean",
6806.                      allopt[optidx].name, buf);
6807. #endif /* ?MACOS9 */
6808.     return;
6809. }
6810. 
6811. staticfn void
6812. rejectoption(const char *optname)
6813. {
6814. #ifdef MICRO
6815.     pline("\"%s\" settable only from %s.", optname, get_configfile());
6816. #else
6817.     pline("%s can be set only from NETHACKOPTIONS or %s.", optname,
6818.           get_configfile());
6819. #endif
6820. }
6821. 
6822. /*
6823. 
6824. # errors:
6825. OPTIONS=aaaaaaaaaa[ more than 247 (255 - 8 for 'OPTIONS=') total ]aaaaaaaaaa
6826. OPTIONS
6827. OPTIONS=
6828. MSGTYPE=stop"You swap places with "
6829. MSGTYPE=st.op "You swap places with "
6830. MSGTYPE=stop "You swap places with \"
6831. MENUCOLOR=" blessed "green&none
6832. MENUCOLOR=" holy " = green&reverse
6833. MENUCOLOR=" cursed " = red&uline
6834. MENUCOLOR=" unholy " = reed
6835. OPTIONS=!legacy:true,fooo
6836. OPTIONS=align:!pin
6837. OPTIONS=gender
6838. 
6839. */
6840. /* most environment variables will eventually be printed in an error
6841.  * message if they don't work, and most error message paths go through
6842.  * BUFSZ buffers, which could be overflowed by a maliciously long
6843.  * environment variable.  If a variable can legitimately be long, or
6844.  * if it's put in a smaller buffer, the responsible code will have to
6845.  * bounds-check itself.
6846.  */
6847. char *
6848. nh_getenv(const char *ev)
6849. {
6850.     char *getev = getenv(ev);
6851. 
6852.     if (getev && strlen(getev) <= (BUFSZ / 2))
6853.         return getev;
6854.     else
6855.         return (char *) 0;
6856. }
6857. 
6858. /* copy up to maxlen-1 characters; 'dest' must be able to hold maxlen;
6859.    treat comma as alternate end of 'src' */
6860. staticfn void
6861. nmcpy(char *dest, const char *src, int maxlen)
6862. {
6863.     int count;
6864. 
6865.     for (count = 1; count < maxlen; count++) {
6866.         if (*src == ',' || *src == '\0')
6867.             break; /*exit on \0 terminator*/
6868.         *dest++ = *src++;
6869.     }
6870.     *dest = '\0';
6871. }
6872. 
6873. /*
6874.  * escapes(): escape expansion for showsyms.  C-style escapes understood
6875.  * include \n, \b, \t, \r, \xnnn (hex), \onnn (octal), \nnn (decimal).
6876.  * (Note: unlike in C, leading digit 0 is not used to indicate octal;
6877.  * the letter o (either upper or lower case) is used for that.
6878.  * The ^-prefix for control characters is also understood, and \[mM]
6879.  * has the effect of 'meta'-ing the value which follows (so that the
6880.  * alternate character set will be enabled).
6881.  *
6882.  * X     normal key X
6883.  * ^X    control-X
6884.  * \mX   meta-X
6885.  *
6886.  * For 3.4.3 and earlier, input ending with "\M", backslash, or caret
6887.  * prior to terminating '\0' would pull that '\0' into the output and then
6888.  * keep processing past it, potentially overflowing the output buffer.
6889.  * Now, trailing \ or ^ will act like \\ or \^ and add '\\' or '^' to the
6890.  * output and stop there; trailing \M will fall through to \<other> and
6891.  * yield 'M', then stop.  Any \X or \O followed by something other than
6892.  * an appropriate digit will also fall through to \<other> and yield 'X'
6893.  * or 'O', plus stop if the non-digit is end-of-string.
6894.  */
6895. staticfn void
6896. escapes(const char *cp, /* might be 'tp', updating in place */
6897.         char *tp)       /* result is never longer than 'cp' */
6898. {
6899.     static NEARDATA const char oct[] = "01234567", dec[] = "0123456789";
6900.     /* hexdd[] is defined in decl.c */
6901. 
6902.     const char *dp;
6903.     int cval, meta, dcount;
6904. 
6905.     while (*cp) {
6906.         /* \M has to be followed by something to do meta conversion,
6907.            otherwise it will just be \M which ultimately yields 'M' */
6908.         meta = (*cp == '\\' && (cp[1] == 'm' || cp[1] == 'M') && cp[2]);
6909.         if (meta)
6910.             cp += 2;
6911. 
6912.         cval = dcount = 0; /* for decimal, octal, hexadecimal cases */
6913.         if ((*cp != '\\' && *cp != '^') || !cp[1]) {
6914.             /* simple character, or nothing left for \ or ^ to escape */
6915.             cval = *cp++;
6916.         } else if (*cp == '^') { /* expand control-character syntax */
6917.             cval = (*++cp & 0x1f);
6918.             ++cp;
6919. 
6920.         /* remaining cases are all for backslash; we know cp[1] is not \0 */
6921.         } else if (strchr(dec, cp[1])) {
6922.             ++cp; /* move past backslash to first digit */
6923.             do {
6924.                 cval = (cval * 10) + (*cp - '0');
6925.             } while (*++cp && strchr(dec, *cp) && ++dcount < 3);
6926.         } else if ((cp[1] == 'o' || cp[1] == 'O') && cp[2]
6927.                    && strchr(oct, cp[2])) {
6928.             cp += 2; /* move past backslash and 'O' */
6929.             do {
6930.                 cval = (cval * 8) + (*cp - '0');
6931.             } while (*++cp && strchr(oct, *cp) && ++dcount < 3);
6932.         } else if ((cp[1] == 'x' || cp[1] == 'X') && cp[2]
6933.                    && (dp = strchr(hexdd, cp[2])) != 0) {
6934.             cp += 2; /* move past backslash and 'X' */
6935.             do {
6936.                 cval = (cval * 16) + ((int) (dp - hexdd) / 2);
6937.             } while (*++cp && (dp = strchr(hexdd, *cp)) != 0 && ++dcount < 2);
6938.         } else { /* C-style character escapes */
6939.             switch (*++cp) {
6940.             case '\\':
6941.                 cval = '\\';
6942.                 break;
6943.             case 'n':
6944.                 cval = '\n';
6945.                 break;
6946.             case 't':
6947.                 cval = '\t';
6948.                 break;
6949.             case 'b':
6950.                 cval = '\b';
6951.                 break;
6952.             case 'r':
6953.                 cval = '\r';
6954.                 break;
6955.             default:
6956.                 cval = *cp;
6957.             }
6958.             ++cp;
6959.         }
6960. 
6961.         if (meta)
6962.             cval |= 0x80;
6963.         *tp++ = (char) cval;
6964.     }
6965.     *tp = '\0';
6966. }
6967. 
6968. /* returns a one-byte character from the text; may change txt[];
6969.    moved from cmd.c in order to get access to escapes() */
6970. uchar
6971. txt2key(char *txt)
6972. {
6973.     uchar uc;
6974.     boolean makemeta = FALSE;
6975. 
6976.     txt = trimspaces(txt);
6977.     if (!*txt)
6978.         return '\0';
6979. 
6980.     /* simple character */
6981.     if (!txt[1])
6982.         return (uchar) txt[0];
6983. 
6984.     /* a few special entries */
6985.     if (!strcmp(txt, "<enter>"))
6986.         return '\n';
6987.     if (!strcmp(txt, "<space>"))
6988.         return ' ';
6989.     if (!strcmp(txt, "<esc>"))
6990.         return '\033';
6991. 
6992.     /* handle things like \b and \7 and \mX */
6993.     if (*txt == '\\') {
6994.         char tbuf[QBUFSZ];
6995. 
6996.         if (strlen(txt) >= sizeof tbuf)
6997.             txt[sizeof tbuf - 1] = '\0';
6998.         escapes(txt, tbuf);
6999.         return *tbuf;
7000.     }
7001. 
7002.     /* control and meta keys */
7003.     if (highc(*txt) == 'M') {
7004.         /*
7005.          * M <nothing>             return 'M'
7006.          * M - <nothing>           return M-'-'
7007.          * M <other><nothing>      return M-<other>
7008.          * otherwise M is pending until after ^/C- processing.
7009.          * Since trailing spaces are discarded, the only way to
7010.          * specify M-' ' is via "160".
7011.          */
7012.         if (!txt[1])
7013.             return (uchar) *txt;
7014.         /* skip past 'M' or 'm' and maybe '-' */
7015.         ++txt;
7016.         if (*txt == '-' && txt[1])
7017.             ++txt;
7018.         if (!txt[1])
7019.             return M((uchar) *txt);
7020.         makemeta = TRUE;
7021.     }
7022.     if (*txt == '^' || highc(*txt) == 'C') {
7023.         /*
7024.          * C <nothing>             return 'C' or M-'C'
7025.          * C - <nothing>           return '-' or M-'-'
7026.          * C [-] <other><nothing>  return C-<other> or M-C-<other>
7027.          * C [-] ?                 return <rubout>
7028.          * otherwise return C-<other> or M-C-<other>
7029.          */
7030.         uc = (uchar) *txt;
7031.         if (!txt[1])
7032.             return makemeta ? M(uc) : uc;
7033.         ++txt;
7034.         /* unlike M-x, lots of values of x are invalid for C-x;
7035.            checking and rejecting them is not worthwhile; GIGO;
7036.            we do accept "^-x" as synonym for "^x" or "C-x" */
7037.         if (*txt == '-' && txt[1])
7038.             ++txt;
7039.         /* and accept ^?, which gets used despite not being a control char */
7040.         if (*txt == '?')
7041.             return (uchar) (makemeta ? '\377' : '\177'); /* rubout/delete */
7042.         uc = C((uchar) *txt);
7043.         return makemeta ? M(uc) : uc;
7044.     }
7045.     if (makemeta && *txt)
7046.         return M((uchar) *txt);
7047. 
7048.     /* FIXME: should accept single-quote single-character single-quote
7049.        and probably single-quote backslash octal-digits single-quote;
7050.        if we do that, the M- and C- results should be pending until
7051.        after, so that C-'X' becomes valid for ^X */
7052. 
7053.     /* ascii codes: must be three-digit decimal */
7054.     if (*txt >= '0' && *txt <= '9') {
7055.         uchar key = 0;
7056.         int i;
7057. 
7058.         for (i = 0; i < 3; i++) {
7059.             if (txt[i] < '0' || txt[i] > '9')
7060.                 return '\0';
7061.             key = 10 * key + txt[i] - '0';
7062.         }
7063.         return key;
7064.     }
7065. 
7066.     return '\0';
7067. }
7068. 
7069. /*
7070.  **********************************
7071.  *
7072.  *   Options Initialization
7073.  *
7074.  **********************************
7075.  */
7076. 
7077. /* process options, possibly including SYSCF */
7078. void
7079. initoptions(void)
7080. {
7081.     /*
7082.      * Most places that call initoptions_init()/initoptions() would
7083.      * have the calls next to each other, so instead of adding
7084.      * initoptions_init() everywhere, just add it where it's needed in
7085.      * a non-adjacent place and call it here for all the other cases.
7086.      */
7087.     if (go.opt_phase != builtin_opt)
7088.          initoptions_init();
7089. #ifdef SYSCF
7090. /* someday there may be other SYSCF alternatives besides text file */
7091. #ifdef SYSCF_FILE
7092.     /* If SYSCF_FILE is specified, it _must_ exist... */
7093.     assure_syscf_file();
7094.     config_error_init(TRUE, SYSCF_FILE, FALSE);
7095. 
7096.     /* ... and _must_ parse correctly. */
7097.     go.opt_phase = syscf_opt;
7098.     if (!read_config_file(SYSCF_FILE, set_in_sysconf)) {
7099.         if (config_error_done() && !iflags.initoptions_noterminate)
7100.             nh_terminate(EXIT_FAILURE);
7101.     }
7102.     config_error_done();
7103.     /*
7104.      * TODO [maybe]: parse the sysopt entries which are space-separated
7105.      * lists of usernames into arrays with one name per element.
7106.      */
7107. #endif
7108. #endif /* SYSCF */
7109. 
7110.     /* Carry out options that got deferred from early_options */
7111.     if (gd.deferred_showpaths)
7112.         do_deferred_showpaths(0);  /* does not return */
7113. 
7114.     initoptions_finish();
7115. }
7116. 
7117. /* set up default values for options where 0 or False isn't sufficient */
7118. void
7119. initoptions_init(void)
7120. {
7121. #if (defined(UNIX) || defined(VMS)) && defined(TTY_GRAPHICS)
7122.     char *opts;
7123. #endif
7124.     int i;
7125.     boolean have_branch = (nomakedefs.git_branch && *nomakedefs.git_branch);
7126. 
7127.     go.opt_phase = builtin_opt;    /* Did I need to move this here? */
7128.     /* initialize the function pointers for saving the game */
7129.     sf_init();
7130.     allopt_array_init();
7131.     /* if windowtype has been specified on the command line, set it up
7132.        early so windowtype-specific options use it as their base */
7133.     if (gc.cmdline_windowsys) {
7134.         nmcpy(gc.chosen_windowtype, gc.cmdline_windowsys, WINTYPELEN);
7135.         config_error_init(FALSE, "command line", FALSE);
7136.         choose_windows(gc.cmdline_windowsys);
7137.         config_error_done();
7138.         /*
7139.          * FIXME?  This continues even if setting windowtype to player's
7140.          * specified value fails.  It doesn't lock the windowtype in
7141.          * that situation though, so the game will use whatever is in
7142.          * RC/NETHACKOPTIONS or resort to DEFAULT_WINDOW_SYS.
7143.          */
7144.         if (windowprocs.name
7145.             && !strcmpi(windowprocs.name, gc.cmdline_windowsys))
7146.             /* ignore any windowtype:foo in RC file or NETHACKOPTIONS */
7147.             iflags.windowtype_locked = TRUE;
7148.         /* shouldn't need cmdline_windowsys beyond here */
7149.         free((genericptr_t) gc.cmdline_windowsys),
7150.             gc.cmdline_windowsys = NULL;
7151.     }
7152. 
7153.     /* make any symbol parsing quicker */
7154.     if (!glyphid_cache_status())
7155.         fill_glyphid_cache();
7156. 
7157.     /* set up the command parsing */
7158.     reset_commands(TRUE); /* init */
7159. 
7160.     /* initialize the random number generator(s) */
7161.     init_random(rn2);
7162.     init_random(rn2_on_display_rng);
7163. 
7164.     go.opt_phase = builtin_opt;
7165.     for (i = 0; allopt[i].name; i++) {
7166.         if (allopt[i].addr)
7167.             *(allopt[i].addr) = allopt[i].initval;
7168.     }
7169. 
7170.     flags.end_own = FALSE;
7171.     flags.end_top = 3;
7172.     flags.end_around = 2;
7173.     flags.paranoia_bits = PARANOID_PRAY | PARANOID_SWIM | PARANOID_TRAP;
7174.     flags.versinfo = have_branch ? 4 : 1;
7175.     flags.pile_limit = PILE_LIMIT_DFLT;  /* 5 */
7176.     flags.runmode = RUN_LEAP;
7177.     iflags.msg_history = 20;
7178. 
7179.     /* msg_window has conflicting defaults for multi-interface binary */
7180. #ifdef TTY_GRAPHICS
7181.     iflags.prevmsg_window = 's';
7182. #else
7183. #ifdef CURSES_GRAPHICS
7184.     iflags.prevmsg_window = 'r';
7185. #endif
7186. #endif
7187. 
7188.     iflags.menu_headings.attr = ATR_INVERSE;
7189.     iflags.menu_headings.color = NO_COLOR;
7190.     iflags.getpos_coords = GPCOORDS_NONE;
7191. 
7192.     /* hero's role, race, &c haven't been chosen yet */
7193.     flags.initrole = flags.initrace = flags.initgend = flags.initalign
7194.         = ROLE_NONE;
7195. 
7196.     init_ov_primary_symbols();
7197.     init_ov_rogue_symbols();
7198.     /* Set the default monster and object class symbols. */
7199.     init_symbols();
7200.     for (i = 0; i < WARNCOUNT; i++)
7201.         gw.warnsyms[i] = def_warnsyms[i].sym;
7202. 
7203.     /* assert( sizeof flags.inv_order == sizeof def_inv_order ); */
7204.     (void) memcpy((genericptr_t) flags.inv_order,
7205.                   (genericptr_t) def_inv_order, sizeof flags.inv_order);
7206.     flags.pickup_types[0] = '\0';
7207.     flags.pickup_burden = MOD_ENCUMBER;
7208.     flags.sortloot = 'l'; /* sort only loot by default */
7209. 
7210.     for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++)
7211.         flags.end_disclose[i] = DISCLOSE_PROMPT_DEFAULT_NO;
7212.     switch_symbols(FALSE); /* set default characters */
7213.     init_rogue_symbols();
7214. #if defined(UNIX) && defined(TTY_GRAPHICS)
7215.     /*
7216.      * Set defaults for some options depending on what we can
7217.      * detect about the environment's capabilities.
7218.      * This has to be done after the global initialization above
7219.      * and before reading user-specific initialization via
7220.      * config file/environment variable below.
7221.      */
7222.     /* this detects the IBM-compatible console on most 386 boxes */
7223.     if ((opts = nh_getenv("TERM")) && !strncmp(opts, "AT", 2)) {
7224.         if (!gs.symset[PRIMARYSET].explicitly)
7225.             load_symset("IBMGraphics", PRIMARYSET);
7226.         if (!gs.symset[ROGUESET].explicitly)
7227.             load_symset("RogueIBM", ROGUESET);
7228.         switch_symbols(TRUE);
7229.         iflags.use_color = TRUE;
7230.     }
7231. #endif /* UNIX && TTY_GRAPHICS */
7232. #if defined(UNIX) || defined(VMS)
7233. #ifdef TTY_GRAPHICS
7234.     /* detect whether a "vt" terminal can handle alternate charsets */
7235.     if ((opts = nh_getenv("TERM"))
7236.         /* [could also check "xterm" which emulates vtXXX by default] */
7237.         && !strncmpi(opts, "vt", 2)
7238.         && AS && AE && strchr(AS, '\016') && strchr(AE, '\017')) {
7239.         if (!gs.symset[PRIMARYSET].explicitly)
7240.             load_symset("DECGraphics", PRIMARYSET);
7241.         switch_symbols(TRUE);
7242.     }
7243. #endif
7244. #endif /* UNIX || VMS */
7245. 
7246. #if defined(MSDOS) || defined(WIN32)
7247.     /* Use IBM defaults. Can be overridden via config file */
7248.     if (!gs.symset[PRIMARYSET].explicitly)
7249.         load_symset("IBMGraphics_2", PRIMARYSET);
7250.     if (!gs.symset[ROGUESET].explicitly)
7251.         load_symset("RogueEpyx", ROGUESET);
7252. #endif
7253. #ifdef MAC_GRAPHICS_ENV
7254.     if (!gs.symset[PRIMARYSET].explicitly)
7255.         load_symset("MACGraphics", PRIMARYSET);
7256.     switch_symbols(TRUE);
7257. #endif /* MAC_GRAPHICS_ENV */
7258.     flags.menu_style = MENU_FULL;
7259. 
7260.     iflags.wc_align_message = ALIGN_TOP;
7261.     iflags.wc_align_status = ALIGN_BOTTOM;
7262.     /* used by tty and curses */
7263.     iflags.wc2_statuslines = 2;
7264.     iflags.wc2_petattr = ATR_INVERSE;
7265.     /* only used by curses */
7266.     iflags.wc2_windowborders = 2; /* 'Auto' */
7267. 
7268.     /*
7269.      * A few menus have certain items (typically operate-on-everything or
7270.      * change-subset or sort or help entries) flagged as 'skip-invert' to
7271.      * control how whole-page and whole-menu operations affect them.
7272.      * 'menuinvertmode' controls how that functions:
7273.      * 0: ignore 'skip-invert' flag on menu items (used to be the default);
7274.      * 1: don't toggle 'skip-invert' items On for set-all/set-page/invert-
7275.      *    all/invert-page but do toggle Off if already set (default);
7276.      * 2: don't toggle 'skip-invert' items either On of Off for set-all/
7277.      *    set-page/unset-all/unset-page/invert-all/invert-page.
7278.      */
7279.     iflags.menuinvertmode = 1;
7280. 
7281.     /* since this is done before init_objects(), do partial init here */
7282.     objects[SLIME_MOLD].oc_name_idx = SLIME_MOLD;
7283.     nmcpy(svp.pl_fruit, OBJ_NAME(objects[SLIME_MOLD]), PL_FSIZ);
7284. 
7285. #ifdef SYSCF
7286. /* someday there may be other SYSCF alternatives besides text file */
7287. #ifdef SYSCF_FILE
7288.     /* If SYSCF_FILE is specified, it _must_ exist... */
7289.     assure_syscf_file();
7290.     config_error_init(TRUE, SYSCF_FILE, FALSE);
7291. 
7292.     /* ... and _must_ parse correctly. */
7293.     go.opt_phase = syscf_opt;
7294.     if (!read_config_file(SYSCF_FILE, set_in_sysconf)) {
7295.         if (config_error_done() && !iflags.initoptions_noterminate)
7296.             nh_terminate(EXIT_FAILURE);
7297.     }
7298.     config_error_done();
7299.     /*
7300.      * TODO [maybe]: parse the sysopt entries which are space-separated
7301.      * lists of usernames into arrays with one name per element.
7302.      */
7303. #endif
7304. #endif /* SYSCF */
7305. }
7306. 
7307. /*
7308.  *  Process user's run-time configuration file:
7309.  *    get value of NETHACKOPTIONS;
7310.  *    if command line specified -nethackrc=filename, use that;
7311.  *      if NETHACKOPTIONS is present,
7312.  *        honor it if it has a list of options to set
7313.  *        or ignore it if it specifies a file name;
7314.  *    else if not specified on command line and NETHACKOPTIONS names a file,
7315.  *      use that as the config file;
7316.  *      no extra options (normal use of NETHACKOPTIONS) will be set;
7317.  *    otherwise (not on command line and either no NETHACKOPTIONS or that
7318.  *        isn't a file name),
7319.  *      pass Null to read_config_file() so that it will read ~/.nethackrc
7320.  *        by default,
7321.  *      then process the value of NETHACKOPTIONS as extra options.
7322.  */
7323. void
7324. initoptions_finish(void)
7325. {   nhsym sym = 0;
7326. 
7327.     rcfile();
7328. 
7329.     (void) fruitadd(svp.pl_fruit, (struct fruit *) 0);
7330.     /*
7331.      * Remove "slime mold" from list of object names.  This will
7332.      * prevent it from being wished unless it's actually present
7333.      * as a named (or default) fruit.  Wishing for "fruit" will
7334.      * result in the player's preferred fruit.  [Once upon a time
7335.      * the override value used was "\033" which prevented wishing
7336.      * for the slime mold object at all except by asking for a
7337.      * specific named fruit.]  Note that there are multiple fruit
7338.      * object types (apple, melon, &c) but the "fruit" object is
7339.      * slime mold or whatever custom name player assigns to that.
7340.      */
7341.     obj_descr[SLIME_MOLD].oc_name = "fruit";
7342. 
7343.     sym = get_othersym(SYM_BOULDER,
7344.                 Is_rogue_level(&u.uz) ? ROGUESET : PRIMARYSET);
7345.     if (sym)
7346.         gs.showsyms[SYM_BOULDER + SYM_OFF_X] = sym;
7347.     reglyph_darkroom();
7348.     reset_glyphmap(gm_optionchange);
7349. #ifdef STATUS_HILITES
7350.     /*
7351.      * A multi-interface binary might only support status highlighting
7352.      * for some of the interfaces; check whether we asked for it but are
7353.      * using one which doesn't.
7354.      *
7355.      * Option processing can take place before a user-decided WindowPort
7356.      * is even initialized, so check for that too.
7357.      */
7358.     if (iflags.hilite_delta && !wc2_supported("statushilites")) {
7359.         raw_printf("Status highlighting not supported for %s interface.",
7360.                     windowprocs.name);
7361.         iflags.hilite_delta = 0;
7362.     }
7363. #endif
7364.     update_rest_on_space();
7365. 
7366.     /* these can't rely on compile-time initialization for their defaults
7367.        because a multi-interface binary might need different values for
7368.        different interfaces; if neither tiled_map nor ascii_map pass the
7369.        wc_supported() test, assume ascii_map */
7370.     if (iflags.wc_tiled_map && !wc_supported("tiled_map"))
7371.         iflags.wc_tiled_map = FALSE, iflags.wc_ascii_map = TRUE;
7372.     else if (iflags.wc_ascii_map && !wc_supported("ascii_map")
7373.              && wc_supported("tiled_map"))
7374.         iflags.wc_ascii_map = FALSE, iflags.wc_tiled_map = TRUE;
7375. 
7376. #ifdef ENHANCED_SYMBOLS
7377.     if (glyphid_cache_status())
7378.         free_glyphid_cache();
7379.     apply_customizations(gc.currentgraphics,
7380.                          do_custom_symbols | do_custom_colors);
7381. #endif
7382.     go.opt_initial = FALSE;
7383.     return;
7384. }
7385. 
7386. #if 0
7387.     /*
7388.      * Do these after clearing the 'opt_initial' flag.
7389.      */
7390. 
7391.     /* player's RC file might try to enable perm_invent before selecting
7392.        current interface, so the decision then would have been based on
7393.        default interface; re-check with the active interface now */
7394.     if (iflags.perm_invent) {
7395.         /* can_set_perm_invent() expects to be called when perm_invent
7396.            is about to be toggled On, so start with it Off */
7397.         iflags.perm_invent = FALSE;
7398.         if (can_set_perm_invent())
7399.             iflags.perm_invent = TRUE;
7400.     }
7401. }
7402. #endif
7403. 
7404. void
7405. allopt_array_init(void)
7406. {
7407.     int i;
7408.     static boolean options_array_inited_already = FALSE;
7409. 
7410.     if (!options_array_inited_already) {
7411.         memcpy(allopt, allopt_init, sizeof(allopt));
7412.         determine_ambiguities();
7413.         for (i = 0; allopt[i].name; i++) {
7414.             if (allopt[i].addr)
7415.                 *(allopt[i].addr) = allopt[i].initval;
7416.         }
7417.         heed_all_options();
7418.         /*
7419.          * Call each option function with an init flag and give it a chance
7420.          * to make any preparations that it might require.  We do this
7421.          * whether or not the option itself is ever specified; that's
7422.          * irrelevant for the init call.  Doing this allows the prep code for
7423.          * option settings to remain adjacent to, and in the same function as,
7424.          * the code that processes those options.
7425.          */
7426.         for (i = 0; i < OPTCOUNT; ++i) {
7427.             if (allopt[i].optfn)
7428.                 (*allopt[i].optfn)(i, do_init, FALSE, empty_optstr,
7429.                                    empty_optstr);
7430.         }
7431.         options_array_inited_already = TRUE;
7432.     }
7433. }
7434. 
7435. /*
7436.  *******************************************
7437.  *
7438.  * Support Functions for Individual Options
7439.  *
7440.  *******************************************
7441.  */
7442. 
7443. /* iflags.menuobjsyms also controls iflags.menu_head_objsym, and
7444.    iflags.use_menu_glyphs; they affect execution but are no longer options */
7445. staticfn void
7446. set_menuobjsyms_flags(int newobjsyms)
7447. {
7448.     iflags.menuobjsyms = newobjsyms;
7449.     iflags.menu_head_objsym = ((newobjsyms & 1) != 0) ? TRUE : FALSE;
7450.     iflags.use_menu_glyphs = ((newobjsyms & (2 | 4)) != 0) ? TRUE : FALSE;
7451. }
7452. 
7453. /*
7454.  * Change the inventory order, using the given string as the new order.
7455.  * Missing characters in the new order are filled in at the end from
7456.  * the current inv_order, except for gold, which is forced to be first
7457.  * if not explicitly present.
7458.  *
7459.  * This routine returns 1 unless there is a duplicate or bad char in
7460.  * the string.
7461.  *
7462.  * Used by: optfn_packorder()
7463.  *
7464.  */
7465. staticfn int
7466. change_inv_order(char *op)
7467. {
7468.     int oc_sym, num;
7469.     char *sp, buf[QBUFSZ];
7470.     int retval = 1;
7471. 
7472.     num = 0;
7473.     if (!strchr(op, GOLD_SYM))
7474.         buf[num++] = COIN_CLASS;
7475. 
7476.     for (sp = op; *sp; sp++) {
7477.         boolean fail = FALSE;
7478.         oc_sym = def_char_to_objclass(*sp);
7479.         /* reject bad or duplicate entries */
7480.         if (oc_sym == MAXOCLASSES) { /* not an object class char */
7481.             config_error_add("Not an object class '%c'", *sp);
7482.             retval = 0;
7483.             fail = TRUE;
7484.         } else if (!strchr(flags.inv_order, oc_sym)) {
7485.             /* VENOM_CLASS, RANDOM_CLASS, and ILLOBJ_CLASS are excluded
7486.                because they aren't in def_inv_order[] so don't make it
7487.                into flags.inv_order, hence always fail this strchr() test */
7488.             config_error_add("Object class '%c' not allowed", *sp);
7489.             retval = 0;
7490.             fail = TRUE;
7491.         } else if (strchr(sp + 1, *sp)) {
7492.             config_error_add("Duplicate object class '%c'", *sp);
7493.             retval = 0;
7494.             fail = TRUE;
7495.         }
7496.         /* retain good ones */
7497.         if (!fail)
7498.             buf[num++] = (char) oc_sym;
7499.     }
7500.     buf[num] = '\0';
7501. 
7502.     /* fill in any omitted classes, using previous ordering */
7503.     for (sp = flags.inv_order; *sp; sp++)
7504.         if (!strchr(buf, *sp))
7505.             (void) strkitten(&buf[num++], *sp);
7506.     buf[MAXOCLASSES - 1] = '\0';
7507. 
7508.     Strcpy(flags.inv_order, buf);
7509.     return retval;
7510. }
7511. 
7512. 
7513. /*
7514.  * Support functions for "warning"
7515.  *
7516.  * Used by: optfn_warnings()
7517.  *
7518.  */
7519. 
7520. staticfn boolean
7521. warning_opts(char *opts, const char *optype)
7522. {
7523.     uchar translate[WARNCOUNT];
7524.     int length, i;
7525. 
7526.     if ((opts = string_for_env_opt(optype, opts, FALSE)) == empty_optstr)
7527.         return FALSE;
7528.     escapes(opts, opts);
7529. 
7530.     length = (int) strlen(opts);
7531.     /* match the form obtained from PC configuration files */
7532.     for (i = 0; i < WARNCOUNT; i++)
7533.         translate[i] = (i >= length) ? 0
7534.                                      : opts[i] ? (uchar) opts[i]
7535.                                                : def_warnsyms[i].sym;
7536.     assign_warnings(translate);
7537.     return TRUE;
7538. }
7539. 
7540. void
7541. assign_warnings(uchar *graph_chars)
7542. {
7543.     int i;
7544. 
7545.     for (i = 0; i < WARNCOUNT; i++)
7546.         if (graph_chars[i])
7547.             gw.warnsyms[i] = graph_chars[i];
7548. }
7549. 
7550. /*
7551.  * Support functions for "suppress_alert"
7552.  *
7553.  * Used by: optfn_suppress_alert()
7554.  *
7555.  */
7556. 
7557. staticfn int
7558. feature_alert_opts(char *op, const char *optn)
7559. {
7560.     char buf[BUFSZ];
7561.     unsigned long fnv = get_feature_notice_ver(op); /* version.c */
7562. 
7563.     if (fnv == 0L)
7564.         return 0;
7565.     if (fnv > get_current_feature_ver()) {
7566.         if (!go.opt_initial) {
7567.             You_cant("disable new feature alerts for future versions.");
7568.         } else {
7569.             config_error_add(
7570.                         "%s=%s Invalid reference to a future version ignored",
7571.                              optn, op);
7572.         }
7573.         return 0;
7574.     }
7575. 
7576.     flags.suppress_alert = fnv;
7577.     if (!go.opt_initial) {
7578.         Sprintf(buf, "%lu.%lu.%lu", FEATURE_NOTICE_VER_MAJ,
7579.                 FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH);
7580.         pline(
7581.           "Feature change alerts disabled for NetHack %s features and prior.",
7582.               buf);
7583.     }
7584.     return 1;
7585. }
7586. 
7587. /*
7588.  * This is used by parse_config_line() in files.c
7589.  *
7590.  */
7591. 
7592. /* parse key:command[,key2:command2,...] after BINDINGS= prefix has been
7593.    stripped; returns False if any problem seen, True if every binding in
7594.    the comma-separated list is successful */
7595. boolean
7596. parsebindings(char *bindings)
7597. {
7598.     char *bind;
7599.     uchar key;
7600.     int i;
7601.     boolean ret = TRUE; /* assume success */
7602.     static const char *const mousebtn_names[NUM_MOUSE_BUTTONS] = {
7603.         "mouse1", "mouse2"
7604.     };
7605. 
7606.     /* look for first comma, then decide whether it is the key being bound
7607.        or a list element separator; if it's a key, find separator beyond it */
7608.     if ((bind = strchr(bindings, ',')) != 0) {
7609.         /* at start so it represents a key */
7610.         if (bind == bindings)
7611.             bind = strchr(bind + 1, ',');
7612. 
7613.         /* to get here, bind is non-Null and not equal to bindings,
7614.            so it is greater than bindings and bind[-1] is valid; check
7615.            whether current comma happens to be for "\,:cmd" or "',':cmd"
7616.            (":cmd" part is assumed if the comma has expected quoting) */
7617.         else if (bind[-1] == '\\' || (bind[-1] == '\ && bind[1] == '\))
7618.             bind = strchr(bind + 2, ',');
7619.     }
7620.     /* if a comma separator has been found, break off first binding from rest;
7621.        parse the rest and then handle this first one when recursion returns */
7622.     if (bind) {
7623.         *bind++ = '\0';
7624.         if (!parsebindings(bind))
7625.             ret = FALSE;
7626.     }
7627. 
7628.     /* parse a single binding: first split around : */
7629.     if (! (bind = strchr(bindings, ':')))
7630.         return FALSE; /* it's not a binding */
7631.     *bind++ = 0;
7632. 
7633.     bind = trimspaces(bind);
7634. 
7635.     for (i = 0; i < SIZE(mousebtn_names); i++)
7636.         if (!strcmp(bindings, mousebtn_names[i])) {
7637.             if (!bind_mousebtn(i + 1, bind)) {
7638.                 config_error_add("Error binding mouse button %i", i + 1);
7639.             } else {
7640.                 return ret;
7641.             }
7642.         }
7643. 
7644.     /* read the key to be bound */
7645.     key = txt2key(bindings);
7646.     if (!key) {
7647.         config_error_add("Unknown key binding key '%s'", bindings);
7648.         return FALSE;
7649.     }
7650. 
7651.     /* is it a special key? */
7652.     if (bind_specialkey(key, bind))
7653.         return ret;
7654. 
7655.     /* is it a menu command? */
7656.     for (i = 0; default_menu_cmd_info[i].name; i++) {
7657.         if (!strcmp(default_menu_cmd_info[i].name, bind)) {
7658.             if (illegal_menu_cmd_key(key)) {
7659.                 config_error_add("Bad menu key %s:%s", visctrl(key), bind);
7660.                 return FALSE;
7661.             } else {
7662.                 add_menu_cmd_alias((char) key, default_menu_cmd_info[i].cmd);
7663.             }
7664.             return ret;
7665.         }
7666.     }
7667. 
7668.     /* extended command? */
7669.     if (!bind_key(key, bind, TRUE)) {
7670.         config_error_add("Unknown key binding command '%s'", bind);
7671.         return FALSE;
7672.     }
7673.     return ret;
7674. }
7675. 
7676. static const struct {
7677.     const char *name;
7678.     xint8 msgtyp;
7679.     const char *descr;
7680. } msgtype_names[] = {
7681.     { "show", MSGTYP_NORMAL, "Show message normally" },
7682.     { "hide", MSGTYP_NOSHOW, "Hide message" },
7683.     { "noshow", MSGTYP_NOSHOW, NULL },
7684.     { "stop", MSGTYP_STOP, "Prompt for more after the message" },
7685.     { "more", MSGTYP_STOP, NULL },
7686.     { "norep", MSGTYP_NOREP, "Do not repeat the message" }
7687. };
7688. 
7689. staticfn const char *
7690. msgtype2name(int typ)
7691. {
7692.     int i;
7693. 
7694.     for (i = 0; i < SIZE(msgtype_names); i++)
7695.         if (msgtype_names[i].descr && msgtype_names[i].msgtyp == typ)
7696.             return msgtype_names[i].name;
7697.     return (char *) 0;
7698. }
7699. 
7700. staticfn int
7701. query_msgtype(void)
7702. {
7703.     winid tmpwin;
7704.     anything any;
7705.     int i, pick_cnt;
7706.     menu_item *picks = (menu_item *) 0;
7707.     int clr = NO_COLOR;
7708. 
7709.     tmpwin = create_nhwindow(NHW_MENU);
7710.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
7711.     any = cg.zeroany;
7712.     for (i = 0; i < SIZE(msgtype_names); i++)
7713.         if (msgtype_names[i].descr) {
7714.             any.a_int = msgtype_names[i].msgtyp + 1;
7715.             add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
7716.                      ATR_NONE, clr,
7717.                      msgtype_names[i].descr, MENU_ITEMFLAGS_NONE);
7718.         }
7719.     end_menu(tmpwin, "How to show the message");
7720.     pick_cnt = select_menu(tmpwin, PICK_ONE, &picks);
7721.     destroy_nhwindow(tmpwin);
7722.     if (pick_cnt > 0) {
7723.         i = picks->item.a_int - 1;
7724.         free((genericptr_t) picks);
7725.         return i;
7726.     }
7727.     return -1;
7728. }
7729. 
7730. staticfn boolean
7731. msgtype_add(int typ, char *pattern)
7732. {
7733.     static const char *const re_error = "MSGTYPE regex error";
7734.     struct plinemsg_type *tmp = (struct plinemsg_type *) alloc(sizeof *tmp);
7735. 
7736.     tmp->msgtype = typ;
7737.     tmp->regex = regex_init();
7738.     /* test_regex_pattern() has already validated this regexp but parsing
7739.        it again could conceivably run out of memory */
7740.     if (!regex_compile(pattern, tmp->regex)) {
7741.         char errbuf[BUFSZ];
7742.         char *re_error_desc = regex_error_desc(tmp->regex, errbuf);
7743. 
7744.         /* free first in case reason for failure was insufficient memory */
7745.         regex_free(tmp->regex);
7746.         free((genericptr_t) tmp);
7747.         config_error_add("%s: %s", re_error, re_error_desc);
7748.         return FALSE;
7749.     }
7750.     tmp->pattern = dupstr(pattern);
7751.     tmp->next = gp.plinemsg_types;
7752.     gp.plinemsg_types = tmp;
7753.     return TRUE;
7754. }
7755. 
7756. void
7757. msgtype_free(void)
7758. {
7759.     struct plinemsg_type *tmp, *tmp2 = 0;
7760. 
7761.     for (tmp = gp.plinemsg_types; tmp; tmp = tmp2) {
7762.         tmp2 = tmp->next;
7763.         free((genericptr_t) tmp->pattern);
7764.         regex_free(tmp->regex);
7765.         tmp->regex = 0;
7766.         free((genericptr_t) tmp);
7767.     }
7768.     gp.plinemsg_types = (struct plinemsg_type *) 0;
7769. }
7770. 
7771. staticfn void
7772. free_one_msgtype(int idx) /* 0 .. */
7773. {
7774.     struct plinemsg_type *tmp = gp.plinemsg_types;
7775.     struct plinemsg_type *prev = NULL;
7776. 
7777.     while (tmp) {
7778.         if (idx == 0) {
7779.             struct plinemsg_type *next = tmp->next;
7780. 
7781.             regex_free(tmp->regex);
7782.             free((genericptr_t) tmp->pattern);
7783.             free((genericptr_t) tmp);
7784.             if (prev)
7785.                 prev->next = next;
7786.             else
7787.                 gp.plinemsg_types = next;
7788.             return;
7789.         }
7790.         idx--;
7791.         prev = tmp;
7792.         tmp = tmp->next;
7793.     }
7794. }
7795. 
7796. int
7797. msgtype_type(const char *msg,
7798.              boolean norepeat) /* called from Norep(via pline) */
7799. {
7800.     struct plinemsg_type *tmp = gp.plinemsg_types;
7801. 
7802.     while (tmp) {
7803.         /* we don't exclude entries with negative msgtype values
7804.            because then the msg might end up matching a later pattern */
7805.         if (regex_match(msg, tmp->regex))
7806.             return tmp->msgtype;
7807.         tmp = tmp->next;
7808.     }
7809.     return norepeat ? MSGTYP_NOREP : MSGTYP_NORMAL;
7810. }
7811. 
7812. /* negate one or more types of messages so that their type handling will
7813.    be disabled or re-enabled; MSGTYPE_NORMAL (value 0) is not affected */
7814. void
7815. hide_unhide_msgtypes(boolean hide, int hide_mask)
7816. {
7817.     struct plinemsg_type *tmp;
7818.     int mt;
7819. 
7820.     /* negative msgtype value won't be recognized by pline, so does nothing */
7821.     for (tmp = gp.plinemsg_types; tmp; tmp = tmp->next) {
7822.         mt = tmp->msgtype;
7823.         if (!hide)
7824.             mt = -mt; /* unhide: negate negative, yielding positive */
7825.         if (mt > 0 && ((1 << mt) & hide_mask))
7826.             tmp->msgtype = -tmp->msgtype;
7827.     }
7828. }
7829. 
7830. staticfn int
7831. msgtype_count(void)
7832. {
7833.     int c = 0;
7834.     struct plinemsg_type *tmp = gp.plinemsg_types;
7835. 
7836.     while (tmp) {
7837.         c++;
7838.         tmp = tmp->next;
7839.     }
7840.     return c;
7841. }
7842. 
7843. boolean
7844. msgtype_parse_add(char *str)
7845. {
7846.     char pattern[256];
7847.     char msgtype[11];
7848. 
7849.     if (sscanf(str, "%10s \"%255[^\"]\"", msgtype, pattern) == 2) {
7850.         int typ = -1;
7851.         int i;
7852. 
7853.         for (i = 0; i < SIZE(msgtype_names); i++)
7854.             if (str_start_is(msgtype_names[i].name, msgtype, TRUE)) {
7855.                 typ = msgtype_names[i].msgtyp;
7856.                 break;
7857.             }
7858.         if (typ != -1)
7859.             return msgtype_add(typ, pattern);
7860.         else
7861.             config_error_add("Unknown message type '%s'", msgtype);
7862.     } else {
7863.         config_error_add("Malformed MSGTYPE");
7864.     }
7865.     return FALSE;
7866. }
7867. 
7868. /* parse 'str' as a regular expression to check whether it's valid;
7869.    compiled regexp gets thrown away regardless of the outcome */
7870. staticfn boolean
7871. test_regex_pattern(const char *str, const char *errmsg)
7872. {
7873.     static const char def_errmsg[] = "NHregex error";
7874.     struct nhregex *match;
7875.     char *re_error_desc, errbuf[BUFSZ];
7876.     boolean retval;
7877. 
7878.     if (!str)
7879.         return FALSE;
7880.     if (!errmsg)
7881.         errmsg = def_errmsg;
7882. 
7883.     match = regex_init();
7884.     if (!match) {
7885.         config_error_add("%s", errmsg);
7886.         return FALSE;
7887.     }
7888. 
7889.     retval = regex_compile(str, match);
7890.     /* get potential error message before freeing regexp and free regexp
7891.        before issuing message in case the error is "ran out of memory"
7892.        since message delivery might need to allocate some memory */
7893.     re_error_desc = !retval ? regex_error_desc(match, errbuf) : 0;
7894.     /* discard regexp; caller will re-parse it after validating other stuff */
7895.     regex_free(match);
7896.     /* if returning failure, tell player */
7897.     if (!retval)
7898.         config_error_add("%s: %s", errmsg, re_error_desc);
7899. 
7900.     return retval;
7901. }
7902. 
7903. /* parse 'role' or 'race' or 'gender' or 'alignment' */
7904. staticfn boolean
7905. parse_role_opt(
7906.     int optidx,
7907.     boolean negated,
7908.     const char *fullname,
7909.     char *opts,
7910.     char **opp)
7911. {
7912.     static char neg_opt[] = "!"; /* not 'const' but never modified */
7913.     char *preval, *op;
7914.     int which = (optidx == opt_role) ? RS_ROLE
7915.                 : (optidx == opt_race) ? RS_RACE
7916.                   : (optidx == opt_gender) ? RS_GENDER
7917.                     : (optidx == opt_alignment) ? RS_ALGNMNT
7918.                       : RS_filter; /* none of the above */
7919.     boolean ok = FALSE;
7920. 
7921.     /*
7922.      * Accepts multiple forms
7923.      *  role:priest       -- play as priest
7924.      *  race:!orc         -- any race other than orc
7925.      *  role:!cav !mon    -- any role other than caveman/cavewoman or monk
7926.      *  !role:tour        -- any role other than tourist
7927.      *  !role:tou rog wiz -- any role other than tourist or rogue or wizard
7928.      * TODO: add support for
7929.      *  role:arc bar kni  -- only role archeologist or barbarian or knight
7930.      * Rejected:
7931.      *  role:sam !val     -+ invalid; need either positive or negative subset
7932.      *  !role:!sam        +- not a mixture of the two and not dual negation.
7933.      */
7934.     if ((op = string_for_env_opt(fullname, opts, FALSE)) != empty_optstr) {
7935.         char *sp;
7936.         boolean val_negated, prev_negated = FALSE, first = TRUE;
7937. 
7938.         mungspaces(op);
7939.         while (*op) {
7940.             if (*op == ' ')
7941.                 ++op;
7942.             val_negated = FALSE;
7943.             while (*op == '!' || !strncmpi(op, "no", 2)) {
7944.                 val_negated = !val_negated;
7945.                 op += (*op == '!') ? 1 : (op[2] != '-') ? 2 : 3;
7946.             }
7947.             if (!*op || *op == ' ') {
7948.                 config_error_add("Negated nothing for '%s'", fullname);
7949.                 return FALSE;
7950.             }
7951.             if (!first) {
7952.                 if ((val_negated ^ prev_negated)
7953.                     || (negated && val_negated)) {
7954.                     config_error_add("Invalid mixed negation for '%s%s'",
7955.                                      negated ? "!" : "", fullname);
7956.                     return FALSE;
7957.                 } else if (!negated && !val_negated) {
7958.                     config_error_add(
7959.                     "Multiple role values only allowed when list is negated");
7960.                     return FALSE;
7961.                 }
7962.             }
7963.             first = FALSE;
7964.             prev_negated = val_negated;
7965. 
7966.             /* hide rest of list, if any */
7967.             sp = strchr(op, ' ');
7968.             if (sp)
7969.                 *sp = '\0';
7970. 
7971.             preval = getoptstr(optidx, go.opt_phase);
7972.             if (val_negated || negated) {
7973.                 char negbuf[BUFSZ];
7974. 
7975.                 /* for negative value, clear filter if there is a prior
7976.                    value from a different phase; for same phase, duplicates
7977.                    are allowed and setrolefilter() merges them */
7978.                 if (!preval || *preval != '!')
7979.                     clearrolefilter(which);
7980.                 if (!setrolefilter(op)) {
7981.                     config_error_add("Invalid %s '%s'", fullname, op);
7982.                     return FALSE;
7983.                 }
7984.                 saveoptstr(optidx, rolefilterstring(negbuf, which));
7985.                 *opp = neg_opt;
7986.             } else {
7987.                 /* for positive value, allow duplicate if prior value
7988.                    was a negative one or came from a different phase;
7989.                    reject if prior value was positive and from same phase */
7990.                 if (duplicate) {
7991.                     if (preval && *preval == '!') {
7992.                         complain_about_duplicate(optidx);
7993.                         return FALSE;
7994.                     }
7995.                 }
7996.                 /* save raw string value; caller will validate it and
7997.                    if it's ok, replace it with canonical form */
7998.                 saveoptstr(optidx, op);
7999.                 *opp = op;
8000.                 /*ok = TRUE; // redundant*/
8001.                 /* don't return yet; value might be a list that follows
8002.                    this with something else which might make it invalid */
8003.             }
8004. 
8005.             if (sp) {
8006.                 *sp = ' ';
8007.                 op = sp + 1;
8008.             } else {
8009.                 op += strlen(op); /* break; */
8010.             }
8011.         }
8012.         /* '!ok' without config_error_add() implies a valid negation */
8013.         ok = TRUE;
8014.     }
8015.     return ok;
8016. }
8017. 
8018. /* fetch a saved role|race|gender|alignment value suitable for writing into
8019.    a new run-time config file */
8020. staticfn char *
8021. get_cnf_role_opt(int optidx)
8022. {
8023.     int phase;
8024.     char *op = 0;
8025. 
8026.     for (phase = num_opt_phases - 1; phase >= 0 && !op; --phase) {
8027.         if (phase == cmdline_opt || phase == environ_opt
8028.             || phase == builtin_opt)
8029.             continue;
8030.         op = getoptstr(optidx, phase);
8031.     }
8032.     return op;
8033. }
8034. 
8035. /* Check if character c is illegal as a menu command key */
8036. staticfn boolean
8037. illegal_menu_cmd_key(uchar c)
8038. {
8039.     if (c == 0 || c == '\r' || c == '\n' || c == '\033' || c == ' '
8040.         || digit((char) c) || (letter((char) c) && c != '@')) {
8041.         config_error_add("Reserved menu command key '%s'", visctrl((char) c));
8042.         return TRUE;
8043.     } else { /* reject default object class symbols */
8044.         int j;
8045. 
8046.         for (j = 1; j < MAXOCLASSES; j++)
8047.             if (c == (uchar) def_oc_syms[j].sym) {
8048.                 config_error_add("Menu command key '%s' is an object class",
8049.                                  visctrl((char) c));
8050.                 return TRUE;
8051.             }
8052.     }
8053.     return FALSE;
8054. }
8055. 
8056. 
8057. /*
8058.  * Convert the given string of object classes to a string of default object
8059.  * symbols.
8060.  */
8061. void
8062. oc_to_str(char *src, char *dest)
8063. {
8064.     int i;
8065. 
8066.     while ((i = (int) *src++) != 0) {
8067.         if (i < 0 || i >= MAXOCLASSES)
8068.             impossible("oc_to_str:  illegal object class %d", i);
8069.         else
8070.             *dest++ = def_oc_syms[i].sym;
8071.     }
8072.     *dest = '\0';
8073. }
8074. 
8075. /*
8076.  * Add the given mapping to the menu command map list.  Always keep the
8077.  * maps valid C strings.
8078.  */
8079. void
8080. add_menu_cmd_alias(char from_ch, char to_ch)
8081. {
8082.     if (gn.n_menu_mapped >= MAX_MENU_MAPPED_CMDS) {
8083.         pline("out of menu map space.");
8084.     } else {
8085.         gm.mapped_menu_cmds[gn.n_menu_mapped] = from_ch;
8086.         gm.mapped_menu_op[gn.n_menu_mapped] = to_ch;
8087.         gn.n_menu_mapped++;
8088.         gm.mapped_menu_cmds[gn.n_menu_mapped] = '\0';
8089.         gm.mapped_menu_op[gn.n_menu_mapped] = '\0';
8090.     }
8091. }
8092. 
8093. char
8094. get_menu_cmd_key(char ch)
8095. {
8096.     char *found = strchr(gm.mapped_menu_op, ch);
8097. 
8098.     if (found) {
8099.         int idx = (int) (found - gm.mapped_menu_op);
8100. 
8101.         ch = gm.mapped_menu_cmds[idx];
8102.     }
8103.     return ch;
8104. }
8105. 
8106. /*
8107.  * Map the given character to its corresponding menu command.  If it
8108.  * doesn't match anything, just return the original.
8109.  */
8110. char
8111. map_menu_cmd(char ch)
8112. {
8113.     char *found = strchr(gm.mapped_menu_cmds, ch);
8114. 
8115.     if (found) {
8116.         int idx = (int) (found - gm.mapped_menu_cmds);
8117. 
8118.         ch = gm.mapped_menu_op[idx];
8119.     }
8120.     return ch;
8121. }
8122. 
8123. /* get keystrokes that are used for menu scrolling operations which apply;
8124.    printable: for use in a prompt, non-printable: for yn_function() choices */
8125. char *
8126. collect_menu_keys(
8127.     char *outbuf,        /* at least big enough for 6 "M-^X" sequences +'\0'*/
8128.     unsigned scrollmask, /* 1: backwards, "^<"; 2: forwards, ">|";
8129.                           * 4: left, "{";       8: right, "}"; */
8130.     boolean printable)   /* False: output is string of raw characters,
8131.                           * True: output is a string of visctrl() sequences;
8132.                           * matters iff user has mapped any menu scrolling
8133.                           * commands to control or meta characters */
8134. {
8135.     struct menuscrollinfo {
8136.         char cmdkey;
8137.         uchar maskindx;
8138.     };
8139.     static const struct menuscrollinfo scroll_keys[] = {
8140.         { MENU_FIRST_PAGE,    1 },
8141.         { MENU_PREVIOUS_PAGE, 1 },
8142.         { MENU_NEXT_PAGE,     2 },
8143.         { MENU_LAST_PAGE,     2 },
8144.         { MENU_SHIFT_LEFT,    4 },
8145.         { MENU_SHIFT_RIGHT,   8 },
8146.     };
8147.     int i;
8148. 
8149.     outbuf[0] = '\0';
8150.     for (i = 0; i < SIZE(scroll_keys); ++i) {
8151.         if (scrollmask & scroll_keys[i].maskindx) {
8152.             char c = get_menu_cmd_key(scroll_keys[i].cmdkey);
8153. 
8154.             if (printable)
8155.                 Strcat(outbuf, visctrl(c));
8156.             else
8157.                 (void) strkitten(outbuf, c);
8158.         }
8159.     }
8160.     return outbuf;
8161. }
8162. 
8163. /* Returns the fid of the fruit type; if that type already exists, it
8164.  * returns the fid of that one; if it does not exist, it adds a new fruit
8165.  * type to the chain and returns the new one.
8166.  * If replace_fruit is sent in, replace the fruit in the chain rather than
8167.  * adding a new entry--for user specified fruits only.
8168.  */
8169. int
8170. fruitadd(char *str, struct fruit *replace_fruit)
8171. {
8172.     int i;
8173.     struct fruit *f;
8174.     int highest_fruit_id = 0, globpfx;
8175.     char buf[PL_FSIZ], altname[PL_FSIZ];
8176.     boolean user_specified = (str == svp.pl_fruit);
8177.     /* if not user-specified, then it's a fruit name for a fruit on
8178.      * a bones level or from orctown raider's loot...
8179.      */
8180. 
8181.     /* Note: every fruit has an id (kept in obj->spe) of at least 1;
8182.      * 0 is an error.
8183.      */
8184.     if (user_specified) {
8185.         boolean found = FALSE, numeric = FALSE;
8186. 
8187.         /* force fruit to be singular; this handling is not
8188.            needed--or wanted--for fruits from bones because
8189.            they already received it in their original game;
8190.            str==pl_fruit but makesingular() creates a copy
8191.            so we need to copy that back into pl_fruit */
8192.         nmcpy(svp.pl_fruit, makesingular(str), PL_FSIZ);
8193. 
8194.         /* disallow naming after other foods (since it'd be impossible
8195.          * to tell the difference); globs might have a size prefix which
8196.          * needs to be skipped in order to match the object type name
8197.          */
8198.         globpfx = (!strncmp(svp.pl_fruit, "small ", 6)
8199.                    || !strncmp(svp.pl_fruit, "large ", 6)) ? 6
8200.                   : (!strncmp(svp.pl_fruit, "medium ", 7)) ? 7
8201.                     : (!strncmp(svp.pl_fruit, "very large ", 11)) ? 11
8202.                       : 0;
8203.         for (i = svb.bases[FOOD_CLASS]; objects[i].oc_class == FOOD_CLASS;
8204.              i++) {
8205.             if (!strcmp(OBJ_NAME(objects[i]), svp.pl_fruit)
8206.                 || (globpfx > 0 && !strcmp(OBJ_NAME(objects[i]),
8207.                                            &svp.pl_fruit[globpfx]))) {
8208.                 found = TRUE;
8209.                 break;
8210.             }
8211.         }
8212.         if (!found) {
8213.             char *c;
8214. 
8215.             for (c = svp.pl_fruit; *c >= '0' && *c <= '9'; c++)
8216.                 continue;
8217.             if (!*c || isspace((uchar) *c))
8218.                 numeric = TRUE;
8219.         }
8220.         if (found || numeric
8221.             /* these checks for applying food attributes to actual items
8222.                are case sensitive; "glob of foo" is caught by 'found'
8223.                if 'foo' is a valid glob; when not valid, allow it as-is */
8224.             || !strncmp(svp.pl_fruit, "cursed ", 7)
8225.             || !strncmp(svp.pl_fruit, "uncursed ", 9)
8226.             || !strncmp(svp.pl_fruit, "blessed ", 8)
8227.             || !strncmp(svp.pl_fruit, "partly eaten ", 13)
8228.             || (!strncmp(svp.pl_fruit, "tin of ", 7)
8229.                 && (!strcmp(svp.pl_fruit + 7, "spinach")
8230.                     || ismnum(name_to_mon(svp.pl_fruit + 7, (int *) 0))))
8231.             || !strcmp(svp.pl_fruit, "empty tin")
8232.             || (!strcmp(svp.pl_fruit, "glob")
8233.                 || (globpfx > 0 && !strcmp("glob", &svp.pl_fruit[globpfx])))
8234.             || ((str_end_is(svp.pl_fruit, " corpse")
8235.                  || str_end_is(svp.pl_fruit, " egg"))
8236.                 && ismnum(name_to_mon(svp.pl_fruit, (int *) 0)))) {
8237.             Strcpy(buf, svp.pl_fruit);
8238.             Strcpy(svp.pl_fruit, "candied ");
8239.             nmcpy(svp.pl_fruit + 8, buf, PL_FSIZ - 8);
8240.         }
8241.         *altname = '\0';
8242.         /* This flag indicates that a fruit has been made since the
8243.          * last time the user set the fruit.  If it hasn't, we can
8244.          * safely overwrite the current fruit, preventing the user from
8245.          * setting many fruits in a row and overflowing.
8246.          * Possible expansion: check for specific fruit IDs, not for
8247.          * any fruit.
8248.          */
8249.         flags.made_fruit = FALSE;
8250.         if (replace_fruit) {
8251.             /* replace_fruit is already part of the fruit chain;
8252.                update it in place rather than looking it up again */
8253.             f = replace_fruit;
8254.             copynchars(f->fname, svp.pl_fruit, PL_FSIZ - 1);
8255.             goto nonew;
8256.         }
8257.     } else {
8258.         /* not user_supplied, so assumed to be from bones (or orc gang) */
8259.         copynchars(altname, str, PL_FSIZ - 1);
8260.         sanitize_name(altname);
8261.         flags.made_fruit = TRUE; /* for safety.  Any fruit name added from a
8262.                                   * bones level should exist anyway. */
8263.     }
8264.     f = fruit_from_name(*altname ? altname : str, FALSE, &highest_fruit_id);
8265.     if (f)
8266.         goto nonew;
8267. 
8268.     /* Maximum number of named fruits is 127, even if obj->spe can
8269.        handle bigger values.  If adding another fruit would overflow,
8270.        use a random fruit instead... we've got a lot to choose from.
8271.        current_fruit remains as is. */
8272.     if (highest_fruit_id >= 127)
8273.         return rnd(127);
8274. 
8275.     f = newfruit();
8276.     (void) memset((genericptr_t) f, 0, sizeof (struct fruit));
8277.     copynchars(f->fname, *altname ? altname : str, PL_FSIZ - 1);
8278.     f->fid = ++highest_fruit_id;
8279.     /* we used to go out of our way to add it at the end of the list,
8280.        but the order is arbitrary so use simpler insertion at start */
8281.     f->nextf = gf.ffruit;
8282.     gf.ffruit = f;
8283.  nonew:
8284.     if (user_specified)
8285.         svc.context.current_fruit = f->fid;
8286.     return f->fid;
8287. }
8288. 
8289. /*
8290.  **********************************
8291.  *
8292.  * Option-setting, menus,
8293.  *  displaying option values
8294.  *
8295.  **********************************
8296.  */
8297. 
8298. 
8299. DISABLE_WARNING_FORMAT_NONLITERAL   /* RESTORE is after show_menucontrols() */
8300. 
8301. staticfn int
8302. optfn_o_autopickup_exceptions(
8303.     int optidx UNUSED, int req, boolean negated UNUSED,
8304.     char *opts, char *op UNUSED)
8305. {
8306.     if (req == do_init) {
8307.         return optn_ok;
8308.     }
8309.     if (req == do_set) {
8310.     }
8311.     if (req == get_val || req == get_cnf_val) {
8312.         if (!opts)
8313.             return optn_err;
8314.         Sprintf(opts, n_currently_set, count_apes());
8315.         return optn_ok;
8316.     }
8317.     if (req == do_handler) {
8318.         return handler_autopickup_exception();
8319.     }
8320.     return optn_ok;
8321. }
8322. 
8323. staticfn int
8324. optfn_o_bind_keys(
8325.     int optidx UNUSED, int req, boolean negated UNUSED,
8326.     char *opts, char *op UNUSED)
8327. {
8328.     if (req == do_init) {
8329.         return optn_ok;
8330.     }
8331.     if (req == do_set) {
8332.     }
8333.     if (req == get_val || req == get_cnf_val) {
8334.         if (!opts)
8335.             return optn_err;
8336.         Sprintf(opts, n_currently_set, count_bind_keys());
8337.         return optn_ok;
8338.     }
8339.     if (req == do_handler) {
8340.         handler_rebind_keys();
8341.     }
8342.     return optn_ok;
8343. }
8344. 
8345. staticfn int
8346. optfn_o_autocomplete(
8347.     int optidx UNUSED, int req, boolean negated UNUSED,
8348.     char *opts, char *op UNUSED)
8349. {
8350.     if (req == do_init) {
8351.         return optn_ok;
8352.     }
8353.     if (req == do_set) {
8354.     }
8355.     if (req == get_val || req == get_cnf_val) {
8356.         if (!opts)
8357.             return optn_err;
8358.         Sprintf(opts, n_currently_set, count_autocompletions());
8359.         return optn_ok;
8360.     }
8361.     if (req == do_handler) {
8362.         handler_change_autocompletions();
8363.     }
8364.     return optn_ok;
8365. }
8366. 
8367. staticfn int
8368. optfn_o_menu_colors(int optidx UNUSED, int req, boolean negated UNUSED,
8369.               char *opts, char *op UNUSED)
8370. {
8371.     if (req == do_init) {
8372.         return optn_ok;
8373.     }
8374.     if (req == do_set) {
8375.     }
8376.     if (req == get_val || req == get_cnf_val) {
8377.         if (!opts)
8378.             return optn_err;
8379.         Sprintf(opts, n_currently_set, count_menucolors());
8380.         return optn_ok;
8381.     }
8382.     if (req == do_handler) {
8383.         return handler_menu_colors();
8384.     }
8385.     return optn_ok;
8386. }
8387. 
8388. staticfn int
8389. optfn_o_message_types(
8390.     int optidx UNUSED,
8391.     int req,
8392.     boolean negated UNUSED,
8393.     char *opts,
8394.     char *op UNUSED)
8395. {
8396.     if (req == do_init) {
8397.         return optn_ok;
8398.     }
8399.     if (req == do_set) {
8400.     }
8401.     if (req == get_val || req == get_cnf_val) {
8402.         if (!opts)
8403.             return optn_err;
8404.         Sprintf(opts, n_currently_set, msgtype_count());
8405.         return optn_ok;
8406.     }
8407.     if (req == do_handler) {
8408.         return handler_msgtype();
8409.     }
8410.     return optn_ok;
8411. }
8412. 
8413. staticfn int
8414. optfn_o_status_cond(
8415.     int optidx UNUSED,
8416.     int req,
8417.     boolean negated UNUSED,
8418.     char *opts,
8419.     char *op UNUSED)
8420. {
8421.     if (req == do_init) {
8422.         return optn_ok;
8423.     }
8424.     if (req == do_set) {
8425.         ; /* setting status condition options goes through pfxfn_cond_() */
8426.     }
8427.     if (req == get_val) {
8428.         if (!opts) /* opts[] is used as an output argument */
8429.             return optn_err;
8430.         Sprintf(opts, n_currently_set, count_cond());
8431.         return optn_ok;
8432.     }
8433.     if (req == get_cnf_val) {
8434.         ; /* handled inline by all_options_strbuf() via all_options_conds() */
8435.     }
8436.     if (req == do_handler) {
8437.         if (cond_menu())
8438.             opt_set_in_config[pfx_cond_] = TRUE;
8439.         return optn_ok;
8440.     }
8441.     return optn_ok;
8442. }
8443. 
8444. #ifdef STATUS_HILITES
8445. staticfn int
8446. optfn_o_status_hilites(
8447.     int optidx UNUSED,
8448.     int req,
8449.     boolean negated UNUSED,
8450.     char *opts,
8451.     char *op UNUSED)
8452. {
8453.     if (req == do_init) {
8454.         return optn_ok;
8455.     }
8456.     if (req == do_set) {
8457.     }
8458.     if (req == get_val || req == get_cnf_val) {
8459.         if (!opts)
8460.             return optn_err;
8461.         Sprintf(opts, n_currently_set, count_status_hilites());
8462.         return optn_ok;
8463.     }
8464.     if (req == do_handler) {
8465.         if (!status_hilite_menu()) {
8466.             return optn_err; /*pline("Bad status hilite(s) specified.");*/
8467.         } else {
8468.             if (wc2_supported("hilite_status"))
8469.                 preference_update("hilite_status");
8470.         }
8471.         return optn_ok;
8472.     }
8473.     return optn_ok;
8474. }
8475. #endif /*STATUS_HILITES*/
8476. 
8477. /* Get string value of configuration option.
8478.  * Currently handles only boolean and compound options.
8479.  */
8480. char *
8481. get_option_value(const char *optname, boolean cnfvalid)
8482. {
8483.     static char retbuf[BUFSZ];
8484.     boolean *bool_p;
8485.     int i;
8486. 
8487.     for (i = 0; allopt[i].name != 0; i++)
8488.         if (!strcmp(optname, allopt[i].name)) {
8489.             if (allopt[i].opttyp == BoolOpt
8490.                 && (bool_p = allopt[i].addr) != 0) {
8491.                 Sprintf(retbuf, "%s", *bool_p ? "true" : "false");
8492.                 return retbuf;
8493.             } else if (allopt[i].opttyp == CompOpt && allopt[i].optfn) {
8494.                 int reslt = optn_err;
8495. 
8496.                 reslt = (*allopt[i].optfn)(allopt[i].idx,
8497.                                            cnfvalid ? get_cnf_val : get_val,
8498.                                            FALSE, retbuf, empty_optstr);
8499.                 if (reslt == optn_ok && retbuf[0])
8500.                     return retbuf;
8501.                 return (char *) 0;
8502.             }
8503.         }
8504.     return (char *) 0;
8505. }
8506. 
8507. staticfn unsigned int
8508. longest_option_name(int startpass, int endpass)
8509. {
8510.     /* spin through the options to find the longest name */
8511.     unsigned longest_name_len = 0;
8512.     int i, pass, optflags;
8513.     const char *name;
8514. 
8515.     for (pass = 0; pass < 2; pass++)
8516.         for (i = 0; (name = allopt[i].name) != 0; i++) {
8517.             if (pass == 0
8518.                 && (allopt[i].opttyp != BoolOpt || !allopt[i].addr))
8519.                 continue;
8520.             optflags = allopt[i].setwhere;
8521.             if (optflags < startpass || optflags > endpass)
8522.                 continue;
8523.             if ((is_wc_option(name) && !wc_supported(name))
8524.                 || (is_wc2_option(name) && !wc2_supported(name)))
8525.                 continue;
8526. 
8527.             unsigned len = Strlen(name);
8528.             if (len > longest_name_len)
8529.                 longest_name_len = len;
8530.         }
8531.     return longest_name_len;
8532. }
8533. 
8534. /* guts of doset_simple(); called repeatedly until no choice is made */
8535. staticfn int
8536. doset_simple_menu(void)
8537. {
8538.     /* unlike doset()'s fmtstr, there is no leading %s for indentation */
8539.     static const char fmtstr_tab_doset_simple[] = "%s\t[%s]";
8540.     char fmtstr_doset_simple[sizeof "%-15s [%s]   "];
8541.     menu_item *pick_list;
8542.     boolean *bool_p;
8543.     const char *name, *fmtstr;
8544.     char buf[BUFSZ], buf2[BUFSZ], abuf[BUFSZ];
8545.     winid tmpwin;
8546.     anything any;
8547.     enum OptSection section;
8548.     int i, k, pick_cnt, reslt;
8549.     boolean toggled_help = FALSE;
8550. 
8551.     /* we do this each time we're called instead of once in doset_simple()
8552.        in case 'menu_tab_sep' ever gets included in the simple menu so
8553.        becomes subject to being changed while doset_simple() is running */
8554.     if (!iflags.menu_tab_sep)
8555.         Sprintf(fmtstr_doset_simple, "%%-%us [%%s]",
8556.                 longest_option_name(set_gameview, set_in_game));
8557.     else
8558.         Strcpy(fmtstr_doset_simple, fmtstr_tab_doset_simple);
8559.     fmtstr = fmtstr_doset_simple;
8560. 
8561.  redo_opt_help:
8562.     tmpwin = create_nhwindow(NHW_MENU);
8563.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
8564. 
8565.     /* when showing 'help', also describe how to run full doset() */
8566.     if (gs.simple_options_help) {
8567.         /* we could look up whether #optionsfull has been bound to a key
8568.            and show that, or whether #reqmenu and #options are both still
8569.            bound to keys and show those, but if meta keys are involved
8570.            the player might not know how to type them; keep this simple */
8571.         Strcpy(buf, "Use command '#optionsfull'"
8572.                     " to get the complete options list.");
8573.         add_menu_str(tmpwin, buf);
8574.     }
8575.     any = cg.zeroany;
8576.     any.a_int = -2 + 1;
8577.     add_menu(tmpwin, &nul_glyphinfo, &any, '?', 0, ATR_NONE, NO_COLOR,
8578.              gs.simple_options_help ? "hide help" : "show help",
8579.              MENU_ITEMFLAGS_NONE);
8580. 
8581.     for (section = OptS_General; section < OptS_Advanced; section++) {
8582.         any = cg.zeroany;
8583.         add_menu_str(tmpwin, "");
8584.         Sprintf(buf, " %-30s ", OptS_type[section]);
8585.         add_menu_heading(tmpwin, buf);
8586.         for (i = 0; (name = allopt[i].name) != 0; i++) {
8587.             if (allopt[i].section != section)
8588.                 continue;
8589.             if ((is_wc_option(name) && !wc_supported(name))
8590.                 || (is_wc2_option(name) && !wc2_supported(name)))
8591.                 continue;
8592. 
8593.             any.a_int = i + 1;
8594.             switch (allopt[i].opttyp) {
8595.             case BoolOpt:
8596.                 bool_p = allopt[i].addr;
8597.                 if (!bool_p)
8598.                     continue;
8599.                 if (iflags.wc_tiled_map && allopt[i].idx == opt_color)
8600.                     continue;
8601.                 Sprintf(buf, fmtstr, name, *bool_p ? "X" : " ");
8602.                 break;
8603.             case CompOpt:
8604.             case OthrOpt:
8605.                     k = i;
8606.                     if (allopt[i].optfn == optfn_symset
8607.                         && Is_rogue_level(&u.uz)) {
8608.                         k = opt_roguesymset;
8609.                         name = allopt[k].name;
8610.                         any.a_int = k + 1;
8611.                     }
8612. 
8613.                     buf2[0] = '\0';
8614.                     reslt = optn_err;
8615.                     if (allopt[k].optfn)
8616.                         reslt = (*allopt[k].optfn)(allopt[k].idx, get_val,
8617.                                                    FALSE, buf2, empty_optstr);
8618.                     Sprintf(buf, fmtstr, name,
8619.                             ((reslt == optn_ok && buf2[0])
8620.                              ? (const char *) buf2 : "unknown"));
8621.                 break;
8622.             default:
8623.                 Sprintf(buf, "ERROR");
8624.                 break;
8625.             }
8626.             /* pickup_types is separated from autopickup due to the
8627.                spelling of their names; emphasize what it means */
8628.             if (allopt[i].idx == opt_pickup_types
8629.                 || allopt[i].idx == opt_pickup_thrown
8630.                 || allopt[i].idx == opt_pickup_stolen
8631.                 || allopt[i].idx == opt_dropped_nopick)
8632.                 Strcat(buf, "  (for autopickup)");
8633.             add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
8634.                      ATR_NONE, NO_COLOR, buf, MENU_ITEMFLAGS_NONE);
8635.             if (gs.simple_options_help && allopt[i].descr) {
8636.                 Sprintf(buf, "    %s", allopt[i].descr);
8637.                 add_menu_str(tmpwin, buf);
8638.                 add_menu_str(tmpwin, "");
8639.             }
8640.         }
8641.     }
8642.     end_menu(tmpwin, "Options");
8643. 
8644.     go.opt_need_redraw = FALSE;
8645.     go.opt_need_glyph_reset = FALSE;
8646.     go.opt_reset_customcolors = FALSE;
8647.     go.opt_reset_customsymbols = FALSE;
8648.     go.opt_update_basic_palette = FALSE;
8649.     pick_cnt = select_menu(tmpwin, PICK_ONE, &pick_list);
8650.     /* note:  without the complication of a preselected entry, a PICK_ONE
8651.        menu returning pick_cnt > 0 implies exactly 1 */
8652.     if (pick_cnt > 0) {
8653.         k = pick_list[0].item.a_int - 1;
8654. 
8655.         abuf[0] = '\0';
8656.         if (k == -2) {
8657.             gs.simple_options_help = !gs.simple_options_help;
8658.             toggled_help = TRUE;
8659.         } else if (allopt[k].opttyp == BoolOpt) {
8660.             /* boolean option */
8661.             Sprintf(buf, "%s%s", *allopt[k].addr ? "!" : "", allopt[k].name);
8662.             (void) parseoptions(buf, FALSE, FALSE);
8663.         } else {
8664.             /* compound option */
8665.             if (allopt[k].has_handler && allopt[k].optfn) {
8666.                 reslt = (*allopt[k].optfn)(allopt[k].idx, do_handler, FALSE,
8667.                                            empty_optstr, empty_optstr);
8668.                 /* if player eventually saves options, include this one */
8669.                 if (reslt == optn_ok && allopt[k].idx != pfx_cond_)
8670.                     opt_set_in_config[k] = TRUE;
8671.             } else {
8672.                 Sprintf(buf, "Set %s to what?", allopt[k].name);
8673.                 getlin(buf, abuf);
8674.                 if (abuf[0] != '\033') { /* ESC */
8675.                     Sprintf(buf, "%s:", allopt[k].name);
8676.                     copynchars(eos(buf), abuf,
8677.                                (int) (sizeof buf - 1 - strlen(buf)));
8678.                     /* pass the buck */
8679.                     (void) parseoptions(buf, FALSE, FALSE);
8680.                 }
8681.                 /* Note: using ESC to not set a new value will still return
8682.                    'picked 1' to caller which will loop for another choice */
8683.             }
8684.         }
8685.         if (k >= 0 && abuf[0] != '\033'
8686.             && (wc_supported(allopt[k].name)
8687.                 || wc2_supported(allopt[k].name)))
8688.             preference_update(allopt[k].name);
8689. 
8690.         free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
8691.     }
8692.     /* tear down this instance of the menu; if pick_cnt is 1, caller
8693.        will immediately call us back to put up another instance */
8694.     destroy_nhwindow(tmpwin);
8695. 
8696.     if (toggled_help) {
8697.         toggled_help = FALSE;
8698.         goto redo_opt_help;
8699.     }
8700. 
8701.     return pick_cnt;
8702. }
8703. 
8704. /* #options - the user friendly version:  get one option from a subset of
8705.    the zillion choices, act upon it, and prompt for another */
8706. int
8707. doset_simple(void)
8708. {
8709.     int pickedone = 0;
8710.     boolean flush = FALSE;
8711. 
8712.     if (iflags.menu_requested) {
8713.         /* doset() checks for 'm' and calls doset_simple(); clear the
8714.            menu-requested flag to avoid doing that recursively */
8715.         iflags.menu_requested = FALSE;
8716.         return doset();
8717.     }
8718. 
8719.     go.opt_phase = play_opt;
8720.     /* select and change one option at a time, then reprocess the menu
8721.        with updated settings to offer chance for further change */
8722.     give_opt_msg = FALSE;
8723.     do {
8724.         pickedone = doset_simple_menu();
8725.         flush = go.opt_need_redraw;
8726. 
8727.         reset_needed_visuals();
8728.         if (flush) {
8729.             flush_screen(1);
8730.             flush = FALSE;
8731.         }
8732.     } while (pickedone > 0);
8733.     give_opt_msg = TRUE;
8734.     return ECMD_OK;
8735. }
8736. 
8737. staticfn const char *
8738. term_for_boolean(int idx, boolean *b)
8739. {
8740.     int i, f_t = (*b) ? 1: 0;
8741.     const char *boolean_term;
8742.     static const char *const booleanterms[2][num_terms] = {
8743.         { "false", "off", "disabled", "excluded from build" },
8744.         { "true", "on", "enabled", "included"},
8745.     };
8746. 
8747.     boolean_term = booleanterms[f_t][0];
8748.     i = (int) allopt[idx].termpref;
8749.     if (i > Term_False && i < num_terms && i < SIZE(booleanterms[0]))
8750.         boolean_term = booleanterms[f_t][i];
8751.     return boolean_term;
8752. }
8753. 
8754. #define HELP_IDX (SIZE(allopt))
8755. 
8756. /* the #optionsfull command */
8757. int
8758. doset(void) /* changing options via menu by Per Liboriussen */
8759. {
8760.     static const char fmtstr_tab_doset[] = "%s%s\t[%s]";
8761.     char fmtstr_doset[sizeof "%s%-15s [%s]   "];
8762.     char buf[BUFSZ];
8763.     const char *name, *indent;
8764.     int i = 0, pass, pick_cnt, pick_idx, opt_indx;
8765.     boolean *bool_p;
8766.     winid tmpwin;
8767.     anything any;
8768.     menu_item *pick_list;
8769.     int indexoffset, startpass, endpass;
8770.     boolean gavehelp = FALSE, skiphelp = !iflags.cmdassist;
8771.     int clr = NO_COLOR;
8772. 
8773.     if (iflags.menu_requested) {
8774.         /* doset_simple() checks for 'm' and calls doset(); clear the
8775.            menu-requested flag to avoid doing that recursively */
8776.         iflags.menu_requested = FALSE;
8777.         return doset_simple();
8778.     }
8779. 
8780.     go.opt_phase = play_opt;
8781.     /* if we offer '?' as a choice and it is the only thing chosen,
8782.        we'll end up coming back here after showing the explanatory text */
8783.  rerun:
8784.     tmpwin = create_nhwindow(NHW_MENU);
8785.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
8786. 
8787.     /* offer novices a chance to request helpful [sic] advice */
8788.     if (!skiphelp) {
8789.         /* help text surrounding '?' choice should have exactly one NULL */
8790.         static const char *const helptext[] = {
8791.             "For a brief explanation of how this works, type '?' to select",
8792.             "the next menu choice, then press <enter> or <return>.",
8793.             NULL, /* actual '?' menu entry gets inserted here */
8794.             ("[To suppress this menu help,"
8795.              " toggle off the 'cmdassist' option.]"),
8796.             "",
8797.         };
8798.         any = cg.zeroany;
8799.         for (i = 0; i < SIZE(helptext); ++i) {
8800.             if (helptext[i]) {
8801.                 Sprintf(buf, "%4s%.75s", "", helptext[i]);
8802.                 add_menu_str(tmpwin, buf);
8803.             } else {
8804.                 any.a_int = HELP_IDX + 1; /* handling pick_list subtracts 1 */
8805.                 add_menu(tmpwin, &nul_glyphinfo, &any, '?', '?', ATR_NONE,
8806.                          clr, "view help for options menu",
8807.                          MENU_ITEMFLAGS_SKIPINVERT);
8808.             }
8809.         }
8810.     }
8811. 
8812. #ifdef notyet /* SYSCF */
8813.     /* XXX I think this is still fragile.  Fixing initial/from_file and/or
8814.        changing the SET_* etc to bitmaps will let me make this better. */
8815.     if (wizard)
8816.         startpass = set_in_sysconf;
8817.     else
8818. #endif
8819.         startpass = set_gameview;
8820.     endpass = (wizard) ? set_wiznofuz : set_in_game;
8821. 
8822.     if (!iflags.menu_tab_sep)
8823.         /* initial "%s" is for indentation of non-selectable items */
8824.         Sprintf(fmtstr_doset, "%%s%%-%us [%%s]",
8825.                 longest_option_name(startpass, endpass));
8826.     else
8827.         Strcpy(fmtstr_doset, fmtstr_tab_doset);
8828. 
8829.     indexoffset = 1;
8830.     any = cg.zeroany;
8831.     add_menu_heading(tmpwin, "Booleans (selecting will toggle value):");
8832.     any.a_int = 0;
8833.     /* first list any other non-modifiable booleans, then modifiable ones */
8834.     for (pass = 0; pass <= 1; pass++)
8835.         for (i = 0; (name = allopt[i].name) != 0; i++)
8836.             if (allopt[i].opttyp == BoolOpt
8837.                 && (bool_p = allopt[i].addr) != 0
8838.                 && ((allopt[i].setwhere <= set_gameview && pass == 0)
8839.                     || (allopt[i].setwhere >= set_in_game && pass == 1))) {
8840.                 if (bool_p == &flags.female)
8841.                     continue; /* obsolete */
8842.                 if (allopt[i].setwhere == set_wizonly && !wizard)
8843.                     continue;
8844.                 if (allopt[i].setwhere == set_wiznofuz
8845.                     && (!wizard || iflags.debug_fuzzer))
8846.                     continue;
8847.                 if ((is_wc_option(name) && !wc_supported(name))
8848.                     || (is_wc2_option(name) && !wc2_supported(name)))
8849.                     continue;
8850. 
8851.                 any.a_int = (pass == 0) ? 0 : i + 1 + indexoffset;
8852.                 indent = (pass == 0 && !iflags.menu_tab_sep) ? "    " : "";
8853.                 Sprintf(buf, fmtstr_doset, indent,
8854.                         name, term_for_boolean(i, bool_p));
8855.                 if (pass == 0)
8856.                     enhance_menu_text(buf, sizeof buf, pass, bool_p,
8857.                                       &allopt[i]);
8858.                 add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
8859.                          ATR_NONE, clr, buf, MENU_ITEMFLAGS_SKIPINVERT);
8860.             }
8861. 
8862.     add_menu_str(tmpwin, "");
8863.     add_menu_heading(tmpwin,
8864.                      "Compounds (selecting will prompt for new value):");
8865. 
8866.     for (pass = startpass; pass <= endpass; pass++)
8867.         for (i = 0; (name = allopt[i].name) != 0; i++) {
8868.             if (allopt[i].opttyp != CompOpt)
8869.                 continue;
8870.             if ((int) allopt[i].setwhere == pass) {
8871.                 if ((is_wc_option(name) && !wc_supported(name))
8872.                     || (is_wc2_option(name) && !wc2_supported(name)))
8873.                     continue;
8874. 
8875.                 doset_add_menu(tmpwin, name, fmtstr_doset, i,
8876.                                (pass == set_gameview) ? 0 : indexoffset);
8877.             }
8878.         }
8879. 
8880.     add_menu_str(tmpwin, "");
8881.     add_menu_heading(tmpwin, "Other settings:");
8882. 
8883.     for (pass = startpass; pass <= endpass; pass++)
8884.         for (i = 0; (name = allopt[i].name) != 0; i++) {
8885.             if (allopt[i].opttyp != OthrOpt)
8886.                 continue;
8887.             if ((int) allopt[i].setwhere == pass) {
8888.                 if ((is_wc_option(name) && !wc_supported(name))
8889.                     || (is_wc2_option(name) && !wc2_supported(name)))
8890.                     continue;
8891. 
8892.                 doset_add_menu(tmpwin, name, fmtstr_doset, i,
8893.                                (pass == set_gameview) ? 0 : indexoffset);
8894.             }
8895.         }
8896. 
8897. #ifdef PREFIXES_IN_USE
8898.     add_menu_str(tmpwin, "");
8899.     add_menu_heading(tmpwin, "Variable playground locations:");
8900.     for (i = 0; i < PREFIX_COUNT; i++)
8901.         doset_add_menu(tmpwin, fqn_prefix_names[i], fmtstr_doset, -1, 0);
8902. #endif
8903.     end_menu(tmpwin, "Set what options?");
8904.     go.opt_need_redraw = FALSE;
8905.     go.opt_need_glyph_reset = FALSE;
8906. 
8907.     if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &pick_list)) > 0) {
8908.         /*
8909.          * Walk down the selection list and either invert the booleans
8910.          * or prompt for new values. In most cases, call parseoptions()
8911.          * to take care of options that require special attention, like
8912.          * redraws.
8913.          */
8914.         for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
8915.             opt_indx = pick_list[pick_idx].item.a_int - 1;
8916.             if (opt_indx == HELP_IDX) {
8917.                 display_file(OPTMENUHELP, FALSE);
8918.                 gavehelp = TRUE;
8919.                 continue; /* just handled '?'; there might be more picks */
8920.             }
8921.             if (opt_indx < -1)
8922.                 opt_indx++; /* -1 offset for select_menu() */
8923.             opt_indx -= indexoffset;
8924.             assert(IndexOk(opt_indx, allopt));
8925.             if (allopt[opt_indx].opttyp == BoolOpt) {
8926.                 /* boolean option */
8927.                 Sprintf(buf, "%s%s", *allopt[opt_indx].addr ? "!" : "",
8928.                         allopt[opt_indx].name);
8929.                 (void) parseoptions(buf, FALSE, FALSE);
8930.             } else {
8931.                 /* compound option */
8932.                 int k = opt_indx, reslt;
8933. 
8934.                 if (allopt[k].has_handler && allopt[k].optfn) {
8935.                     reslt = (*allopt[k].optfn)(allopt[k].idx, do_handler,
8936.                                                FALSE, empty_optstr,
8937.                                                empty_optstr);
8938.                     /* if player eventually saves options, include this one */
8939.                     if (reslt == optn_ok)
8940.                         opt_set_in_config[k] = TRUE;
8941.                 } else {
8942.                     char abuf[BUFSZ];
8943. 
8944.                     Sprintf(buf, "Set %s to what?", allopt[opt_indx].name);
8945.                     abuf[0] = '\0';
8946.                     getlin(buf, abuf);
8947.                     if (abuf[0] == '\033')
8948.                         continue;
8949.                     Sprintf(buf, "%s:", allopt[opt_indx].name);
8950.                     (void) strncat(eos(buf), abuf,
8951.                                    (sizeof buf - 1 - strlen(buf)));
8952.                     /* pass the buck */
8953.                     (void) parseoptions(buf, FALSE, FALSE);
8954.                 }
8955.             }
8956.             if (wc_supported(allopt[opt_indx].name)
8957.                 || wc2_supported(allopt[opt_indx].name))
8958.                 preference_update(allopt[opt_indx].name);
8959.         }
8960.         free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
8961.     }
8962. 
8963.     destroy_nhwindow(tmpwin);
8964. 
8965.     if (pick_cnt == 1 && gavehelp) {
8966.         /* when '?' is only the thing selected, go back and pick all
8967.            over again without it as an available choice second time */
8968.         skiphelp = TRUE;
8969.         gavehelp = FALSE; /* currently True; reset for second pass */
8970.         goto rerun;
8971.     }
8972. 
8973.     reset_needed_visuals();
8974.     return ECMD_OK;
8975. }
8976. 
8977. #undef HELP_IDX
8978. 
8979. staticfn void
8980. reset_needed_visuals(void)
8981. {
8982.     if (go.opt_need_glyph_reset) {
8983.         reset_glyphmap(gm_optionchange);
8984.     }
8985.     if (go.opt_reset_customcolors || go.opt_update_basic_palette
8986.         || go.opt_reset_customsymbols || go.opt_need_redraw) {
8987.         if (go.opt_update_basic_palette) {
8988. #ifdef CHANGE_COLOR
8989.             change_palette();
8990. #endif
8991.             go.opt_update_basic_palette = FALSE;
8992.         }
8993.         if (go.opt_reset_customcolors)
8994.             reset_customcolors();
8995.         if (go.opt_reset_customsymbols)
8996.             reset_customsymbols();
8997.         if (go.opt_need_redraw) {
8998.             check_gold_symbol();
8999.             reglyph_darkroom();
9000.         }
9001.         docrt();
9002.     }
9003.     if (go.opt_need_promptstyle) {
9004.         adjust_menu_promptstyle(WIN_INVEN, &iflags.menu_headings);
9005.     }
9006.     if (disp.botl || disp.botlx) {
9007.         bot();
9008.     }
9009.     go.opt_need_redraw = FALSE;
9010.     go.opt_need_glyph_reset = FALSE;
9011.     go.opt_reset_customcolors = FALSE;
9012.     go.opt_reset_customsymbols = FALSE;
9013.     go.opt_update_basic_palette = FALSE;
9014. }
9015. 
9016. /* doset(#optionsfull command) menu entries for compound options */
9017. staticfn void
9018. doset_add_menu(
9019.     winid win,          /* window to add to */
9020.     const char *option, /* option name */
9021.     const char *fmtstr, /* fmtstr_doset */
9022.     int idx,            /* index in allopt[] */
9023.     int indexoffset)    /* value to add to index in allopt[],
9024.                          * or zero if option cannot be changed */
9025. {
9026.     const char *value = "unknown"; /* current value */
9027.     const char *indent;
9028.     char buf[BUFSZ], buf2[BUFSZ];
9029.     anything any;
9030.     int i = idx, reslt = optn_err;
9031. #ifdef PREFIXES_IN_USE
9032.     int j;
9033. #endif
9034.     int clr = NO_COLOR;
9035. 
9036.     buf2[0] = '\0';  /* per opt functs may not guarantee this, so do it */
9037.     any = cg.zeroany;
9038.     if (i >= 0 && i < OPTCOUNT && allopt[i].name && allopt[i].optfn) {
9039.         any.a_int = (indexoffset == 0) ? 0 : i + 1 + indexoffset;
9040.         if (allopt[i].optfn)
9041.             reslt = (*allopt[i].optfn)(allopt[i].idx, get_val,
9042.                                        FALSE, buf2, empty_optstr);
9043.         if (reslt == optn_ok && buf2[0])
9044.             value = (const char *) buf2;
9045.     } else {
9046.         /* We are trying to add an option not found in allopt[].
9047.            This is almost certainly bad, but we'll let it through anyway
9048.            (with a zero value, so it can't be selected). */
9049.         any.a_int = 0;
9050. #ifdef PREFIXES_IN_USE
9051.         for (j = 0; j < PREFIX_COUNT; ++j)
9052.             if (!strcmp(option, fqn_prefix_names[j]) && gf.fqn_prefix[j])
9053.                 Sprintf(buf2, "%s", gf.fqn_prefix[j]);
9054. #endif
9055.         if (!buf2[0])
9056.             Strcpy(buf2, "unknown");
9057.         value = (const char *) buf2;
9058.     }
9059. 
9060.     /* "    " replaces "a - " -- assumes menus follow that style */
9061.     indent = !any.a_int ? "    " : "";
9062.     Sprintf(buf, fmtstr, indent, option, value);
9063.     add_menu(win, &nul_glyphinfo, &any, 0, 0,
9064.              ATR_NONE, clr, buf, MENU_ITEMFLAGS_SKIPINVERT);
9065. }
9066. 
9067. 
9068. /* display keys for menu actions; used by cmd.c '?i' and pager.c '?k' */
9069. void
9070. show_menu_controls(winid win, boolean dolist)
9071. {
9072.     struct xtra_cntrls {
9073.         const char *key, *desc;
9074.     };
9075.     static const struct xtra_cntrls hardcoded[] = {
9076.         { "Return", "Accept current choice(s) and dismiss menu" },
9077.         { "Enter",  "Same as Return" },
9078.         { "Space",  "If not on last page, advance one page;" },
9079.         { "     ",  "when on last page, treat like Return" },
9080.         { "Escape", "Cancel menu without making any choice(s)" },
9081.         { (char *) 0, (char *) 0}
9082.     };
9083.     static const char mc_fmt[] = "%8s     %-6s %s",
9084.                       mc_altfmt[] = "%9s  %-6s %s";
9085.     char buf[BUFSZ];
9086.     const char *fmt, *arg;
9087.     const struct xtra_cntrls *xcp;
9088.     boolean has_menu_shift = wc2_supported("menu_shift");
9089. 
9090.     /*
9091.      * Relies on spaces to line things up in columns, so must be rendered
9092.      * with a fixed-width font or will look dreadful.
9093.      */
9094. 
9095.     putstr(win, 0, "Menu control keys:");
9096.     if (dolist) { /* key bindings help: '?i' */
9097.         int i;
9098.         char ch;
9099. 
9100.         fmt = "%-7s %s";
9101.         for (i = 0; default_menu_cmd_info[i].desc; i++) {
9102.             ch = default_menu_cmd_info[i].cmd;
9103.             if ((ch == MENU_SHIFT_RIGHT
9104.                  || ch == MENU_SHIFT_LEFT) && !has_menu_shift)
9105.                 continue;
9106.             Sprintf(buf, fmt,
9107.                     visctrl(get_menu_cmd_key(ch)),
9108.                     default_menu_cmd_info[i].desc);
9109.             putstr(win, 0, buf);
9110.         }
9111.         /* no separator before hardcoded */
9112.         fmt = "%s%-7s %s"; /* extra specifier to absorb 'arg' */
9113.         arg = ""; /* no extra prefix for 'dolist' */
9114.     } else { /* menu controls help: '?k' */
9115.         putstr(win, 0, "");
9116.         Sprintf(buf, mc_altfmt, "", "Whole", "Current");
9117.         putstr(win, 0, buf);
9118.         Sprintf(buf, mc_altfmt, "", " Menu", " Page");
9119.         putstr(win, 0, buf);
9120.         Sprintf(buf, mc_fmt, "Select",
9121.                 visctrl(get_menu_cmd_key(MENU_SELECT_ALL)),
9122.                 visctrl(get_menu_cmd_key(MENU_SELECT_PAGE)));
9123.         putstr(win, 0, buf);
9124.         Sprintf(buf, mc_fmt, "Invert",
9125.                 visctrl(get_menu_cmd_key(MENU_INVERT_ALL)),
9126.                 visctrl(get_menu_cmd_key(MENU_INVERT_PAGE)));
9127.         putstr(win, 0, buf);
9128.         Sprintf(buf, mc_fmt, "Deselect",
9129.                 visctrl(get_menu_cmd_key(MENU_UNSELECT_ALL)),
9130.                 visctrl(get_menu_cmd_key(MENU_UNSELECT_PAGE)));
9131.         putstr(win, 0, buf);
9132.         putstr(win, 0, "");
9133.         Sprintf(buf, mc_fmt, "Go to",
9134.                 visctrl(get_menu_cmd_key(MENU_NEXT_PAGE)),
9135.                 "Next page");
9136.         putstr(win, 0, buf);
9137.         Sprintf(buf, mc_fmt, "",
9138.                 visctrl(get_menu_cmd_key(MENU_PREVIOUS_PAGE)),
9139.                 "Previous page");
9140.         putstr(win, 0, buf);
9141.         Sprintf(buf, mc_fmt, "",
9142.                 visctrl(get_menu_cmd_key(MENU_FIRST_PAGE)),
9143.                 "First page");
9144.         putstr(win, 0, buf);
9145.         Sprintf(buf, mc_fmt, "",
9146.                 visctrl(get_menu_cmd_key(MENU_LAST_PAGE)),
9147.                 "Last page");
9148.         putstr(win, 0, buf);
9149.         if (has_menu_shift) {
9150.             Sprintf(buf, mc_fmt, "Pan view",
9151.                     visctrl(get_menu_cmd_key(MENU_SHIFT_RIGHT)),
9152.                     "Right (perm_invent only)");
9153.             putstr(win, 0, buf);
9154.             Sprintf(buf, mc_fmt, "",
9155.                     visctrl(get_menu_cmd_key(MENU_SHIFT_LEFT)),
9156.                     "Left");
9157.             putstr(win, 0, buf);
9158.         }
9159.         putstr(win, 0, "");
9160.         Sprintf(buf, mc_fmt, "Search",
9161.                 visctrl(get_menu_cmd_key(MENU_SEARCH)),
9162.                 "Exter a target string and invert all matching entries");
9163.         putstr(win, 0, buf);
9164.         /* separator before hardcoded */
9165.         putstr(win, 0, "");
9166.         fmt = "%9s  %-8s %s";
9167.         arg = "Other "; /* prefix for first hardcoded[] entry, then reset */
9168.     }
9169.     for (xcp = hardcoded; xcp->key; ++xcp) {
9170.         Sprintf(buf, fmt, arg, xcp->key, xcp->desc);
9171.         putstr(win, 0, buf);
9172.         arg = "";
9173.     }
9174. }
9175. 
9176. RESTORE_WARNING_FORMAT_NONLITERAL
9177. 
9178. staticfn int
9179. count_cond(void)
9180. {
9181.     int i, cnt = 0;
9182. 
9183.     for (i = 0; i < CONDITION_COUNT; ++i) {
9184.         if (condtests[i].enabled)
9185.             cnt++;
9186.     }
9187.     return cnt;
9188. }
9189. 
9190. staticfn int
9191. count_apes(void)
9192. {
9193.     int numapes = 0;
9194.     struct autopickup_exception *ape = ga.apelist;
9195. 
9196.     while (ape) {
9197.       numapes++;
9198.       ape = ape->next;
9199.     }
9200. 
9201.     return numapes;
9202. }
9203. 
9204. DISABLE_WARNING_FORMAT_NONLITERAL
9205. 
9206. /* common to msg-types, menu-colors, autopickup-exceptions */
9207. staticfn int
9208. handle_add_list_remove(const char *optname, int numtotal)
9209. {
9210.     winid tmpwin;
9211.     anything any;
9212.     int i, pick_cnt, opt_idx;
9213.     menu_item *pick_list = (menu_item *) 0;
9214.     static const struct action {
9215.         char letr;
9216.         const char *desc;
9217.     } action_titles[] = {
9218.         { 'a', "add new %s" },         /* [0] */
9219.         { 'l', "list %s" },            /* [1] */
9220.         { 'r', "remove existing %s" }, /* [2] */
9221.         { 'x', "exit this menu" },     /* [3] */
9222.     };
9223.     int clr = NO_COLOR;
9224. 
9225.     tmpwin = create_nhwindow(NHW_MENU);
9226.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
9227.     any = cg.zeroany;
9228.     for (i = 0; i < SIZE(action_titles); i++) {
9229.         char tmpbuf[BUFSZ];
9230. 
9231.         any.a_int++;
9232.         /* omit list and remove if there aren't any yet */
9233.         if (!numtotal && (i == 1 || i == 2))
9234.             continue;
9235.         Sprintf(tmpbuf, action_titles[i].desc,
9236.                 (i == 1) ? makeplural(optname) : optname);
9237.         add_menu(tmpwin, &nul_glyphinfo,&any, action_titles[i].letr,
9238.                  0, ATR_NONE, clr, tmpbuf,
9239.                  (i == 3) ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
9240.     }
9241.     end_menu(tmpwin, "Do what?");
9242.     if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &pick_list)) > 0) {
9243.         opt_idx = pick_list[0].item.a_int - 1;
9244.         if (pick_cnt > 1 && opt_idx == 3)
9245.             opt_idx = pick_list[1].item.a_int - 1;
9246.         free((genericptr_t) pick_list);
9247.     } else
9248.         opt_idx = 3; /* none selected, exit menu */
9249.     destroy_nhwindow(tmpwin);
9250.     return opt_idx;
9251. }
9252. 
9253. RESTORE_WARNING_FORMAT_NONLITERAL
9254. 
9255. int
9256. dotogglepickup(void)
9257. {
9258.     char buf[BUFSZ], ocl[MAXOCLASSES + 1];
9259. 
9260.     flags.pickup = !flags.pickup;
9261.     if (flags.pickup) {
9262.         oc_to_str(flags.pickup_types, ocl);
9263.         Sprintf(buf, "ON, for %s objects%s", ocl[0] ? ocl : "all",
9264.                 (ga.apelist)
9265.                     ? ((count_apes() == 1)
9266.                            ? ", with one exception"
9267.                            : ", with some exceptions")
9268.                     : "");
9269.     } else {
9270.         Strcpy(buf, "OFF");
9271.     }
9272.     pline("Autopickup: %s.", buf);
9273.     return ECMD_OK;
9274. }
9275. 
9276. /* toggle any (settable in-game) boolean option by name */
9277. int
9278. toggle_bool_option(const char *p)
9279. {
9280.     int i;
9281.     int ret = ECMD_FAIL;
9282. 
9283.     for (i = 0; i < OPTCOUNT; i++)
9284.         if (!strncmpi(allopt[i].name, p, strlen(p))
9285.             && allopt[i].opttyp == BoolOpt
9286.             && allopt[i].setwhere == set_in_game
9287.             && allopt[i].addr != 0) {
9288.             char buf[BUFSZ];
9289. 
9290.             Sprintf(buf, "%s%s", *allopt[i].addr ? "!" : "", allopt[i].name);
9291.             if (parseoptions(buf, FALSE, FALSE))
9292.                 ret = ECMD_OK;
9293. 
9294.             reset_needed_visuals();
9295.         }
9296.     return ret;
9297. }
9298. 
9299. int
9300. add_autopickup_exception(const char *mapping)
9301. {
9302.     static const char
9303.         APE_regex_error[] = "regex error in AUTOPICKUP_EXCEPTION",
9304.         APE_syntax_error[] = "syntax error in AUTOPICKUP_EXCEPTION";
9305. 
9306.     struct autopickup_exception *ape;
9307.     char text[256], end;
9308.     int n;
9309.     boolean grab = FALSE;
9310. 
9311.     /* scan length limit used to be 255, but smaller size allows the
9312.        quoted value to fit within BUFSZ, simplifying formatting elsewhere;
9313.        this used to ignore the possibility of trailing junk but now checks
9314.        for it, accepting whitespace but rejecting anything else unless it
9315.        starts with '#" for a comment */
9316.     end = '\0';
9317.     if ((n = sscanf(mapping, "\"<%253[^\"]\" %c", text, &end)) == 1
9318.         || (n == 2 && end == '#')) {
9319.         grab = TRUE;
9320.     } else if ((n = sscanf(mapping, "\">%253[^\"]\" %c", text, &end)) == 1
9321.                || (n = sscanf(mapping, "\"%253[^\"]\" %c", text, &end)) == 1
9322.                || (n == 2 && end == '#')) {
9323.         grab = FALSE;
9324.     } else {
9325.         config_error_add("%s", APE_syntax_error);
9326.         return 0;
9327.     }
9328. 
9329.     ape = (struct autopickup_exception *) alloc(sizeof *ape);
9330.     ape->regex = regex_init();
9331.     if (!regex_compile(text, ape->regex)) {
9332.         char errbuf[BUFSZ];
9333.         char *re_error_desc = regex_error_desc(ape->regex, errbuf);
9334. 
9335.         /* free first in case reason for failure was insufficient memory */
9336.         regex_free(ape->regex);
9337.         free((genericptr_t) ape);
9338.         config_error_add("%s: %s", APE_regex_error, re_error_desc);
9339.         return 0;
9340.     }
9341.     ape->pattern = dupstr(text);
9342.     ape->grab = grab;
9343.     ape->next = ga.apelist;
9344.     ga.apelist = ape;
9345.     return 1;
9346. }
9347. 
9348. staticfn void
9349. remove_autopickup_exception(struct autopickup_exception *whichape)
9350. {
9351.     struct autopickup_exception *ape, *freeape, *prev = 0;
9352. 
9353.     for (ape = ga.apelist; ape;) {
9354.         if (ape == whichape) {
9355.             freeape = ape;
9356.             ape = ape->next;
9357.             if (prev)
9358.                 prev->next = ape;
9359.             else
9360.                 ga.apelist = ape;
9361.             regex_free(freeape->regex);
9362.             free((genericptr_t) freeape->pattern);
9363.             free((genericptr_t) freeape);
9364.         } else {
9365.             prev = ape;
9366.             ape = ape->next;
9367.         }
9368.     }
9369. }
9370. 
9371. void
9372. free_autopickup_exceptions(void)
9373. {
9374.     struct autopickup_exception *ape;
9375. 
9376.     while ((ape = ga.apelist) != 0) {
9377.         free((genericptr_t) ape->pattern);
9378.         regex_free(ape->regex);
9379.         ga.apelist = ape->next;
9380.         free((genericptr_t) ape);
9381.     }
9382. }
9383. 
9384. int
9385. sym_val(const char *strval) /* up to 4*BUFSZ-1 long; only first few
9386.                                chars matter */
9387. {
9388.     char buf[QBUFSZ], tmp[QBUFSZ]; /* to hold truncated copy of 'strval' */
9389. 
9390.     buf[0] = '\0';
9391.     if (!strval[0] || !strval[1]) { /* empty, or single character */
9392.         /* if single char is space or tab, leave buf[0]=='\0' */
9393.         if (!isspace((uchar) strval[0]))
9394.             buf[0] = strval[0];
9395.     } else if (strval[0] == '\) { /* single quote */
9396.         /* simple matching single quote; we know strval[1] isn't '\0' */
9397.         if (strval[2] == '\ && !strval[3]) {
9398.             /* accepts '\' as backslash and  as single quote */
9399.             buf[0] = strval[1];
9400. 
9401.         /* if backslash, handle single or double quote or second backslash */
9402.         } else if (strval[1] == '\\' && strval[2] && strval[3] == '\
9403.             && strchr("'\"\\", strval[2]) && !strval[4]) {
9404.             buf[0] = strval[2];
9405. 
9406.         /* not simple quote or basic backslash;
9407.            strip closing quote and let escapes() deal with it */
9408.         } else {
9409.             char *p;
9410. 
9411.             /* +1: skip opening single quote */
9412.             (void) strncpy(tmp, strval + 1, sizeof tmp - 1);
9413.             tmp[sizeof tmp - 1] = '\0';
9414.             if ((p = strrchr(tmp, '\)) != 0) {
9415.                 *p = '\0';
9416.                 escapes(tmp, buf);
9417.             } /* else buf[0] stays '\0' */
9418.         }
9419.     } else { /* not lone char nor single quote */
9420.         (void) strncpy(tmp, strval, sizeof tmp - 1);
9421.         tmp[sizeof tmp - 1] = '\0';
9422.         escapes(tmp, buf);
9423.     }
9424. 
9425.     return (int) *buf;
9426. }
9427. 
9428. /* data for option_help() */
9429. static const char *opt_intro[] = {
9430.     "",
9431.     "                 NetHack Options Help:", "",
9432. #define CONFIG_SLOT 3 /* fill in next value at run-time */
9433.     (char *) 0,
9434. #if !defined(MICRO) && !defined(MACOS9)
9435.     "or use `NETHACKOPTIONS=\"<options>\"' in your environment",
9436. #endif
9437.     "(<options> is a list of options separated by commas)",
9438. #ifdef VMS
9439.     "-- for example, $ DEFINE NETHACKOPTIONS \"noautopickup,fruit:kumquat\"",
9440. #endif
9441.     "or press \"O\" while playing and use the menu.",
9442.     "",
9443.     ("Boolean options (which can be negated by prefixing them"
9444.      " with '!' or \"no\"):"),
9445.     (char *) 0
9446. };
9447. 
9448. static const char *const opt_epilog[] = {
9449.     "",
9450.     "Some of the options can only be set before the game is started;",
9451.     "those items will not be selectable in the 'O' command's menu.",
9452.     "Some options are stored in a game's save file, and will keep saved",
9453.     "values when restoring that game even if you have updated your config-",
9454.     "uration file to change them.  Such changes will matter for new games.",
9455.     "The \"other settings\" can be set with 'O', but when set within the",
9456.     "configuration file they use their own directives rather than OPTIONS.",
9457.     "See NetHack's \"Guidebook\" for details.",
9458.     (char *) 0
9459. };
9460. 
9461. void
9462. option_help(void)
9463. {
9464.     char buf[BUFSZ], buf2[BUFSZ];
9465.     const char *optname;
9466.     int i;
9467.     winid datawin;
9468. 
9469.     datawin = create_nhwindow(NHW_TEXT);
9470.     Snprintf(buf, sizeof buf,
9471.              "Set options as OPTIONS=<options> in %s", get_configfile());
9472.     opt_intro[CONFIG_SLOT] = (const char *) buf;
9473.     for (i = 0; opt_intro[i]; i++)
9474.         putstr(datawin, 0, opt_intro[i]);
9475. 
9476.     /* Boolean options */
9477.     for (i = 0; allopt[i].name; i++) {
9478.         if ((allopt[i].opttyp != BoolOpt || !allopt[i].addr)
9479.             || (allopt[i].setwhere == set_wizonly && !wizard))
9480.             continue;
9481.         if (allopt[i].setwhere == set_wiznofuz
9482.             && (!wizard || iflags.debug_fuzzer))
9483.             continue;
9484.         optname = allopt[i].name;
9485.         if ((is_wc_option(optname) && !wc_supported(optname))
9486.             || (is_wc2_option(optname) && !wc2_supported(optname)))
9487.             continue;
9488.         next_opt(datawin, optname);
9489.     }
9490.     next_opt(datawin, "");
9491. 
9492.     /* Compound options */
9493.     putstr(datawin, 0, "Compound options:");
9494.     for (i = 0; allopt[i].name; i++) {
9495.         if (allopt[i].opttyp != CompOpt
9496.             || (allopt[i].setwhere == set_wizonly && !wizard))
9497.             continue;
9498.         if (allopt[i].setwhere == set_wiznofuz
9499.             && (!wizard || iflags.debug_fuzzer))
9500.             continue;
9501.         optname = allopt[i].name;
9502.         if ((is_wc_option(optname) && !wc_supported(optname))
9503.             || (is_wc2_option(optname) && !wc2_supported(optname)))
9504.             continue;
9505.         Sprintf(buf2, "`%s'", optname);
9506.         Snprintf(buf, sizeof(buf), "%-20s - %s%c", buf2, allopt[i].descr,
9507.                  allopt[i + 1].name ? ',' : '.');
9508.         putstr(datawin, 0, buf);
9509.     }
9510.     putstr(datawin, 0, "");
9511. 
9512.     /* Compound options */
9513.     putstr(datawin, 0, "Other settings:");
9514.     for (i = 0; allopt[i].name; i++) {
9515.         if (allopt[i].opttyp != OthrOpt)
9516.             continue;
9517.         Sprintf(buf, " %s", allopt[i].name);
9518.         putstr(datawin, 0, buf);
9519.     }
9520. 
9521.     putstr(datawin, 0, "");
9522. 
9523.     for (i = 0; opt_epilog[i]; i++)
9524.         putstr(datawin, 0, opt_epilog[i]);
9525. 
9526.     /*
9527.      * TODO:
9528.      *  briefly describe interface-specific option-like settings for
9529.      *  the currently active interface:
9530.      *    X11 uses X-specific "application defaults" from NetHack.ad;
9531.      *    Qt has menu accessible "game -> Qt settings" (non-OSX) or
9532.      *      "nethack -> Preferences" (OSX) to maintain a few options
9533.      *      (font size, map tile size, paperdoll show/hide flag and
9534.      *      tile size) which persist across games;
9535.      *    Windows GUI also has some port-specific menus;
9536.      *    tty and curses: anything?
9537.      *  Best done via a new windowprocs function rather than plugging
9538.      *  in details here.
9539.      *
9540.      * Maybe:
9541.      *  switch from text window to pick-none menu so that user can
9542.      *  scroll back up.  (Not necessary for Qt where text windows are
9543.      *  already scrollable.)
9544.      */
9545. 
9546.     display_nhwindow(datawin, FALSE);
9547.     destroy_nhwindow(datawin);
9548.     return;
9549. }
9550. 
9551. /* gather all non-default cond_xyz options into one OPTIONS=cond_foo,!cond_bar
9552.    entry spread across multiple lines with backslash+newline if needed;
9553.    conditions with their default settings (cond_blind, !cond_glowhands, &c)
9554.    are excluded */
9555. staticfn void
9556. all_options_conds(strbuf_t *sbuf)
9557. {
9558.     char buf[BUFSZ], nextcond[BUFSZ];
9559.     int idx = 0;
9560.     boolean gotone = FALSE;
9561. 
9562.     buf[0] = '\0';
9563.     while (opt_next_cond(idx, nextcond)) {
9564.         /* 75: room for about 5 conditions, with enough space for player
9565.            to edit resulting file manually and insert '!' in front of them */
9566.         if (idx == 0) {
9567.             Strcpy(buf, "OPTIONS=");
9568.         } else if (Strlen(buf) + 1 + Strlen(nextcond) >= 75) {
9569.             /* finish off previous line */
9570.             Strcat(buf, ",\\\n"); /* comma and backslash+newline */
9571.             strbuf_append(sbuf, buf);
9572.             /* indent continuation line */
9573.             Sprintf(buf, "%8s", " "); /* 8: strlen("OPTIONS=") */
9574.         } else if (nextcond[0] && gotone) {
9575.             Strcat(buf, ",");
9576.         }
9577.         if (nextcond[0]) {
9578.             gotone = TRUE;
9579.             Strcat(buf, nextcond);
9580.         }
9581.         ++idx;
9582.     }
9583.     /* finish off final line; value might be empty if one or more cond_xyz
9584.        options were changed in such a manner that they're all back to their
9585.        default values--which will produce "OPTIONS=" with nothing after the
9586.        equals sign; only add to the output when there is more present */
9587.     if (strcmp(buf, "OPTIONS=")) {
9588.         Strcat(buf, "\n");
9589.         strbuf_append(sbuf, buf);
9590.     }
9591. }
9592. 
9593. /* append menucolor lines to strbuf */
9594. staticfn void
9595. all_options_menucolors(strbuf_t *sbuf)
9596. {
9597.     int i = 0, ncolors = count_menucolors();
9598.     struct menucoloring *tmp = gm.menu_colorings;
9599.     char buf[BUFSZ*2]; /* see also: add_menu_coloring() */
9600.     struct menucoloring **arr;
9601. 
9602.     if (!ncolors)
9603.         return;
9604. 
9605.     /* reverse the order */
9606.     arr = (struct menucoloring **) alloc(ncolors * sizeof *arr);
9607.     while (tmp) {
9608.         arr[i++] = tmp;
9609.         tmp = tmp->next;
9610.     }
9611. 
9612.     for (i = ncolors; i > 0; i--) {
9613.         tmp = arr[i-1];
9614.         const char *sattr = attr2attrname(tmp->attr);
9615.         const char *sclr = clr2colorname(tmp->color);
9616.         Sprintf(buf, "MENUCOLOR=\"%s\"=%s%s%s\n",
9617.                 tmp->origstr,
9618.                 sclr,
9619.                 (tmp->attr != ATR_NONE) ? "&" : "",
9620.                 (tmp->attr != ATR_NONE) ? sattr : "");
9621.         strbuf_append(sbuf, buf);
9622.     }
9623. 
9624.     free(arr);
9625. }
9626. 
9627. staticfn void
9628. all_options_msgtypes(strbuf_t *sbuf)
9629. {
9630.     struct plinemsg_type *tmp = gp.plinemsg_types;
9631.     char buf[BUFSZ];
9632. 
9633.     while (tmp) {
9634.         const char *mtype = msgtype2name(tmp->msgtype);
9635.         Sprintf(buf, "MSGTYPE=%s \"%s\"\n",
9636.                 mtype, tmp->pattern);
9637.         strbuf_append(sbuf, buf);
9638.         tmp = tmp->next;
9639.     }
9640. }
9641. 
9642. staticfn void
9643. all_options_apes(strbuf_t *sbuf)
9644. {
9645.     struct autopickup_exception *tmp = ga.apelist;
9646.     char buf[BUFSZ];
9647. 
9648.     while (tmp) {
9649.         Sprintf(buf, "autopickup_exception=\"%c%s\"\n",
9650.                 tmp->grab ? '<' : '>', tmp->pattern);
9651.         strbuf_append(sbuf, buf);
9652.         tmp = tmp->next;
9653.     }
9654. }
9655. 
9656. #ifdef CHANGE_COLOR
9657. staticfn void
9658. all_options_palette(strbuf_t *sbuf)
9659. {
9660.     int clr, n = count_alt_palette();
9661.     char buf[BUFSZ];
9662. 
9663.     if (!n)
9664.         return;
9665. 
9666.     for (clr = 0; clr < CLR_MAX; ++clr) {
9667.         if (ga.altpalette[clr] != 0U) {
9668.             Sprintf(buf, "OPTIONS=palette:%s/#%06x\n",
9669.                     clr2colorname(clr), COLORVAL(ga.altpalette[clr]));
9670.             strbuf_append(sbuf, buf);
9671.         }
9672.     }
9673. }
9674. #endif /* CHANGE_COLOR */
9675. 
9676. /* return strbuf of all options, to write to file */
9677. void
9678. all_options_strbuf(strbuf_t *sbuf)
9679. {
9680.     const char *name;
9681.     char tmp[BUFSZ];
9682.     char *buf2;
9683.     boolean *bool_p;
9684.     int i;
9685. 
9686.     strbuf_init(sbuf);
9687.     Sprintf(tmp, "# NetHack config, saved %s\n#\n",
9688.             yyyymmddhhmmss((time_t) 0));
9689.     strbuf_append(sbuf, tmp);
9690. 
9691.     for (i = 0; (name = allopt[i].name) != 0; i++) {
9692.         if (!opt_set_in_config[i])
9693.             continue;
9694.         switch (allopt[i].opttyp) {
9695.         case BoolOpt:
9696.             bool_p = allopt[i].addr;
9697.             if (!bool_p || bool_p == &flags.female)
9698.                 break; /* obsolete */
9699.             if (*bool_p != allopt[i].initval) {
9700.                 Sprintf(tmp, "OPTIONS=%s%s\n", *bool_p ? "" : "!", name);
9701.                 strbuf_append(sbuf, tmp);
9702.             }
9703.             break;
9704.         case CompOpt:
9705.             if (!(allopt[i].setwhere == set_in_config
9706.                   || allopt[i].setwhere == set_gameview
9707.                   || allopt[i].setwhere == set_in_game))
9708.                 break;
9709.             /* FIXME: get_option_value for:
9710.                - menu_deselect_all &c menu control keys,
9711.                - term_cols, term_rows */
9712.             buf2 = get_option_value(name, TRUE);
9713.             if (buf2) {
9714.                 Snprintf(tmp, sizeof tmp - 1, "OPTIONS=%s:%s", name, buf2);
9715.                 Strcat(tmp, "\n"); /* guaranteed to fit */
9716.                 strbuf_append(sbuf, tmp);
9717.             }
9718.             break;
9719.         case OthrOpt:
9720.             break;
9721.         }
9722.     }
9723. 
9724.     /* cond_xyz are closer to regular options than the other 'other opts'
9725.        so put them next; [pfx_cond_] will be set if any cond_Foo were
9726.        present when RC file was read in or if player made any changes via
9727.        status conditions menu; ignore opt_set_in_config[opt_o_status_cond] */
9728.     if (opt_set_in_config[pfx_cond_])
9729.         all_options_conds(sbuf);
9730. 
9731. #ifdef CHANGE_COLOR
9732.     all_options_palette(sbuf);
9733. #endif
9734.     get_changed_key_binds(sbuf);
9735.     savedsym_strbuf(sbuf);
9736.     all_options_menucolors(sbuf);
9737.     all_options_msgtypes(sbuf);
9738.     all_options_apes(sbuf);
9739.     all_options_autocomplete(sbuf);
9740. #ifdef STATUS_HILITES
9741.     all_options_statushilites(sbuf);
9742. #endif
9743. 
9744.     if (gw.wizkit[0]) {
9745.         Sprintf(tmp, "WIZKIT=%s\n", gw.wizkit);
9746.         strbuf_append(sbuf, tmp);
9747.     }
9748. }
9749. 
9750. /*
9751.  * prints the next boolean option, on the same line if possible, on a new
9752.  * line if not. End with next_opt("").
9753.  */
9754. void
9755. next_opt(winid datawin, const char *str)
9756. {
9757.     static char *buf = 0;
9758.     int i;
9759.     char *s;
9760. 
9761.     if (!buf)
9762.         *(buf = (char *) alloc(COLBUFSZ)) = '\0';
9763. 
9764.     if (!*str) {
9765.         s = eos(buf);
9766.         if (s > &buf[1] && s[-2] == ',')
9767.             s[-2] = '.', s[-1] = '\0'; /* replace ending ", " with "." */
9768.         i = COLNO;              /* (greater than COLNO - 2) */
9769.     } else {
9770.         i = Strlen(buf) + Strlen(str) + 2;
9771.     }
9772. 
9773.     if (i > COLNO - 2) { /* rule of thumb */
9774.         putstr(datawin, 0, buf);
9775.         buf[0] = 0;
9776.     }
9777.     if (*str) {
9778.         Strcat(buf, str);
9779.         Strcat(buf, ", ");
9780.     } else {
9781.         putstr(datawin, 0, str);
9782.         free((genericptr_t) buf), buf = 0;
9783.     }
9784.     return;
9785. }
9786. 
9787. static struct wc_Opt wc_options[] = {
9788.     { "ascii_map", WC_ASCII_MAP },
9789.     { "color", WC_COLOR },
9790.     { "eight_bit_tty", WC_EIGHT_BIT_IN },
9791.     { "hilite_pet", WC_HILITE_PET },
9792.     { "perm_invent", WC_PERM_INVENT },
9793.     { "perminv_mode", WC_PERM_INVENT }, /* shares WC_PERM_INVENT */
9794.     { "popup_dialog", WC_POPUP_DIALOG },
9795.     { "player_selection", WC_PLAYER_SELECTION },
9796.     { "preload_tiles", WC_PRELOAD_TILES },
9797.     { "tiled_map", WC_TILED_MAP },
9798.     { "tile_file", WC_TILE_FILE },
9799.     { "tile_width", WC_TILE_WIDTH },
9800.     { "tile_height", WC_TILE_HEIGHT },
9801.     { "align_message", WC_ALIGN_MESSAGE },
9802.     { "align_status", WC_ALIGN_STATUS },
9803.     { "font_map", WC_FONT_MAP },
9804.     { "font_menu", WC_FONT_MENU },
9805.     { "font_message", WC_FONT_MESSAGE },
9806.     { "font_size_map", WC_FONTSIZ_MAP },
9807.     { "font_size_menu", WC_FONTSIZ_MENU },
9808.     { "font_size_message", WC_FONTSIZ_MESSAGE },
9809.     { "font_size_status", WC_FONTSIZ_STATUS },
9810.     { "font_size_text", WC_FONTSIZ_TEXT },
9811.     { "font_status", WC_FONT_STATUS },
9812.     { "font_text", WC_FONT_TEXT },
9813.     { "map_mode", WC_MAP_MODE },
9814.     { "scroll_amount", WC_SCROLL_AMOUNT },
9815.     { "scroll_margin", WC_SCROLL_MARGIN },
9816.     { "splash_screen", WC_SPLASH_SCREEN },
9817.     { "use_inverse", WC_INVERSE },
9818.     { "vary_msgcount", WC_VARY_MSGCOUNT },
9819.     { "windowcolors", WC_WINDOWCOLORS },
9820.     { "mouse_support", WC_MOUSE_SUPPORT },
9821.     { (char *) 0, 0L }
9822. };
9823. static struct wc_Opt wc2_options[] = {
9824.     { "armorstatus", WC2_EXTRASTATUS },
9825.     { "fullscreen", WC2_FULLSCREEN },
9826.     { "guicolor", WC2_GUICOLOR },
9827.     { "hilite_status", WC2_HILITE_STATUS },
9828.     { "hitpointbar", WC2_HITPOINTBAR },
9829.     { "menu_shift", WC2_MENU_SHIFT },
9830.     { "petattr", WC2_PETATTR },
9831.     { "softkeyboard", WC2_SOFTKEYBOARD },
9832.     /* name shown in 'O' menu is different */
9833.     { "status hilite rules", WC2_HILITE_STATUS },
9834.     /* statushilites doesn't have its own bit */
9835.     { "statushilites", WC2_HILITE_STATUS },
9836.     { "statuslines", WC2_STATUSLINES },
9837.     { "term_cols", WC2_TERM_SIZE },
9838.     { "term_rows", WC2_TERM_SIZE },
9839.     { "terrainstatus", WC2_EXTRASTATUS },
9840.     { "use_darkgray", WC2_DARKGRAY },
9841.     { "weaponstatus", WC2_EXTRASTATUS },
9842.     { "windowborders", WC2_WINDOWBORDERS },
9843.     { "wraptext", WC2_WRAPTEXT },
9844.     { (char *) 0, 0L }
9845. };
9846. 
9847. /*
9848.  * If a port wants to change or ensure that the set_in_sysconf,
9849.  * set_in_config, set_gameview, or set_in_game status of an option is
9850.  * correct (for controlling its display in the option menu) call
9851.  * set_option_mod_status()
9852.  * with the appropriate second argument.
9853.  */
9854. void
9855. set_option_mod_status(const char *optnam, int status)
9856. {
9857.     int k;
9858. 
9859.     if (SET__IS_VALUE_VALID(status)) {
9860.         impossible("set_option_mod_status: status out of range %d.", status);
9861.         return;
9862.     }
9863.     for (k = 0; allopt[k].name; k++) {
9864.         if (str_start_is(allopt[k].name, optnam, TRUE)) {
9865.             allopt[k].setwhere = status;
9866.             return;
9867.         }
9868.     }
9869. }
9870. 
9871. /*
9872.  * You can set several wc_options in one call to
9873.  * set_wc_option_mod_status() by setting
9874.  * the appropriate bits for each option that you
9875.  * are setting in the optmask argument
9876.  * prior to calling.
9877.  *    example: set_wc_option_mod_status(WC_COLOR|WC_SCROLL_MARGIN,
9878.  * set_in_game);
9879.  */
9880. void
9881. set_wc_option_mod_status(unsigned long optmask, int status)
9882. {
9883.     int k = 0;
9884. 
9885.     if (SET__IS_VALUE_VALID(status)) {
9886.         impossible("set_wc_option_mod_status: status out of range %d.",
9887.                    status);
9888.         return;
9889.     }
9890.     while (wc_options[k].wc_name) {
9891.         if (optmask & wc_options[k].wc_bit) {
9892.             set_option_mod_status(wc_options[k].wc_name, status);
9893.         }
9894.         k++;
9895.     }
9896. }
9897. 
9898. staticfn boolean
9899. is_wc_option(const char *optnam)
9900. {
9901.     int k = 0;
9902. 
9903.     while (wc_options[k].wc_name) {
9904.         if (strcmp(wc_options[k].wc_name, optnam) == 0)
9905.             return TRUE;
9906.         k++;
9907.     }
9908.     return FALSE;
9909. }
9910. 
9911. staticfn boolean
9912. wc_supported(const char *optnam)
9913. {
9914.     int k;
9915. 
9916.     for (k = 0; wc_options[k].wc_name; ++k) {
9917.         if (!strcmp(wc_options[k].wc_name, optnam))
9918.             return (windowprocs.wincap & wc_options[k].wc_bit) ? TRUE : FALSE;
9919.     }
9920.     return FALSE;
9921. }
9922. 
9923. /*
9924.  * You can set several wc2_options in one call to
9925.  * set_wc2_option_mod_status() by setting
9926.  * the appropriate bits for each option that you
9927.  * are setting in the optmask argument
9928.  * prior to calling.
9929.  *    example:
9930.  * set_wc2_option_mod_status(WC2_FULLSCREEN|WC2_SOFTKEYBOARD|WC2_WRAPTEXT,
9931.  * set_in_config);
9932.  */
9933. 
9934. void
9935. set_wc2_option_mod_status(unsigned long optmask, int status)
9936. {
9937.     int k = 0;
9938. 
9939.     if (SET__IS_VALUE_VALID(status)) {
9940.         impossible("set_wc2_option_mod_status: status out of range %d.",
9941.                    status);
9942.         return;
9943.     }
9944.     while (wc2_options[k].wc_name) {
9945.         if (optmask & wc2_options[k].wc_bit) {
9946.             set_option_mod_status(wc2_options[k].wc_name, status);
9947.         }
9948.         k++;
9949.     }
9950. }
9951. 
9952. staticfn boolean
9953. is_wc2_option(const char *optnam)
9954. {
9955.     int k = 0;
9956. 
9957.     while (wc2_options[k].wc_name) {
9958.         if (strcmp(wc2_options[k].wc_name, optnam) == 0)
9959.             return TRUE;
9960.         k++;
9961.     }
9962.     return FALSE;
9963. }
9964. 
9965. staticfn boolean
9966. wc2_supported(const char *optnam)
9967. {
9968.     int k;
9969. 
9970.     for (k = 0; wc2_options[k].wc_name; ++k) {
9971.         if (!strcmp(wc2_options[k].wc_name, optnam))
9972.             return (windowprocs.wincap2 & wc2_options[k].wc_bit) ? TRUE
9973.                                                                  : FALSE;
9974.     }
9975.     return FALSE;
9976. }
9977. 
9978. staticfn void
9979. wc_set_font_name(int opttype, char *fontname)
9980. {
9981.     char **fn = (char **) 0;
9982. 
9983.     if (!fontname)
9984.         return;
9985.     switch (opttype) {
9986.     case MAP_OPTION:
9987.         fn = &iflags.wc_font_map;
9988.         break;
9989.     case MESSAGE_OPTION:
9990.         fn = &iflags.wc_font_message;
9991.         break;
9992.     case TEXT_OPTION:
9993.         fn = &iflags.wc_font_text;
9994.         break;
9995.     case MENU_OPTION:
9996.         fn = &iflags.wc_font_menu;
9997.         break;
9998.     case STATUS_OPTION:
9999.         fn = &iflags.wc_font_status;
10000.         break;
10001.     default:
10002.         return;
10003.     }
10004.     if (fn) {
10005.         if (*fn)
10006.             free((genericptr_t) *fn);
10007.         *fn = dupstr(fontname);
10008.     }
10009.     return;
10010. }
10011. 
10012. static char **fgp[] = { &iflags.wcolors[wcolor_menu].fg,
10013.                         &iflags.wcolors[wcolor_message].fg,
10014.                         &iflags.wcolors[wcolor_status].fg,
10015.                         &iflags.wcolors[wcolor_text].fg };
10016. static char **bgp[] = { &iflags.wcolors[wcolor_menu].bg,
10017.                         &iflags.wcolors[wcolor_message].bg,
10018.                         &iflags.wcolors[wcolor_status].bg,
10019.                         &iflags.wcolors[wcolor_text].bg };
10020. int options_set_window_colors_flag = 0;
10021. 
10022. staticfn int
10023. wc_set_window_colors(char *op)
10024. {
10025.     /* syntax:
10026.      *  menu white/black message green/yellow status white/blue text
10027.      * white/black
10028.      */
10029. 
10030.     int j;
10031.     int32 clr;
10032.     char buf[BUFSZ];
10033.     char *wn, *tfg, *tbg, *newop;
10034. 
10035.     Strcpy(buf, op);
10036.     newop = mungspaces(buf);
10037.     while (*newop) {
10038.         wn = tfg = tbg = (char *) 0;
10039. 
10040.         /* until first non-space in case there's leading spaces - before
10041.            colorname*/
10042.         if (*newop == ' ')
10043.             newop++;
10044.         if (!*newop)
10045.             return 0;
10046.         wn = newop;
10047. 
10048.         /* until first space - colorname*/
10049.         while (*newop && *newop != ' ')
10050.             newop++;
10051.         if (!*newop)
10052.             return 0;
10053.         *newop++ = '\0';
10054. 
10055.         /* until first non-space - before foreground*/
10056.         if (*newop == ' ')
10057.             newop++;
10058.         if (!*newop)
10059.             return 0;
10060.         tfg = newop;
10061. 
10062.         /* until slash - foreground */
10063.         while (*newop && *newop != '/')
10064.             newop++;
10065.         if (!*newop)
10066.             return 0;
10067.         *newop++ = '\0';
10068. 
10069.         /* until first non-space (in case there's leading space after slash) -
10070.          * before background */
10071.         if (*newop == ' ')
10072.             newop++;
10073.         if (!*newop)
10074.             return 0;
10075.         tbg = newop;
10076. 
10077.         /* until first space - background */
10078.         while (*newop && *newop != ' ')
10079.             newop++;
10080.         if (*newop)
10081.             *newop++ = '\0';
10082. 
10083.         for (j = 0; j < WC_COUNT; ++j) {
10084.             if (!strcmpi(wn, wcnames[j]) || !strcmpi(wn, wcshortnames[j])) {
10085.                 if (!strstri(tfg, " ")) {
10086.                     if (*fgp[j])
10087.                         free((genericptr_t) *fgp[j]);
10088.                     clr = check_enhanced_colors(tfg);
10089.                     *fgp[j] = dupstr((clr >= 0) ? wc_color_name(clr) : tfg);
10090.                 }
10091.                 if (!strstri(tbg, " ")) {
10092.                     if (*bgp[j])
10093.                         free((genericptr_t) *bgp[j]);
10094.                     clr = check_enhanced_colors(tbg);
10095.                     *bgp[j] = dupstr((clr >= 0) ? wc_color_name(clr) : tbg);
10096.                 }
10097.                 if (wcolors_opt[j] != 0) {
10098.                     config_error_add(
10099.                        "windowcolors for %s windows specified multiple times",
10100.                                      wcnames[j]);
10101.                 }
10102.                 wcolors_opt[j]++;
10103.                 break;
10104.             }
10105.         }
10106.         if (j == WC_COUNT) {
10107.             config_error_add("windowcolors for unrecognized window type: %s",
10108.                              wn);
10109.         }
10110.     }
10111.     options_set_window_colors_flag = 1;
10112.     return 1;
10113. }
10114. 
10115. void
10116. options_free_window_colors(void)
10117. {
10118.     int j;
10119. 
10120.     for (j = 0; j < WC_COUNT; ++j) {
10121.         if (*fgp[j])
10122.             free((genericptr_t) *fgp[j]), *fgp[j] = 0;
10123.         if (*bgp[j])
10124.             free((genericptr_t) *bgp[j]), *bgp[j] = 0;
10125.     }
10126.     options_set_window_colors_flag = 0;
10127. }
10128. 
10129. /* set up for wizard mode if player or save file has requested it;
10130.    called from port-specific startup code to handle `nethack -D' or
10131.    OPTIONS=playmode:debug, or from dorecover()'s restgamestate() if
10132.    restoring a game which was saved in wizard mode */
10133. void
10134. set_playmode(void)
10135. {
10136.     if (wizard) {
10137.         if (authorize_wizard_mode())
10138.             gp.plnamelen = (int) strlen(strcpy(svp.plname, "wizard"));
10139.         else
10140.             wizard = FALSE; /* not allowed or not available */
10141.         /* try explore mode if we didn't make it into wizard mode */
10142.         /* if requesting wizard mode when restoring a normal game, this will
10143.            set iflags.deferred_X and prompt to activate explore mode after the
10144.            save file has already been deleted */
10145.         discover = !wizard;
10146.         iflags.deferred_X = FALSE;
10147.     }
10148.     if (discover && !authorize_explore_mode()) {
10149.         discover = iflags.deferred_X = FALSE;
10150.     }
10151.     /* don't need to do anything special for normal play */
10152. }
10153. 
10154. staticfn void
10155. enhance_menu_text(
10156.     char *buf,
10157.     size_t sz,
10158.     int whichpass UNUSED,
10159.     boolean *bool_p,
10160.     struct allopt_t *thisopt)
10161. {
10162.     size_t nowsz, availsz;
10163. 
10164.     if (!buf)
10165.         return;
10166.     nowsz = strlen(buf) + 1;
10167.     availsz = sz - nowsz;
10168. 
10169. #if 0 /*#ifdef TTY_PERM_INVENT*/
10170.     if (bool_p == &iflags.perm_invent && WINDOWPORT(tty)) {
10171.         if (thisopt->setwhere == set_gameview)
10172.             Snprintf(eos(buf), availsz, " *terminal size is too small");
10173.     }
10174. #else
10175.     nhUse(availsz);
10176.     nhUse(bool_p);
10177.     nhUse(thisopt);
10178. #endif
10179.     return;
10180. }
10181. 
10182. void
10183. heed_all_options(void)
10184. {
10185.     int i;
10186. 
10187.     for (i = 0; i < OPTCOUNT; i++)
10188.         allopt[i].disregarded = FALSE;
10189. }
10190. 
10191. void
10192. disregard_all_options(void)
10193. {
10194.     int i;
10195. 
10196.     for (i = 0; i < OPTCOUNT ; i++)
10197.         allopt[i].disregarded = TRUE;
10198. }
10199. 
10200. void
10201. heed_this_option(enum opt optidx)
10202. {
10203.     if (optidx >= 0 && optidx < (enum opt) OPTCOUNT)
10204.          allopt[optidx].disregarded = FALSE;
10205. }
10206. void
10207. disregard_this_option(enum opt optidx)
10208. {
10209.     if (optidx >= 0 && optidx < (enum opt) OPTCOUNT)
10210.         allopt[optidx].disregarded = TRUE;
10211. }
10212. 
10213. 
10214. 
10215. #undef OPTIONS_HEADING
10216. #undef CONFIG_SLOT
10217. 
10218. #endif /* OPTION_LISTS_ONLY */
10219. 
10220. #undef BACKWARD_COMPAT
10221. #undef COMPLAIN_ABOUT_PRAYCONFIRM
10222. #undef PREV_MSGS
10223. #undef PILE_LIMIT_DFLT
10224. 
10225. /*options.c*/