Skip to content

Commit

Permalink
Add opt_toggle_disallowed to abort toggling a string option
Browse files Browse the repository at this point in the history
before the user enters the new string.
Use it to abort -o if the input is not a pipe.
  • Loading branch information
gwsw committed Mar 5, 2020
1 parent ada582c commit c25faac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,12 @@ commands(VOID_PARAM)
optgetname = FALSE;
mca_opt_toggle();
c = getcc();
cbuf = opt_toggle_disallowed(c);
if (cbuf != NULL)
{
error(cbuf, NULL_PARG);
break;
}
goto again;

case A_DISP_OPTION:
Expand Down
18 changes: 18 additions & 0 deletions option.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,24 @@ opt_prompt(o)
return (o->odesc[0]);
}

/*
* If the specified option can be toggled, return NULL.
* Otherwise return an appropriate error message.
*/
public char *
opt_toggle_disallowed(c)
int c;
{
switch (c)
{
case 'o':
if (ch_getflags() & CH_CANSEEK)
return "Input is not a pipe";
break;
}
return NULL;
}

/*
* Return whether or not there is a string option pending;
* that is, if the previous option was a string-valued option letter
Expand Down

0 comments on commit c25faac

Please sign in to comment.