diff --git a/nshlib/README.txt b/nshlib/README.txt index 1bd382e82..5af84ec80 100644 --- a/nshlib/README.txt +++ b/nshlib/README.txt @@ -122,18 +122,15 @@ Looping These works from the command line but are primarily intended for use within NSH scripts (see the sh command). The syntax is as follows: - while [!] ; do ; done + while ; do ; done Execute as long as has an exit status of - zero (OR non-zero if inverted with '!'). + zero. - until [!] ; do ; done + until ; do ; done Execute as long as has a non-zero exit - status (OR zero if inverted with '!'). - - Note that 'while' is equivalent to 'until' if the command result is - inverted. + status. A break command is also supported. The break command is only meaningful within the body of the a while or until loop, between the do and done diff --git a/nshlib/nsh.h b/nshlib/nsh.h index 018badcdb..187cc5696 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -776,8 +776,7 @@ enum nsh_lp_e struct nsh_loop_s { uint8_t lp_enable : 1; /* Loop command processing is enabled */ - uint8_t lp_inverted : 1; /* TRUE: inverted logic ('while ! ') */ - uint8_t lp_unused : 4; + uint8_t lp_unused : 5; uint8_t lp_state : 2; /* Loop state (see enume nsh_lp_e) */ #ifndef CONFIG_NSH_DISABLE_ITEF uint8_t lp_iendx; /* Saved if-then-else-fi index */ diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c index ac142cdd9..6888aed8c 100644 --- a/nshlib/nsh_parse.c +++ b/nshlib/nsh_parse.c @@ -439,8 +439,6 @@ static int nsh_saveresult(FAR struct nsh_vtbl_s *vtbl, bool result) if (np->np_lpstate[np->np_lpndx].lp_state == NSH_LOOP_WHILE) { - result ^= np->np_lpstate[np->np_lpndx].lp_inverted; - np->np_fail = false; np->np_lpstate[np->np_lpndx].lp_enable = (result == OK); return OK; @@ -457,8 +455,6 @@ static int nsh_saveresult(FAR struct nsh_vtbl_s *vtbl, bool result) else if (np->np_lpstate[np->np_lpndx].lp_state == NSH_LOOP_UNTIL) { - result ^= np->np_lpstate[np->np_lpndx].lp_inverted; - np->np_fail = false; np->np_lpstate[np->np_lpndx].lp_enable = (result != OK); return OK; @@ -1774,7 +1770,6 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, bool whilematch; bool untilmatch; bool enable; - bool inverted = false; int ret; if (cmd != NULL) @@ -1797,22 +1792,6 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, goto errout; } - /* Check for inverted logic */ - - if (strcmp(*ppcmd, "!") == 0) - { - inverted = true; - - /* Get the next cmd */ - - *ppcmd = nsh_argument(vtbl, saveptr, memlist); - if (*ppcmd == NULL || **ppcmd == '\0') - { - nsh_output(vtbl, g_fmtarginvalid, cmd); - goto errout; - } - } - /* Verify that "while" or "until" is valid in this context */ if ( @@ -1849,13 +1828,12 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, np->np_jump = false; #endif np->np_lpndx++; - np->np_lpstate[np->np_lpndx].lp_state = state; - np->np_lpstate[np->np_lpndx].lp_enable = enable; - np->np_lpstate[np->np_lpndx].lp_inverted = inverted; + np->np_lpstate[np->np_lpndx].lp_state = state; + np->np_lpstate[np->np_lpndx].lp_enable = enable; #ifndef CONFIG_NSH_DISABLE_ITEF - np->np_lpstate[np->np_lpndx].lp_iendx = np->np_iendx; + np->np_lpstate[np->np_lpndx].lp_iendx = np->np_iendx; #endif - np->np_lpstate[np->np_lpndx].lp_topoffs = offset; + np->np_lpstate[np->np_lpndx].lp_topoffs = offset; } /* Check if the token is "do" */ @@ -1959,13 +1937,12 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, errout: #ifndef NSH_DISABLE_SEMICOLON - np->np_jump = false; + np->np_jump = false; #endif - np->np_lpndx = 0; - np->np_lpstate[0].lp_state = NSH_LOOP_NORMAL; - np->np_lpstate[0].lp_enable = true; - np->np_lpstate[0].lp_inverted = false; - np->np_lpstate[0].lp_topoffs = 0; + np->np_lpndx = 0; + np->np_lpstate[0].lp_state = NSH_LOOP_NORMAL; + np->np_lpstate[0].lp_enable = true; + np->np_lpstate[0].lp_topoffs = 0; return ERROR; } #endif