Prevent changing name or save file when using system savedir
This commit is contained in:
parent
265ac56d38
commit
5cc5f36a58
2 changed files with 50 additions and 5 deletions
|
|
@ -34,6 +34,8 @@ struct optstruct {
|
|||
|
||||
typedef struct optstruct OPTION;
|
||||
|
||||
int allowchange(OPTION *opt); /* doesn't need to be externally visible */
|
||||
|
||||
OPTION optlist[] = {
|
||||
{"terse", "Terse output: ",
|
||||
(int *) &terse, put_bool, get_bool },
|
||||
|
|
@ -69,9 +71,12 @@ option()
|
|||
*/
|
||||
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
|
||||
{
|
||||
waddstr(hw, op->o_prompt);
|
||||
(*op->o_putfunc)(op->o_opt);
|
||||
waddch(hw, '\n');
|
||||
if (allowchange(op))
|
||||
{
|
||||
waddstr(hw, op->o_prompt);
|
||||
(*op->o_putfunc)(op->o_opt);
|
||||
waddch(hw, '\n');
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Set values
|
||||
|
|
@ -79,11 +84,21 @@ option()
|
|||
wmove(hw, 0, 0);
|
||||
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
|
||||
{
|
||||
if (!allowchange(op))
|
||||
continue;
|
||||
waddstr(hw, op->o_prompt);
|
||||
if ((retval = (*op->o_getfunc)(op->o_opt, hw)))
|
||||
{
|
||||
if (retval == QUIT)
|
||||
break;
|
||||
else if (op > optlist) { /* MINUS */
|
||||
#if 0
|
||||
/* Support for MINUS has been removed because making it work with
|
||||
* hidden unchangable options without underflowing optlist will
|
||||
* require a complete rewrite. And it should also be rewritten
|
||||
* so option() doesn't count on get_str() to put the cursor in the
|
||||
* right place, because that makes it a pain to understand.
|
||||
*/
|
||||
else if (op > optlist) { /* retval == MINUS */
|
||||
wmove(hw, (int)(op - optlist) - 1, 0);
|
||||
op -= 2;
|
||||
}
|
||||
|
|
@ -93,6 +108,10 @@ option()
|
|||
wmove(hw, 0, 0);
|
||||
op--;
|
||||
}
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Switch back to original screen
|
||||
|
|
@ -285,6 +304,11 @@ parse_opts(char *str)
|
|||
* Look it up and deal with it
|
||||
*/
|
||||
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
|
||||
{
|
||||
/* If using system savefiles, changing your name or the
|
||||
save file is not allowed. */
|
||||
if (!allowchange(op))
|
||||
continue;
|
||||
if (EQSTR(str, op->o_name, len))
|
||||
{
|
||||
if (op->o_putfunc == put_bool) /* if option is a boolean */
|
||||
|
|
@ -324,6 +348,7 @@ parse_opts(char *str)
|
|||
*(int *)op->o_opt = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* skip to start of next option name
|
||||
|
|
@ -351,3 +376,15 @@ strucpy(char *s1, char *s2, size_t len)
|
|||
}
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
/* Tells whether the user is allowed to change the option. */
|
||||
int allowchange(OPTION *opt)
|
||||
{
|
||||
if (!use_savedir)
|
||||
return 1;
|
||||
if (!strcmp(opt->o_name, "name"))
|
||||
return 0;
|
||||
if (!strcmp(opt->o_name, "file"))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue