1010#include <shell/shell.h>
1111#include "shell_utils.h"
1212#include "shell_ops.h"
13+ #include "shell_wildcard.h"
1314#include "shell_vt100.h"
1415#include <assert.h>
1516#include <atomic.h>
@@ -381,6 +382,15 @@ static const struct shell_static_entry *get_last_command(
381382 * match_arg = SHELL_CMD_ROOT_LVL ;
382383
383384 while (* match_arg < argc ) {
385+
386+ if (IS_ENABLED (CONFIG_SHELL_WILDCARD )) {
387+ /* ignore wildcard argument */
388+ if (shell_wildcard_character_exist (argv [* match_arg ])) {
389+ (* match_arg )++ ;
390+ continue ;
391+ }
392+ }
393+
384394 entry = find_cmd (prev_cmd , * match_arg , argv [* match_arg ],
385395 d_entry );
386396 if (entry ) {
@@ -922,6 +932,7 @@ static void shell_execute(const struct shell *shell)
922932 const struct shell_cmd_entry * p_cmd = NULL ;
923933 size_t cmd_lvl = SHELL_CMD_ROOT_LVL ;
924934 size_t cmd_with_handler_lvl = 0 ;
935+ bool wildcard_found = false;
925936 size_t cmd_idx ;
926937 size_t argc ;
927938 char quote ;
@@ -938,6 +949,10 @@ static void shell_execute(const struct shell *shell)
938949 history_put (shell , shell -> ctx -> cmd_buff ,
939950 shell -> ctx -> cmd_buff_len );
940951
952+ if (IS_ENABLED (CONFIG_SHELL_WILDCARD )) {
953+ shell_wildcard_prepare (shell );
954+ }
955+
941956 /* create argument list */
942957 quote = shell_make_argv (& argc , & argv [0 ], shell -> ctx -> cmd_buff ,
943958 CONFIG_SHELL_ARGC_MAX );
@@ -985,6 +1000,28 @@ static void shell_execute(const struct shell *shell)
9851000 break ;
9861001 }
9871002
1003+ if (IS_ENABLED (CONFIG_SHELL_WILDCARD )) {
1004+ enum shell_wildcard_status status ;
1005+
1006+ status = shell_wildcard_process (shell , p_cmd ,
1007+ argv [cmd_lvl ]);
1008+ /* Wildcard character found but there is no matching
1009+ * command.
1010+ */
1011+ if (status == SHELL_WILDCARD_CMD_NO_MATCH_FOUND ) {
1012+ break ;
1013+ }
1014+
1015+ /* Wildcard character was not found function can process
1016+ * argument.
1017+ */
1018+ if (status != SHELL_WILDCARD_NOT_FOUND ) {
1019+ ++ cmd_lvl ;
1020+ wildcard_found = true;
1021+ continue ;
1022+ }
1023+ }
1024+
9881025 cmd_get (p_cmd , cmd_lvl , cmd_idx ++ , & p_static_entry , & d_entry );
9891026
9901027 if ((cmd_idx == 0 ) || (p_static_entry == NULL )) {
@@ -994,6 +1031,28 @@ static void shell_execute(const struct shell *shell)
9941031 if (strcmp (argv [cmd_lvl ], p_static_entry -> syntax ) == 0 ) {
9951032 /* checking if command has a handler */
9961033 if (p_static_entry -> handler != NULL ) {
1034+ if (IS_ENABLED (CONFIG_SHELL_WILDCARD )) {
1035+ if (wildcard_found ) {
1036+ shell_op_cursor_end_move (shell );
1037+ shell_op_cond_next_line (shell );
1038+
1039+ /* An error occurred, fnmatch
1040+ * argument cannot be followed
1041+ * by argument with a handler to
1042+ * avoid multiple function
1043+ * calls.
1044+ */
1045+ shell_fprintf (shell ,
1046+ SHELL_ERROR ,
1047+ "Error: requested"
1048+ " multiple function"
1049+ " executions\r\n" );
1050+ help_flag_clear (shell );
1051+
1052+ return ;
1053+ }
1054+ }
1055+
9971056 shell -> ctx -> active_cmd = * p_static_entry ;
9981057 cmd_with_handler_lvl = cmd_lvl ;
9991058 }
@@ -1004,6 +1063,17 @@ static void shell_execute(const struct shell *shell)
10041063 }
10051064 }
10061065
1066+ if (IS_ENABLED (CONFIG_SHELL_WILDCARD )) {
1067+ shell_wildcard_finalize (shell );
1068+ /* cmd_buffer has been overwritten by function finalize function
1069+ * with all expanded commands. Hence shell_make_argv needs to
1070+ * be called again.
1071+ */
1072+ (void )shell_make_argv (& argc , & argv [0 ],
1073+ shell -> ctx -> cmd_buff ,
1074+ CONFIG_SHELL_ARGC_MAX );
1075+ }
1076+
10071077 /* Executing the deepest found handler. */
10081078 if (shell -> ctx -> active_cmd .handler == NULL ) {
10091079 if (shell -> ctx -> active_cmd .help ) {
0 commit comments