From 9968461c2be694e042035f774ab6e98e088cceab Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Fri, 21 Feb 2020 10:32:23 +0800 Subject: [PATCH] nsh/command: do not show the module application in built-in list Change-Id: Ia6dd5dcf7d7eb829fde67c522f7ee2155a4051ce Signed-off-by: chao.an --- nshlib/nsh_command.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index 819bfae54..da749a835 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -766,12 +766,12 @@ static inline void help_allcmds(FAR struct nsh_vtbl_s *vtbl) static inline void help_builtins(FAR struct nsh_vtbl_s *vtbl) { #ifdef CONFIG_NSH_BUILTIN_APPS - FAR const char *name; - unsigned int num_builtins; - unsigned int column_width; - unsigned int builtin_width; + FAR const struct builtin_s *builtin; unsigned int builtins_per_line; unsigned int num_builtin_rows; + unsigned int builtin_width; + unsigned int num_builtins; + unsigned int column_width; unsigned int i; unsigned int j; unsigned int k; @@ -781,17 +781,29 @@ static inline void help_builtins(FAR struct nsh_vtbl_s *vtbl) num_builtins = 0; column_width = 0; - for (i = 0; (name = builtin_getname(i)) != NULL; i++) + for (i = 0; (builtin = builtin_for_index(i)) != NULL; i++) { + if (builtin->main == NULL) + { + continue; + } + num_builtins++; - builtin_width = strlen(name); + builtin_width = strlen(builtin->name); if (builtin_width > column_width) { column_width = builtin_width; } } + /* Skip the printing if no available built-in commands */ + + if (num_builtins == 0) + { + return; + } + column_width += 2; /* Determine the number of commands to put on one line */ @@ -817,13 +829,18 @@ static inline void help_builtins(FAR struct nsh_vtbl_s *vtbl) { nsh_output(vtbl, " "); for (j = 0, k = i; - j < builtins_per_line && k < num_builtins; + j < builtins_per_line && + (builtin = builtin_for_index(k)); j++, k += num_builtin_rows) { - name = builtin_getname(k); - nsh_output(vtbl, "%s", name); + if (builtin->main == NULL) + { + continue; + } - for (builtin_width = strlen(name); + nsh_output(vtbl, "%s", builtin->name); + + for (builtin_width = strlen(builtin->name); builtin_width < column_width; builtin_width++) {