Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nshlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ if(CONFIG_NSH_LIBRARY)
list(APPEND CSRCS nsh_fsutils.c)

if(CONFIG_NSH_BUILTIN_APPS)
list(APPEND CSRCS nsh_builtin.c)
if(NOT CONFIG_NSH_BUILTIN_AS_COMMAND)
list(APPEND CSRCS nsh_builtin.c)
endif()
endif()

if(CONFIG_NSH_FILE_APPS)
Expand Down
8 changes: 8 additions & 0 deletions nshlib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ config NSH_BUILTIN_APPS
more information). This options requires support for builtin
applications (BUILTIN).

config NSH_BUILTIN_AS_COMMAND
bool "Run builtin apps as command"
default n
depends on BUILTIN
---help---
Enable to run builtin application directly without creating
a separate thread.

config NSH_FILE_APPS
bool "Enable execution of program files"
default n
Expand Down
2 changes: 2 additions & 0 deletions nshlib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ endif
CSRCS += nsh_fsutils.c

ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
ifneq ($(CONFIG_NSH_BUILTIN_AS_COMMAND),y)
CSRCS += nsh_builtin.c
endif
endif

ifeq ($(CONFIG_NSH_FILE_APPS),y)
CSRCS += nsh_fileapps.c
Expand Down
29 changes: 25 additions & 4 deletions nshlib/nsh_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,10 +1213,14 @@ static int cmd_expr(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)

int nsh_command(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char *argv[])
{
const struct cmdmap_s *cmdmap;
const char *cmd;
nsh_cmd_t handler = cmd_unrecognized;
int ret;
const struct cmdmap_s *cmdmap;
const char *cmd;
nsh_cmd_t handler = cmd_unrecognized;
#ifdef CONFIG_NSH_BUILTIN_AS_COMMAND
const struct builtin_s *builtin;
int index;
#endif
int ret;

/* The form of argv is:
*
Expand All @@ -1228,6 +1232,23 @@ int nsh_command(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char *argv[])

cmd = argv[0];

#ifdef CONFIG_NSH_BUILTIN_AS_COMMAND
/* Check if the command is available in the builtin list */

index = builtin_isavail(cmd);

if (index > 0)
{
/* Get the builtin structure by index */

builtin = builtin_for_index(index);
if (builtin != NULL)
{
return (builtin->main)(argc, (FAR char **)argv);
}
}
#endif

/* See if the command is one that we understand */

for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++)
Expand Down
8 changes: 4 additions & 4 deletions nshlib/nsh_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,12 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
*
* 1. Load a file from file system if possible. An external command on a
* file system with the provided name (and on the defined PATH) takes
* precendence over any other source of a command by that name. This
* precedence over any other source of a command by that name. This
* allows the user to replace a built-in command with a command on a`
* file system
*
* 2. If not, run a built-in application of that name if possible. A
* built-in application will take precendence over any NSH command.
* built-in application will take precedence over any NSH command.
*
* 3. If not, run an NSH command line command if possible.
*
Expand All @@ -540,7 +540,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
* Note the priority is not effected by nice-ness.
*/

#ifdef CONFIG_NSH_BUILTIN_APPS
#if defined(CONFIG_NSH_BUILTIN_APPS) && !defined(CONFIG_NSH_BUILTIN_AS_COMMAND)
ret = nsh_builtin(vtbl, argv[0], argv, param);
if (ret >= 0)
{
Expand Down Expand Up @@ -637,7 +637,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
sh_argv[3] = NULL;

/* np.np_bg still there, try use nsh_builtin or nsh_fileapp to
* dispatch the backgroud by sh -c ""
* dispatch the background by sh -c ""
*/

ret = nsh_execute(vtbl, 4, sh_argv, param);
Expand Down
Loading