1
1
/*
2
- * Copyright (c) 2006-2022 , RT-Thread Development Team
2
+ * Copyright (c) 2006-2025 , RT-Thread Development Team
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*
17
17
#ifdef RT_USING_FINSH
18
18
19
19
#ifndef FINSH_ARG_MAX
20
- #define FINSH_ARG_MAX 8
20
+ #define FINSH_ARG_MAX 8
21
21
#endif /* FINSH_ARG_MAX */
22
22
23
23
#include "msh.h"
@@ -40,16 +40,16 @@ static int msh_help(int argc, char **argv)
40
40
struct finsh_syscall * index ;
41
41
#if defined(FINSH_USING_SYMTAB )
42
42
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 ))
45
45
{
46
46
#if defined(FINSH_USING_DESCRIPTION )
47
47
rt_kprintf ("%-16s - %s\n" , index -> name , index -> desc );
48
48
#else
49
49
rt_kprintf ("%s " , index -> name );
50
- #endif /* FINSH_USING_DESCRIPTION */
50
+ #endif /* FINSH_USING_DESCRIPTION */
51
51
}
52
- #endif /* FINSH_USING_SYMTAB */
52
+ #endif /* FINSH_USING_SYMTAB */
53
53
}
54
54
rt_kprintf ("\n" );
55
55
@@ -61,14 +61,14 @@ MSH_CMD_EXPORT_ALIAS(msh_help, help, RT-Thread shell help);
61
61
static int cmd_ps (int argc , char * * argv )
62
62
{
63
63
extern long list_thread (void );
64
- extern int list_module (void );
64
+ extern int list_module (void );
65
65
66
66
#ifdef RT_USING_MODULE
67
67
if ((argc == 2 ) && (strcmp (argv [1 ], "-m" ) == 0 ))
68
68
list_module ();
69
69
else
70
70
#endif
71
- list_thread ();
71
+ list_thread ();
72
72
return 0 ;
73
73
}
74
74
MSH_CMD_EXPORT_ALIAS (cmd_ps , ps , List threads in the system );
@@ -136,12 +136,12 @@ static int cmd_bind(int argc, char **argv)
136
136
if (result == RT_EOK )
137
137
{
138
138
rt_kprintf ("Thread 0x%lx bound to core %d successfully\n" ,
139
- thread_id , core_id );
139
+ thread_id , core_id );
140
140
}
141
141
else
142
142
{
143
143
rt_kprintf ("Failed to bind thread 0x%lx to core %d\n" ,
144
- thread_id , core_id );
144
+ thread_id , core_id );
145
145
}
146
146
return 0 ;
147
147
}
@@ -167,8 +167,8 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX])
167
167
while ((* ptr == ' ' || * ptr == '\t' ) && position < length )
168
168
{
169
169
* ptr = '\0' ;
170
- ptr ++ ;
171
- position ++ ;
170
+ ptr ++ ;
171
+ position ++ ;
172
172
}
173
173
174
174
if (argc >= FINSH_ARG_MAX )
@@ -182,15 +182,16 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX])
182
182
break ;
183
183
}
184
184
185
- if (position >= length ) break ;
185
+ if (position >= length )
186
+ break ;
186
187
187
188
/* handle string */
188
189
if (* ptr == '"' )
189
190
{
190
- ptr ++ ;
191
- position ++ ;
191
+ ptr ++ ;
192
+ position ++ ;
192
193
argv [argc ] = ptr ;
193
- argc ++ ;
194
+ argc ++ ;
194
195
195
196
/* skip this string */
196
197
while (* ptr != '"' && position < length )
@@ -199,30 +200,32 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX])
199
200
{
200
201
if (* (ptr + 1 ) == '"' )
201
202
{
202
- ptr ++ ;
203
- position ++ ;
203
+ ptr ++ ;
204
+ position ++ ;
204
205
}
205
206
}
206
- ptr ++ ;
207
- position ++ ;
207
+ ptr ++ ;
208
+ position ++ ;
208
209
}
209
- if (position >= length ) break ;
210
+ if (position >= length )
211
+ break ;
210
212
211
213
/* skip '"' */
212
214
* ptr = '\0' ;
213
- ptr ++ ;
214
- position ++ ;
215
+ ptr ++ ;
216
+ position ++ ;
215
217
}
216
218
else
217
219
{
218
220
argv [argc ] = ptr ;
219
- argc ++ ;
221
+ argc ++ ;
220
222
while ((* ptr != ' ' && * ptr != '\t' ) && position < length )
221
223
{
222
- ptr ++ ;
223
- position ++ ;
224
+ ptr ++ ;
225
+ position ++ ;
224
226
}
225
- if (position >= length ) break ;
227
+ if (position >= length )
228
+ break ;
226
229
}
227
230
}
228
231
@@ -235,11 +238,10 @@ static cmd_function_t msh_get_cmd(char *cmd, int size)
235
238
cmd_function_t cmd_func = RT_NULL ;
236
239
#if defined(FINSH_USING_SYMTAB )
237
240
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 ))
240
243
{
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' )
243
245
{
244
246
cmd_func = (cmd_function_t )index -> func ;
245
247
break ;
@@ -263,13 +265,13 @@ int msh_exec_module(const char *cmd_line, int size)
263
265
return - RT_ERROR ;
264
266
/* get the length of command0 */
265
267
while ((cmd_line [cmd_length ] != ' ' && cmd_line [cmd_length ] != '\t' ) && cmd_length < size )
266
- cmd_length ++ ;
268
+ cmd_length ++ ;
267
269
268
270
/* get name length */
269
271
length = cmd_length + 32 ;
270
272
271
273
/* allocate program name memory */
272
- pg_name = (char * ) rt_malloc (length + 3 );
274
+ pg_name = (char * )rt_malloc (length + 3 );
273
275
if (pg_name == RT_NULL )
274
276
return - RT_ENOMEM ;
275
277
@@ -334,7 +336,7 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
334
336
335
337
/* find the size of first command */
336
338
while (cmd0_size < length && (cmd [cmd0_size ] != ' ' && cmd [cmd0_size ] != '\t' ))
337
- cmd0_size ++ ;
339
+ cmd0_size ++ ;
338
340
if (cmd0_size == 0 )
339
341
return - RT_ERROR ;
340
342
@@ -488,7 +490,7 @@ int _msh_exec_lwp(int debug, char *cmd, rt_size_t length)
488
490
489
491
/* find the size of first command */
490
492
while ((cmd [cmd0_size ] != ' ' && cmd [cmd0_size ] != '\t' ) && cmd0_size < length )
491
- cmd0_size ++ ;
493
+ cmd0_size ++ ;
492
494
if (cmd0_size == 0 )
493
495
return -1 ;
494
496
@@ -544,7 +546,7 @@ int msh_exec(char *cmd, rt_size_t length)
544
546
int cmd_ret = 0 ;
545
547
546
548
/* strim the beginning of command */
547
- while ((length > 0 ) && (* cmd == ' ' || * cmd == '\t' ))
549
+ while ((length > 0 ) && (* cmd == ' ' || * cmd == '\t' ))
548
550
{
549
551
cmd ++ ;
550
552
length -- ;
@@ -559,7 +561,7 @@ int msh_exec(char *cmd, rt_size_t length)
559
561
*/
560
562
if (_msh_exec_cmd (cmd , length , & cmd_ret ) == 0 )
561
563
{
562
- if (cmd_ret < 0 )
564
+ if (cmd_ret < 0 )
563
565
{
564
566
rt_kprintf ("%s: command failed %d.\n" , cmd , cmd_ret );
565
567
}
@@ -620,8 +622,8 @@ static int str_common(const char *str1, const char *str2)
620
622
621
623
while ((* str != 0 ) && (* str2 != 0 ) && (* str == * str2 ))
622
624
{
623
- str ++ ;
624
- str2 ++ ;
625
+ str ++ ;
626
+ str2 ++ ;
625
627
}
626
628
627
629
return (str - str1 );
@@ -638,34 +640,40 @@ void msh_auto_complete_path(char *path)
638
640
return ;
639
641
640
642
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 */
642
645
643
646
if (* path != '/' )
644
647
{
645
648
getcwd (full_path , 256 );
646
- if (full_path [rt_strlen (full_path ) - 1 ] != '/' )
649
+ if (full_path [rt_strlen (full_path ) - 1 ] != '/' )
647
650
strcat (full_path , "/" );
648
651
}
649
- else * full_path = '\0' ;
652
+ else
653
+ * full_path = '\0' ;
650
654
651
655
index = RT_NULL ;
652
656
ptr = path ;
653
657
for (;;)
654
658
{
655
- if (* ptr == '/' ) index = ptr + 1 ;
656
- if (!* ptr ) break ;
659
+ if (* ptr == '/' )
660
+ index = ptr + 1 ;
661
+ if (!* ptr )
662
+ break ;
657
663
658
- ptr ++ ;
664
+ ptr ++ ;
659
665
}
660
- if (index == RT_NULL ) index = path ;
666
+ if (index == RT_NULL )
667
+ index = path ;
661
668
662
669
if (index != RT_NULL )
663
670
{
664
671
char * dest = index ;
665
672
666
673
/* fill the parent path */
667
674
ptr = full_path ;
668
- while (* ptr ) ptr ++ ;
675
+ while (* ptr )
676
+ ptr ++ ;
669
677
670
678
for (index = path ; index != dest ;)
671
679
* ptr ++ = * index ++ ;
@@ -688,7 +696,8 @@ void msh_auto_complete_path(char *path)
688
696
for (;;)
689
697
{
690
698
dirent = readdir (dir );
691
- if (dirent == RT_NULL ) break ;
699
+ if (dirent == RT_NULL )
700
+ break ;
692
701
693
702
rt_kprintf ("%s\n" , dirent -> d_name );
694
703
}
@@ -702,12 +711,13 @@ void msh_auto_complete_path(char *path)
702
711
for (;;)
703
712
{
704
713
dirent = readdir (dir );
705
- if (dirent == RT_NULL ) break ;
714
+ if (dirent == RT_NULL )
715
+ break ;
706
716
707
717
/* matched the prefix string */
708
718
if (strncmp (index , dirent -> d_name , rt_strlen (index )) == 0 )
709
719
{
710
- multi ++ ;
720
+ multi ++ ;
711
721
if (min_length == 0 )
712
722
{
713
723
min_length = rt_strlen (dirent -> d_name );
@@ -734,7 +744,8 @@ void msh_auto_complete_path(char *path)
734
744
for (;;)
735
745
{
736
746
dirent = readdir (dir );
737
- if (dirent == RT_NULL ) break ;
747
+ if (dirent == RT_NULL )
748
+ break ;
738
749
739
750
if (strncmp (index , dirent -> d_name , rt_strlen (index )) == 0 )
740
751
rt_kprintf ("%s\n" , dirent -> d_name );
@@ -920,7 +931,7 @@ void msh_auto_complete(char *prefix)
920
931
break ;
921
932
}
922
933
923
- ptr -- ;
934
+ ptr -- ;
924
935
}
925
936
#if defined(RT_USING_MODULE ) || defined(RT_USING_SMART )
926
937
/* There is a chance that the user want to run the module directly. So
@@ -933,7 +944,7 @@ void msh_auto_complete(char *prefix)
933
944
#endif /* RT_USING_MODULE */
934
945
#ifdef RT_USING_UTEST
935
946
if (utest_get_tc_num () > 0 )
936
- {
947
+ {
937
948
/* Ensure utest initialization is complete */
938
949
msh_utest_list_complete (prefix );
939
950
}
@@ -972,7 +983,7 @@ void msh_auto_complete(char *prefix)
972
983
rt_strncpy (prefix , name_ptr , min_length );
973
984
}
974
985
975
- return ;
986
+ return ;
976
987
}
977
988
978
989
#ifdef FINSH_USING_OPTION_COMPLETION
@@ -994,8 +1005,8 @@ static msh_cmd_opt_t *msh_get_cmd_opt(char *opt_str)
994
1005
}
995
1006
#if defined(FINSH_USING_SYMTAB )
996
1007
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 ))
999
1010
{
1000
1011
if (strncmp (index -> name , opt_str , len ) == 0 && index -> name [len ] == '\0' )
1001
1012
{
@@ -1126,7 +1137,7 @@ int msh_cmd_opt_id_get(int argc, char *argv[], void *options)
1126
1137
1127
1138
void msh_opt_list_dump (void * options )
1128
1139
{
1129
- msh_cmd_opt_t * opt = (msh_cmd_opt_t * ) options ;
1140
+ msh_cmd_opt_t * opt = (msh_cmd_opt_t * )options ;
1130
1141
1131
1142
for (; opt && opt -> id ; opt ++ )
1132
1143
{
0 commit comments