NSH: Loosen up if-then-else-fi syntx so that a command can be on the same line as the 'then' and 'else' tokens. This allows, as an example, 'if true; then echo true; else echo false; fi' which is much more bash-like
This commit is contained in:
parent
cfb7c77ed3
commit
45121c8709
@ -792,3 +792,8 @@
|
|||||||
support for while-do-done and until-do-done loops. These only work
|
support for while-do-done and until-do-done loops. These only work
|
||||||
when executing a script file because they depend on the ability to seek
|
when executing a script file because they depend on the ability to seek
|
||||||
in the file to implement the looping behaviors (2014-1-17).
|
in the file to implement the looping behaviors (2014-1-17).
|
||||||
|
* apps/nshlib/nsh_parse.c: Loosen up if-then-else-fi syntax to allow
|
||||||
|
a command to be on the same line as the then and else tokens like:
|
||||||
|
"if true; then echo true; else echo false; fi". Much more like bash!
|
||||||
|
(2014-1-17).
|
||||||
|
|
||||||
|
@ -1684,14 +1684,9 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
|
|||||||
|
|
||||||
else if (strcmp(cmd, "then") == 0)
|
else if (strcmp(cmd, "then") == 0)
|
||||||
{
|
{
|
||||||
/* Get the cmd following the "then" -- there shouldn't be one */
|
/* Get the cmd following the "then" -- there may or may not be one */
|
||||||
|
|
||||||
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
|
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
|
||||||
if (*ppcmd)
|
|
||||||
{
|
|
||||||
nsh_output(vtbl, g_fmtarginvalid, "then");
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Verify that "then" is valid in this context */
|
/* Verify that "then" is valid in this context */
|
||||||
|
|
||||||
@ -1708,14 +1703,9 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
|
|||||||
|
|
||||||
else if (strcmp(cmd, "else") == 0)
|
else if (strcmp(cmd, "else") == 0)
|
||||||
{
|
{
|
||||||
/* Get the cmd following the "else" -- there shouldn't be one */
|
/* Get the cmd following the "else" -- there may or may not be one */
|
||||||
|
|
||||||
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
|
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
|
||||||
if (*ppcmd)
|
|
||||||
{
|
|
||||||
nsh_output(vtbl, g_fmtarginvalid, "else");
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Verify that "else" is valid in this context */
|
/* Verify that "else" is valid in this context */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user