arogue7: prevent changing protected options.

When using the savedir, whoami, file_name, and score_file cannot be
changed.
This commit is contained in:
John "Elwin" Edwards 2015-05-11 19:41:46 -04:00
parent 7824f79164
commit b6ab08176a

View file

@ -49,6 +49,9 @@ int put_bool(),
get_quest(),
put_quest();
int get_str_prot(char *opt, WINDOW *win);
bool allowchange(OPTION *op);
OPTION optlist[] = {
{"terse", "Terse output: ",
(int *) &terse, put_bool, get_bool },
@ -65,11 +68,11 @@ OPTION optlist[] = {
{"overlay", "Overlay menu: ",
(int *) &menu_overlay, put_bool, get_bool },
{"name", "Name: ",
(int *) whoami, put_str, get_str },
(int *) whoami, put_str, get_str_prot },
{"file", "Save file: ",
(int *) file_name, put_str, get_str },
(int *) file_name, put_str, get_str_prot },
{"score", "Score file: ",
(int *) score_file, put_str, get_str },
(int *) score_file, put_str, get_str_prot },
{"class", "Character class: ",
(int *)&char_type, put_abil, get_abil },
{"quest", "Quest item: ",
@ -381,7 +384,10 @@ register char *str;
/* Put the value into the option field */
if (op->o_putfunc != put_abil)
strcpy((char *)op->o_opt, (char *)value);
{
if (allowchange(op))
strcpy((char *)op->o_opt, (char *)value);
}
else if (*op->o_opt == -1) { /* Only init ability once */
register int len = strlen(value);
@ -463,3 +469,33 @@ WINDOW *win;
{
waddstr(win, str);
}
/* Like get_str, but disallows changes when use_savedir is set. */
int
get_str_prot(char *opt, WINDOW *win)
{
int oy, ox;
if (use_savedir) {
getyx(win, oy, ox);
waddstr(win, opt);
return get_ro(win, oy, ox);
}
else {
return get_str(opt, win);
}
}
bool
allowchange(OPTION *op)
{
if (!use_savedir)
return TRUE;
if (!strcmp(op->o_name, "name"))
return FALSE;
if (!strcmp(op->o_name, "file"))
return FALSE;
if (!strcmp(op->o_name, "score"))
return FALSE;
return TRUE;
}