Move other options into the options array
This commit is contained in:
+22
-1
@@ -13,7 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int optfn_boolean(int, int, boolean, char *, char *);
|
static int optfn_boolean(int, int, boolean, char *, char *);
|
||||||
enum OptType {BoolOpt, CompOpt};
|
enum OptType {BoolOpt, CompOpt, OthrOpt};
|
||||||
enum Y_N {No, Yes};
|
enum Y_N {No, Yes};
|
||||||
enum Off_On {Off, On};
|
enum Off_On {Off, On};
|
||||||
|
|
||||||
@@ -48,6 +48,8 @@ struct allopt_t {
|
|||||||
static int optfn_##a(int, int, boolean, char *, char *);
|
static int optfn_##a(int, int, boolean, char *, char *);
|
||||||
#define NHOPTP(a, b, c, s, n, v, d, h, al, z) \
|
#define NHOPTP(a, b, c, s, n, v, d, h, al, z) \
|
||||||
static int pfxfn_##a(int, int, boolean, char *, char *);
|
static int pfxfn_##a(int, int, boolean, char *, char *);
|
||||||
|
#define NHOPTO(m, a, b, c, s, n, v, d, al, z) \
|
||||||
|
static int optfn_##a(int, int, boolean, char *, char *);
|
||||||
|
|
||||||
#elif defined(NHOPT_ENUM)
|
#elif defined(NHOPT_ENUM)
|
||||||
#define NHOPTB(a, b, c, s, i, n, v, d, al, bp) \
|
#define NHOPTB(a, b, c, s, i, n, v, d, al, bp) \
|
||||||
@@ -56,6 +58,8 @@ opt_##a,
|
|||||||
opt_##a,
|
opt_##a,
|
||||||
#define NHOPTP(a, b, c, s, n, v, d, h, al, z) \
|
#define NHOPTP(a, b, c, s, n, v, d, h, al, z) \
|
||||||
pfx_##a,
|
pfx_##a,
|
||||||
|
#define NHOPTO(m, a, b, c, s, n, v, d, al, z) \
|
||||||
|
opt_##a,
|
||||||
|
|
||||||
#elif defined(NHOPT_PARSE)
|
#elif defined(NHOPT_PARSE)
|
||||||
#define NHOPTB(a, b, c, s, i, n, v, d, al, bp) \
|
#define NHOPTB(a, b, c, s, i, n, v, d, al, bp) \
|
||||||
@@ -67,6 +71,9 @@ pfx_##a,
|
|||||||
#define NHOPTP(a, b, c, s, n, v, d, h, al, z) \
|
#define NHOPTP(a, b, c, s, n, v, d, h, al, z) \
|
||||||
{ #a, 0, b, pfx_##a, s, CompOpt, n, v, d, Yes, c, (boolean *) 0, &pfxfn_##a, \
|
{ #a, 0, b, pfx_##a, s, CompOpt, n, v, d, Yes, c, (boolean *) 0, &pfxfn_##a, \
|
||||||
al, z, #a, Off, h, 0 },
|
al, z, #a, Off, h, 0 },
|
||||||
|
#define NHOPTO(m, a, b, c, s, n, v, d, al, z) \
|
||||||
|
{ m, 0, b, opt_##a, s, OthrOpt, n, v, d, No, c, (boolean *) 0, &optfn_##a, \
|
||||||
|
al, z, (const char *) 0, On, On, 0 },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* B:nm, ln, opt_*, setwhere?, on?, negat?, val?, dup?, hndlr? Alias, bool_p */
|
/* B:nm, ln, opt_*, setwhere?, on?, negat?, val?, dup?, hndlr? Alias, bool_p */
|
||||||
@@ -537,6 +544,19 @@ pfx_##a,
|
|||||||
&iflags.wizweight)
|
&iflags.wizweight)
|
||||||
NHOPTB(wraptext, 0, opt_in, set_in_game, Off, Yes, No, No, NoAlias,
|
NHOPTB(wraptext, 0, opt_in, set_in_game, Off, Yes, No, No, NoAlias,
|
||||||
&iflags.wc2_wraptext)
|
&iflags.wc2_wraptext)
|
||||||
|
|
||||||
|
NHOPTO("autopickup exceptions", o_autopickup_exceptions, BUFSZ, opt_in, set_in_game,
|
||||||
|
No, Yes, No, NoAlias, "edit autopickup exceptions")
|
||||||
|
NHOPTO("menu colors", o_menu_colors, BUFSZ, opt_in, set_in_game,
|
||||||
|
No, Yes, No, NoAlias, "edit menu colors")
|
||||||
|
NHOPTO("message types", o_message_types, BUFSZ, opt_in, set_in_game,
|
||||||
|
No, Yes, No, NoAlias, "edit message types")
|
||||||
|
NHOPTO("status condition fields", o_status_cond, BUFSZ, opt_in, set_in_game,
|
||||||
|
No, Yes, No, NoAlias, "edit status condition fields")
|
||||||
|
#ifdef STATUS_HILITES
|
||||||
|
NHOPTO("status hilite rules", o_status_hilites, BUFSZ, opt_in, set_in_game,
|
||||||
|
No, Yes, No, NoAlias, "edit status hilites")
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Prefix-based Options
|
* Prefix-based Options
|
||||||
*/
|
*/
|
||||||
@@ -555,6 +575,7 @@ pfx_##a,
|
|||||||
#undef NHOPTB
|
#undef NHOPTB
|
||||||
#undef NHOPTC
|
#undef NHOPTC
|
||||||
#undef NHOPTP
|
#undef NHOPTP
|
||||||
|
#undef NHOPTO
|
||||||
|
|
||||||
#endif /* NHOPT_PROTO || NHOPT_ENUM || NHOPT_PARSE */
|
#endif /* NHOPT_PROTO || NHOPT_ENUM || NHOPT_PARSE */
|
||||||
|
|
||||||
|
|||||||
+159
-102
@@ -249,7 +249,6 @@ static int count_menucolors(void);
|
|||||||
static boolean parse_role_opts(int, boolean, const char *,
|
static boolean parse_role_opts(int, boolean, const char *,
|
||||||
char *, char **);
|
char *, char **);
|
||||||
static void doset_add_menu(winid, const char *, int, int);
|
static void doset_add_menu(winid, const char *, int, int);
|
||||||
static void opts_add_others(winid, const char *, int, char *, int);
|
|
||||||
static int handle_add_list_remove(const char *, int);
|
static int handle_add_list_remove(const char *, int);
|
||||||
static void remove_autopickup_exception(struct autopickup_exception *);
|
static void remove_autopickup_exception(struct autopickup_exception *);
|
||||||
static int count_apes(void);
|
static int count_apes(void);
|
||||||
@@ -6971,31 +6970,119 @@ static char fmtstr_doset[] = "%s%-15s [%s] ";
|
|||||||
static char fmtstr_doset_tab[] = "%s\t[%s]";
|
static char fmtstr_doset_tab[] = "%s\t[%s]";
|
||||||
static char n_currently_set[] = "(%d currently set)";
|
static char n_currently_set[] = "(%d currently set)";
|
||||||
|
|
||||||
enum opt_other_enums {
|
static int
|
||||||
OPT_OTHER_COND = -5,
|
optfn_o_autopickup_exceptions(int optidx UNUSED, int req, boolean negated UNUSED,
|
||||||
OPT_OTHER_MSGTYPE = -4,
|
char *opts, char *op UNUSED)
|
||||||
OPT_OTHER_MENUCOLOR = -3,
|
{
|
||||||
OPT_OTHER_STATHILITE = -2,
|
if (req == do_init) {
|
||||||
OPT_OTHER_APEXC = -1
|
return optn_ok;
|
||||||
/* these must be < 0 */
|
}
|
||||||
};
|
if (req == do_set) {
|
||||||
|
}
|
||||||
|
if (req == get_val) {
|
||||||
|
if (!opts)
|
||||||
|
return optn_err;
|
||||||
|
Sprintf(opts, n_currently_set, count_apes());
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_handler) {
|
||||||
|
return handler_autopickup_exception();
|
||||||
|
}
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
optfn_o_menu_colors(int optidx UNUSED, int req, boolean negated UNUSED,
|
||||||
|
char *opts, char *op UNUSED)
|
||||||
|
{
|
||||||
|
if (req == do_init) {
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_set) {
|
||||||
|
}
|
||||||
|
if (req == get_val) {
|
||||||
|
if (!opts)
|
||||||
|
return optn_err;
|
||||||
|
Sprintf(opts, n_currently_set, count_menucolors());
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_handler) {
|
||||||
|
return handler_menu_colors();
|
||||||
|
}
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
optfn_o_message_types(int optidx UNUSED, int req, boolean negated UNUSED,
|
||||||
|
char *opts, char *op UNUSED)
|
||||||
|
{
|
||||||
|
if (req == do_init) {
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_set) {
|
||||||
|
}
|
||||||
|
if (req == get_val) {
|
||||||
|
if (!opts)
|
||||||
|
return optn_err;
|
||||||
|
Sprintf(opts, n_currently_set, msgtype_count());
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_handler) {
|
||||||
|
return handler_msgtype();
|
||||||
|
}
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
optfn_o_status_cond(int optidx UNUSED, int req, boolean negated UNUSED,
|
||||||
|
char *opts, char *op UNUSED)
|
||||||
|
{
|
||||||
|
if (req == do_init) {
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_set) {
|
||||||
|
}
|
||||||
|
if (req == get_val) {
|
||||||
|
if (!opts)
|
||||||
|
return optn_err;
|
||||||
|
Sprintf(opts, n_currently_set, count_cond());
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_handler) {
|
||||||
|
cond_menu();
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
|
||||||
static struct other_opts {
|
|
||||||
const char *name;
|
|
||||||
enum optset_restrictions setwhere;
|
|
||||||
enum opt_other_enums code;
|
|
||||||
int (*othr_count_func)(void);
|
|
||||||
} othropt[] = {
|
|
||||||
{ "autopickup exceptions", set_in_game, OPT_OTHER_APEXC, count_apes },
|
|
||||||
{ "menu colors", set_in_game, OPT_OTHER_MENUCOLOR, count_menucolors },
|
|
||||||
{ "message types", set_in_game, OPT_OTHER_MSGTYPE, msgtype_count },
|
|
||||||
{ "status condition fields", set_in_game, OPT_OTHER_COND, count_cond },
|
|
||||||
#ifdef STATUS_HILITES
|
#ifdef STATUS_HILITES
|
||||||
{ "status hilite rules", set_in_game, OPT_OTHER_STATHILITE,
|
static int
|
||||||
count_status_hilites },
|
optfn_o_status_hilites(int optidx UNUSED, int req, boolean negated UNUSED,
|
||||||
#endif
|
char *opts, char *op UNUSED)
|
||||||
{ (char *) 0, 0, (enum opt_other_enums) 0 },
|
{
|
||||||
};
|
if (req == do_init) {
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_set) {
|
||||||
|
}
|
||||||
|
if (req == get_val) {
|
||||||
|
if (!opts)
|
||||||
|
return optn_err;
|
||||||
|
Sprintf(opts, n_currently_set, count_status_hilites());
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
if (req == do_handler) {
|
||||||
|
if (!status_hilite_menu()) {
|
||||||
|
return optn_err; /*pline("Bad status hilite(s) specified.");*/
|
||||||
|
} else {
|
||||||
|
if (wc2_supported("hilite_status"))
|
||||||
|
preference_update("hilite_status");
|
||||||
|
}
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
return optn_ok;
|
||||||
|
}
|
||||||
|
#endif /*STATUS_HILITES*/
|
||||||
|
|
||||||
/* the 'O' command */
|
/* the 'O' command */
|
||||||
int
|
int
|
||||||
@@ -7030,14 +7117,12 @@ doset(void) /* changing options via menu by Per Liboriussen */
|
|||||||
/* spin through the options to find the longest name
|
/* spin through the options to find the longest name
|
||||||
and adjust the format string accordingly */
|
and adjust the format string accordingly */
|
||||||
longest_name_len = 0;
|
longest_name_len = 0;
|
||||||
for (pass = 0; pass <= 2; pass++)
|
for (pass = 0; pass < 2; pass++)
|
||||||
for (i = 0; (name = ((pass < 2) ? allopt[i].name
|
for (i = 0; (name = allopt[i].name) != 0; i++) {
|
||||||
: othropt[i].name)) != 0; i++) {
|
|
||||||
if (pass == 0 &&
|
if (pass == 0 &&
|
||||||
(allopt[i].opttyp != BoolOpt || !allopt[i].addr))
|
(allopt[i].opttyp != BoolOpt || !allopt[i].addr))
|
||||||
continue;
|
continue;
|
||||||
optflags = (pass < 2) ? allopt[i].setwhere
|
optflags = allopt[i].setwhere;
|
||||||
: othropt[i].setwhere;
|
|
||||||
if (optflags < startpass || optflags > endpass)
|
if (optflags < startpass || optflags > endpass)
|
||||||
continue;
|
continue;
|
||||||
if ((is_wc_option(name) && !wc_supported(name))
|
if ((is_wc_option(name) && !wc_supported(name))
|
||||||
@@ -7121,13 +7206,19 @@ doset(void) /* changing options via menu by Per Liboriussen */
|
|||||||
add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
|
add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
|
||||||
iflags.menu_headings, "Other settings:", MENU_ITEMFLAGS_NONE);
|
iflags.menu_headings, "Other settings:", MENU_ITEMFLAGS_NONE);
|
||||||
|
|
||||||
for (i = 0; (name = othropt[i].name) != 0; i++) {
|
for (pass = startpass; pass <= endpass; pass++)
|
||||||
if ((is_wc_option(name) && !wc_supported(name))
|
for (i = 0; (name = allopt[i].name) != 0; i++) {
|
||||||
|| (is_wc2_option(name) && !wc2_supported(name)))
|
if (allopt[i].opttyp != OthrOpt)
|
||||||
continue;
|
continue;
|
||||||
opts_add_others(tmpwin, name, othropt[i].code,
|
if ((int) allopt[i].setwhere == pass) {
|
||||||
(char *) 0, othropt[i].othr_count_func());
|
if ((is_wc_option(name) && !wc_supported(name))
|
||||||
}
|
|| (is_wc2_option(name) && !wc2_supported(name)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
doset_add_menu(tmpwin, name, i,
|
||||||
|
(pass == set_gameview) ? 0 : indexoffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PREFIXES_IN_USE
|
#ifdef PREFIXES_IN_USE
|
||||||
any = cg.zeroany;
|
any = cg.zeroany;
|
||||||
@@ -7152,56 +7243,37 @@ doset(void) /* changing options via menu by Per Liboriussen */
|
|||||||
opt_indx = pick_list[pick_idx].item.a_int - 1;
|
opt_indx = pick_list[pick_idx].item.a_int - 1;
|
||||||
if (opt_indx < -1)
|
if (opt_indx < -1)
|
||||||
opt_indx++; /* -1 offset for select_menu() */
|
opt_indx++; /* -1 offset for select_menu() */
|
||||||
if (opt_indx == OPT_OTHER_APEXC) {
|
opt_indx -= indexoffset;
|
||||||
handler_autopickup_exception();
|
if (allopt[opt_indx].opttyp == BoolOpt) {
|
||||||
#ifdef STATUS_HILITES
|
/* boolean option */
|
||||||
} else if (opt_indx == OPT_OTHER_STATHILITE) {
|
Sprintf(buf, "%s%s", *allopt[opt_indx].addr ? "!" : "",
|
||||||
if (!status_hilite_menu()) {
|
allopt[opt_indx].name);
|
||||||
pline("Bad status hilite(s) specified.");
|
(void) parseoptions(buf, setinitial, fromfile);
|
||||||
} else {
|
|
||||||
if (wc2_supported("hilite_status"))
|
|
||||||
preference_update("hilite_status");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else if (opt_indx == OPT_OTHER_MENUCOLOR) {
|
|
||||||
handler_menu_colors();
|
|
||||||
} else if (opt_indx == OPT_OTHER_COND) {
|
|
||||||
cond_menu();
|
|
||||||
} else if (opt_indx == OPT_OTHER_MSGTYPE) {
|
|
||||||
handler_msgtype();
|
|
||||||
} else {
|
} else {
|
||||||
opt_indx -= indexoffset;
|
/* compound option */
|
||||||
if (allopt[opt_indx].opttyp == BoolOpt) {
|
int k = opt_indx, reslt UNUSED;
|
||||||
/* boolean option */
|
|
||||||
Sprintf(buf, "%s%s", *allopt[opt_indx].addr ? "!" : "",
|
if (allopt[k].has_handler && allopt[k].optfn) {
|
||||||
allopt[opt_indx].name);
|
reslt = (*allopt[k].optfn)(allopt[k].idx, do_handler,
|
||||||
(void) parseoptions(buf, setinitial, fromfile);
|
FALSE, empty_optstr, empty_optstr);
|
||||||
} else {
|
} else {
|
||||||
/* compound option */
|
char abuf[BUFSZ];
|
||||||
int k = opt_indx, reslt UNUSED;
|
|
||||||
|
|
||||||
if (allopt[k].has_handler && allopt[k].optfn) {
|
Sprintf(buf, "Set %s to what?", allopt[opt_indx].name);
|
||||||
reslt = (*allopt[k].optfn)(allopt[k].idx, do_handler,
|
abuf[0] = '\0';
|
||||||
FALSE, empty_optstr, empty_optstr);
|
getlin(buf, abuf);
|
||||||
} else {
|
if (abuf[0] == '\033')
|
||||||
char abuf[BUFSZ];
|
continue;
|
||||||
|
Sprintf(buf, "%s:", allopt[opt_indx].name);
|
||||||
Sprintf(buf, "Set %s to what?", allopt[opt_indx].name);
|
(void) strncat(eos(buf), abuf,
|
||||||
abuf[0] = '\0';
|
|
||||||
getlin(buf, abuf);
|
|
||||||
if (abuf[0] == '\033')
|
|
||||||
continue;
|
|
||||||
Sprintf(buf, "%s:", allopt[opt_indx].name);
|
|
||||||
(void) strncat(eos(buf), abuf,
|
|
||||||
(sizeof buf - 1 - strlen(buf)));
|
(sizeof buf - 1 - strlen(buf)));
|
||||||
/* pass the buck */
|
/* pass the buck */
|
||||||
(void) parseoptions(buf, setinitial, fromfile);
|
(void) parseoptions(buf, setinitial, fromfile);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (wc_supported(allopt[opt_indx].name)
|
|
||||||
|| wc2_supported(allopt[opt_indx].name))
|
|
||||||
preference_update(allopt[opt_indx].name);
|
|
||||||
}
|
}
|
||||||
|
if (wc_supported(allopt[opt_indx].name)
|
||||||
|
|| wc2_supported(allopt[opt_indx].name))
|
||||||
|
preference_update(allopt[opt_indx].name);
|
||||||
}
|
}
|
||||||
free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
|
free((genericptr_t) pick_list), pick_list = (menu_item *) 0;
|
||||||
}
|
}
|
||||||
@@ -7268,26 +7340,6 @@ doset_add_menu(winid win, /* window to add to */
|
|||||||
ATR_NONE, buf, MENU_ITEMFLAGS_NONE);
|
ATR_NONE, buf, MENU_ITEMFLAGS_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
opts_add_others(winid win, const char *name, int id, char *bufx, int nset)
|
|
||||||
{
|
|
||||||
char buf[BUFSZ], buf2[BUFSZ];
|
|
||||||
anything any = cg.zeroany;
|
|
||||||
|
|
||||||
any.a_int = id;
|
|
||||||
if (!bufx)
|
|
||||||
Sprintf(buf2, n_currently_set, nset);
|
|
||||||
else
|
|
||||||
Sprintf(buf2, "%s", bufx);
|
|
||||||
if (!iflags.menu_tab_sep)
|
|
||||||
Sprintf(buf, fmtstr_doset, any.a_int ? "" : " ",
|
|
||||||
name, buf2);
|
|
||||||
else
|
|
||||||
Sprintf(buf, fmtstr_doset_tab, name, buf2);
|
|
||||||
add_menu(win, &nul_glyphinfo, &any, 0, 0,
|
|
||||||
ATR_NONE, buf, MENU_ITEMFLAGS_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* display keys for menu actions; used by cmd.c '?i' and pager.c '?k' */
|
/* display keys for menu actions; used by cmd.c '?i' and pager.c '?k' */
|
||||||
void
|
void
|
||||||
show_menu_controls(winid win, boolean dolist)
|
show_menu_controls(winid win, boolean dolist)
|
||||||
@@ -7772,12 +7824,17 @@ option_help(void)
|
|||||||
}
|
}
|
||||||
putstr(datawin, 0, "");
|
putstr(datawin, 0, "");
|
||||||
|
|
||||||
|
/* Compound options */
|
||||||
putstr(datawin, 0, "Other settings:");
|
putstr(datawin, 0, "Other settings:");
|
||||||
for (i = 0; othropt[i].name; ++i) {
|
for (i = 0; allopt[i].name; i++) {
|
||||||
Sprintf(buf, " %s", othropt[i].name);
|
if (allopt[i].opttyp != OthrOpt)
|
||||||
|
continue;
|
||||||
|
Sprintf(buf, " %s", allopt[i].name);
|
||||||
putstr(datawin, 0, buf);
|
putstr(datawin, 0, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
putstr(datawin, 0, "");
|
||||||
|
|
||||||
for (i = 0; opt_epilog[i]; i++)
|
for (i = 0; opt_epilog[i]; i++)
|
||||||
putstr(datawin, 0, opt_epilog[i]);
|
putstr(datawin, 0, opt_epilog[i]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user