Revert "apps/nshlib: fix unreachable code about i++"

This reverts commit 467de8ca831f671c24148e0910e0c6217ca952ee.
This commit is contained in:
Jiuzhu Dong 2022-05-07 11:52:31 +08:00 committed by Petro Karashchenko
parent b3a5b56ff3
commit 1f093da6a4

View File

@ -70,6 +70,7 @@ int nsh_session(FAR struct console_stdio_s *pstate,
{ {
FAR struct nsh_vtbl_s *vtbl; FAR struct nsh_vtbl_s *vtbl;
int ret = EXIT_FAILURE; int ret = EXIT_FAILURE;
int i;
DEBUGASSERT(pstate); DEBUGASSERT(pstate);
vtbl = &pstate->cn_vtbl; vtbl = &pstate->cn_vtbl;
@ -115,19 +116,21 @@ int nsh_session(FAR struct console_stdio_s *pstate,
/* Process the command line option */ /* Process the command line option */
if (strcmp(argv[1], "-h") == 0) for (i = 1; i < argc; i++)
{
if (strcmp(argv[i], "-h") == 0)
{ {
nsh_output(vtbl, "Usage: %s [<script-path>|-c <command>]\n", nsh_output(vtbl, "Usage: %s [<script-path>|-c <command>]\n",
argv[0]); argv[0]);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
else if (strcmp(argv[1], "-c") == 0) else if (strcmp(argv[i], "-c") == 0)
{ {
/* Process the inline command */ /* Process the inline command */
if (argc > 2) if (i + 1 < argc)
{ {
return nsh_parse(vtbl, argv[2]); return nsh_parse(vtbl, argv[i + 1]);
} }
else else
{ {
@ -135,20 +138,23 @@ int nsh_session(FAR struct console_stdio_s *pstate,
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
else if (argv[1][0] == '-') else if (argv[i][0] != '-')
{ {
break;
}
/* Unknown option */ /* Unknown option */
nsh_error(vtbl, g_fmtsyntax, argv[0]); nsh_error(vtbl, g_fmtsyntax, argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (argc > 1) if (i < argc)
{ {
#ifndef CONFIG_NSH_DISABLESCRIPT #ifndef CONFIG_NSH_DISABLESCRIPT
/* Execute the shell script */ /* Execute the shell script */
return nsh_script(vtbl, argv[0], argv[1]); return nsh_script(vtbl, argv[0], argv[i]);
#else #else
return EXIT_FAILURE; return EXIT_FAILURE;
#endif #endif