11/*
2- * Copyright (c) 2006-2022 , RT-Thread Development Team
2+ * Copyright (c) 2006-2025 , RT-Thread Development Team
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 *
1717#ifdef RT_USING_FINSH
1818
1919#ifndef FINSH_ARG_MAX
20- #define FINSH_ARG_MAX 8
20+ #define FINSH_ARG_MAX 8
2121#endif /* FINSH_ARG_MAX */
2222
2323#include "msh.h"
@@ -40,16 +40,16 @@ static int msh_help(int argc, char **argv)
4040 struct finsh_syscall * index ;
4141#if defined(FINSH_USING_SYMTAB )
4242 for (index = _syscall_table_begin ;
43- index < _syscall_table_end ;
44- FINSH_NEXT_SYSCALL (index ))
43+ index < _syscall_table_end ;
44+ FINSH_NEXT_SYSCALL (index ))
4545 {
4646#if defined(FINSH_USING_DESCRIPTION )
4747 rt_kprintf ("%-16s - %s\n" , index -> name , index -> desc );
4848#else
4949 rt_kprintf ("%s " , index -> name );
50- #endif /* FINSH_USING_DESCRIPTION */
50+ #endif /* FINSH_USING_DESCRIPTION */
5151 }
52- #endif /* FINSH_USING_SYMTAB */
52+ #endif /* FINSH_USING_SYMTAB */
5353 }
5454 rt_kprintf ("\n" );
5555
@@ -61,14 +61,14 @@ MSH_CMD_EXPORT_ALIAS(msh_help, help, RT-Thread shell help);
6161static int cmd_ps (int argc , char * * argv )
6262{
6363 extern long list_thread (void );
64- extern int list_module (void );
64+ extern int list_module (void );
6565
6666#ifdef RT_USING_MODULE
6767 if ((argc == 2 ) && (strcmp (argv [1 ], "-m" ) == 0 ))
6868 list_module ();
6969 else
7070#endif
71- list_thread ();
71+ list_thread ();
7272 return 0 ;
7373}
7474MSH_CMD_EXPORT_ALIAS (cmd_ps , ps , List threads in the system );
@@ -136,12 +136,12 @@ static int cmd_bind(int argc, char **argv)
136136 if (result == RT_EOK )
137137 {
138138 rt_kprintf ("Thread 0x%lx bound to core %d successfully\n" ,
139- thread_id , core_id );
139+ thread_id , core_id );
140140 }
141141 else
142142 {
143143 rt_kprintf ("Failed to bind thread 0x%lx to core %d\n" ,
144- thread_id , core_id );
144+ thread_id , core_id );
145145 }
146146 return 0 ;
147147}
@@ -167,8 +167,8 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX])
167167 while ((* ptr == ' ' || * ptr == '\t' ) && position < length )
168168 {
169169 * ptr = '\0' ;
170- ptr ++ ;
171- position ++ ;
170+ ptr ++ ;
171+ position ++ ;
172172 }
173173
174174 if (argc >= FINSH_ARG_MAX )
@@ -182,15 +182,16 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX])
182182 break ;
183183 }
184184
185- if (position >= length ) break ;
185+ if (position >= length )
186+ break ;
186187
187188 /* handle string */
188189 if (* ptr == '"' )
189190 {
190- ptr ++ ;
191- position ++ ;
191+ ptr ++ ;
192+ position ++ ;
192193 argv [argc ] = ptr ;
193- argc ++ ;
194+ argc ++ ;
194195
195196 /* skip this string */
196197 while (* ptr != '"' && position < length )
@@ -199,30 +200,32 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX])
199200 {
200201 if (* (ptr + 1 ) == '"' )
201202 {
202- ptr ++ ;
203- position ++ ;
203+ ptr ++ ;
204+ position ++ ;
204205 }
205206 }
206- ptr ++ ;
207- position ++ ;
207+ ptr ++ ;
208+ position ++ ;
208209 }
209- if (position >= length ) break ;
210+ if (position >= length )
211+ break ;
210212
211213 /* skip '"' */
212214 * ptr = '\0' ;
213- ptr ++ ;
214- position ++ ;
215+ ptr ++ ;
216+ position ++ ;
215217 }
216218 else
217219 {
218220 argv [argc ] = ptr ;
219- argc ++ ;
221+ argc ++ ;
220222 while ((* ptr != ' ' && * ptr != '\t' ) && position < length )
221223 {
222- ptr ++ ;
223- position ++ ;
224+ ptr ++ ;
225+ position ++ ;
224226 }
225- if (position >= length ) break ;
227+ if (position >= length )
228+ break ;
226229 }
227230 }
228231
@@ -235,11 +238,10 @@ static cmd_function_t msh_get_cmd(char *cmd, int size)
235238 cmd_function_t cmd_func = RT_NULL ;
236239#if defined(FINSH_USING_SYMTAB )
237240 for (index = _syscall_table_begin ;
238- index < _syscall_table_end ;
239- FINSH_NEXT_SYSCALL (index ))
241+ index < _syscall_table_end ;
242+ FINSH_NEXT_SYSCALL (index ))
240243 {
241- if (strncmp (index -> name , cmd , size ) == 0 &&
242- index -> name [size ] == '\0' )
244+ if (strncmp (index -> name , cmd , size ) == 0 && index -> name [size ] == '\0' )
243245 {
244246 cmd_func = (cmd_function_t )index -> func ;
245247 break ;
@@ -263,13 +265,13 @@ int msh_exec_module(const char *cmd_line, int size)
263265 return - RT_ERROR ;
264266 /* get the length of command0 */
265267 while ((cmd_line [cmd_length ] != ' ' && cmd_line [cmd_length ] != '\t' ) && cmd_length < size )
266- cmd_length ++ ;
268+ cmd_length ++ ;
267269
268270 /* get name length */
269271 length = cmd_length + 32 ;
270272
271273 /* allocate program name memory */
272- pg_name = (char * ) rt_malloc (length + 3 );
274+ pg_name = (char * )rt_malloc (length + 3 );
273275 if (pg_name == RT_NULL )
274276 return - RT_ENOMEM ;
275277
@@ -334,7 +336,7 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
334336
335337 /* find the size of first command */
336338 while (cmd0_size < length && (cmd [cmd0_size ] != ' ' && cmd [cmd0_size ] != '\t' ))
337- cmd0_size ++ ;
339+ cmd0_size ++ ;
338340 if (cmd0_size == 0 )
339341 return - RT_ERROR ;
340342
@@ -488,7 +490,7 @@ int _msh_exec_lwp(int debug, char *cmd, rt_size_t length)
488490
489491 /* find the size of first command */
490492 while ((cmd [cmd0_size ] != ' ' && cmd [cmd0_size ] != '\t' ) && cmd0_size < length )
491- cmd0_size ++ ;
493+ cmd0_size ++ ;
492494 if (cmd0_size == 0 )
493495 return -1 ;
494496
@@ -544,7 +546,7 @@ int msh_exec(char *cmd, rt_size_t length)
544546 int cmd_ret = 0 ;
545547
546548 /* strim the beginning of command */
547- while ((length > 0 ) && (* cmd == ' ' || * cmd == '\t' ))
549+ while ((length > 0 ) && (* cmd == ' ' || * cmd == '\t' ))
548550 {
549551 cmd ++ ;
550552 length -- ;
@@ -559,7 +561,7 @@ int msh_exec(char *cmd, rt_size_t length)
559561 */
560562 if (_msh_exec_cmd (cmd , length , & cmd_ret ) == 0 )
561563 {
562- if (cmd_ret < 0 )
564+ if (cmd_ret < 0 )
563565 {
564566 rt_kprintf ("%s: command failed %d.\n" , cmd , cmd_ret );
565567 }
@@ -620,8 +622,8 @@ static int str_common(const char *str1, const char *str2)
620622
621623 while ((* str != 0 ) && (* str2 != 0 ) && (* str == * str2 ))
622624 {
623- str ++ ;
624- str2 ++ ;
625+ str ++ ;
626+ str2 ++ ;
625627 }
626628
627629 return (str - str1 );
@@ -638,34 +640,40 @@ void msh_auto_complete_path(char *path)
638640 return ;
639641
640642 full_path = (char * )rt_malloc (256 );
641- if (full_path == RT_NULL ) return ; /* out of memory */
643+ if (full_path == RT_NULL )
644+ return ; /* out of memory */
642645
643646 if (* path != '/' )
644647 {
645648 getcwd (full_path , 256 );
646- if (full_path [rt_strlen (full_path ) - 1 ] != '/' )
649+ if (full_path [rt_strlen (full_path ) - 1 ] != '/' )
647650 strcat (full_path , "/" );
648651 }
649- else * full_path = '\0' ;
652+ else
653+ * full_path = '\0' ;
650654
651655 index = RT_NULL ;
652656 ptr = path ;
653657 for (;;)
654658 {
655- if (* ptr == '/' ) index = ptr + 1 ;
656- if (!* ptr ) break ;
659+ if (* ptr == '/' )
660+ index = ptr + 1 ;
661+ if (!* ptr )
662+ break ;
657663
658- ptr ++ ;
664+ ptr ++ ;
659665 }
660- if (index == RT_NULL ) index = path ;
666+ if (index == RT_NULL )
667+ index = path ;
661668
662669 if (index != RT_NULL )
663670 {
664671 char * dest = index ;
665672
666673 /* fill the parent path */
667674 ptr = full_path ;
668- while (* ptr ) ptr ++ ;
675+ while (* ptr )
676+ ptr ++ ;
669677
670678 for (index = path ; index != dest ;)
671679 * ptr ++ = * index ++ ;
@@ -688,7 +696,8 @@ void msh_auto_complete_path(char *path)
688696 for (;;)
689697 {
690698 dirent = readdir (dir );
691- if (dirent == RT_NULL ) break ;
699+ if (dirent == RT_NULL )
700+ break ;
692701
693702 rt_kprintf ("%s\n" , dirent -> d_name );
694703 }
@@ -702,12 +711,13 @@ void msh_auto_complete_path(char *path)
702711 for (;;)
703712 {
704713 dirent = readdir (dir );
705- if (dirent == RT_NULL ) break ;
714+ if (dirent == RT_NULL )
715+ break ;
706716
707717 /* matched the prefix string */
708718 if (strncmp (index , dirent -> d_name , rt_strlen (index )) == 0 )
709719 {
710- multi ++ ;
720+ multi ++ ;
711721 if (min_length == 0 )
712722 {
713723 min_length = rt_strlen (dirent -> d_name );
@@ -734,7 +744,8 @@ void msh_auto_complete_path(char *path)
734744 for (;;)
735745 {
736746 dirent = readdir (dir );
737- if (dirent == RT_NULL ) break ;
747+ if (dirent == RT_NULL )
748+ break ;
738749
739750 if (strncmp (index , dirent -> d_name , rt_strlen (index )) == 0 )
740751 rt_kprintf ("%s\n" , dirent -> d_name );
@@ -920,7 +931,7 @@ void msh_auto_complete(char *prefix)
920931 break ;
921932 }
922933
923- ptr -- ;
934+ ptr -- ;
924935 }
925936#if defined(RT_USING_MODULE ) || defined(RT_USING_SMART )
926937 /* There is a chance that the user want to run the module directly. So
@@ -933,7 +944,7 @@ void msh_auto_complete(char *prefix)
933944#endif /* RT_USING_MODULE */
934945#ifdef RT_USING_UTEST
935946 if (utest_get_tc_num () > 0 )
936- {
947+ {
937948 /* Ensure utest initialization is complete */
938949 msh_utest_list_complete (prefix );
939950 }
@@ -972,7 +983,7 @@ void msh_auto_complete(char *prefix)
972983 rt_strncpy (prefix , name_ptr , min_length );
973984 }
974985
975- return ;
986+ return ;
976987}
977988
978989#ifdef FINSH_USING_OPTION_COMPLETION
@@ -994,8 +1005,8 @@ static msh_cmd_opt_t *msh_get_cmd_opt(char *opt_str)
9941005 }
9951006#if defined(FINSH_USING_SYMTAB )
9961007 for (index = _syscall_table_begin ;
997- index < _syscall_table_end ;
998- FINSH_NEXT_SYSCALL (index ))
1008+ index < _syscall_table_end ;
1009+ FINSH_NEXT_SYSCALL (index ))
9991010 {
10001011 if (strncmp (index -> name , opt_str , len ) == 0 && index -> name [len ] == '\0' )
10011012 {
@@ -1126,7 +1137,7 @@ int msh_cmd_opt_id_get(int argc, char *argv[], void *options)
11261137
11271138void msh_opt_list_dump (void * options )
11281139{
1129- msh_cmd_opt_t * opt = (msh_cmd_opt_t * ) options ;
1140+ msh_cmd_opt_t * opt = (msh_cmd_opt_t * )options ;
11301141
11311142 for (; opt && opt -> id ; opt ++ )
11321143 {
0 commit comments