10
10
#include <shell/shell.h>
11
11
#include "shell_utils.h"
12
12
#include "shell_ops.h"
13
+ #include "shell_wildcard.h"
13
14
#include "shell_vt100.h"
14
15
#include <assert.h>
15
16
#include <atomic.h>
@@ -381,6 +382,15 @@ static const struct shell_static_entry *get_last_command(
381
382
* match_arg = SHELL_CMD_ROOT_LVL ;
382
383
383
384
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
+
384
394
entry = find_cmd (prev_cmd , * match_arg , argv [* match_arg ],
385
395
d_entry );
386
396
if (entry ) {
@@ -922,6 +932,7 @@ static void shell_execute(const struct shell *shell)
922
932
const struct shell_cmd_entry * p_cmd = NULL ;
923
933
size_t cmd_lvl = SHELL_CMD_ROOT_LVL ;
924
934
size_t cmd_with_handler_lvl = 0 ;
935
+ bool wildcard_found = false;
925
936
size_t cmd_idx ;
926
937
size_t argc ;
927
938
char quote ;
@@ -938,6 +949,10 @@ static void shell_execute(const struct shell *shell)
938
949
history_put (shell , shell -> ctx -> cmd_buff ,
939
950
shell -> ctx -> cmd_buff_len );
940
951
952
+ if (IS_ENABLED (CONFIG_SHELL_WILDCARD )) {
953
+ shell_wildcard_prepare (shell );
954
+ }
955
+
941
956
/* create argument list */
942
957
quote = shell_make_argv (& argc , & argv [0 ], shell -> ctx -> cmd_buff ,
943
958
CONFIG_SHELL_ARGC_MAX );
@@ -985,6 +1000,28 @@ static void shell_execute(const struct shell *shell)
985
1000
break ;
986
1001
}
987
1002
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
+
988
1025
cmd_get (p_cmd , cmd_lvl , cmd_idx ++ , & p_static_entry , & d_entry );
989
1026
990
1027
if ((cmd_idx == 0 ) || (p_static_entry == NULL )) {
@@ -994,6 +1031,28 @@ static void shell_execute(const struct shell *shell)
994
1031
if (strcmp (argv [cmd_lvl ], p_static_entry -> syntax ) == 0 ) {
995
1032
/* checking if command has a handler */
996
1033
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
+
997
1056
shell -> ctx -> active_cmd = * p_static_entry ;
998
1057
cmd_with_handler_lvl = cmd_lvl ;
999
1058
}
@@ -1004,6 +1063,17 @@ static void shell_execute(const struct shell *shell)
1004
1063
}
1005
1064
}
1006
1065
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
+
1007
1077
/* Executing the deepest found handler. */
1008
1078
if (shell -> ctx -> active_cmd .handler == NULL ) {
1009
1079
if (shell -> ctx -> active_cmd .help ) {
0 commit comments