Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
天中雨水
rt-thread
提交
96d9fd87
R
rt-thread
项目概览
天中雨水
/
rt-thread
该项目与 Fork 源项目分叉
Fork自
RT-Thread / rt-thread
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
96d9fd87
编写于
3月 27, 2014
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #249 from grissiom/msh-next
Msh next
上级
de16b800
c44f32e5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
94 addition
and
50 deletion
+94
-50
components/finsh/msh.c
components/finsh/msh.c
+94
-50
未找到文件。
components/finsh/msh.c
浏览文件 @
96d9fd87
...
...
@@ -178,35 +178,37 @@ static cmd_function_t msh_get_cmd(char *cmd, int size)
}
#if defined(RT_USING_MODULE) && defined(RT_USING_DFS)
/* Return 0 on module executed. Other value indicate error.
*/
int
msh_exec_module
(
char
*
cmd_line
,
int
size
)
{
int
ret
;
int
fd
=
-
1
;
char
*
pg_name
;
int
length
,
cmd_length
=
0
;
if
(
size
==
0
)
return
-
RT_ERROR
;
/* no command */
/* get the length of command0 */
while
((
cmd_line
[
cmd_length
]
!=
' '
&&
cmd_line
[
cmd_length
]
!=
'\t'
)
&&
cmd_length
<
size
)
cmd_length
++
;
if
(
size
==
0
)
return
-
RT_ERROR
;
/* get the length of command0 */
while
((
cmd_line
[
cmd_length
]
!=
' '
&&
cmd_line
[
cmd_length
]
!=
'\t'
)
&&
cmd_length
<
size
)
cmd_length
++
;
/* get name length */
length
=
cmd_length
+
32
;
/* allocate program name memory */
/* allocate program name memory */
pg_name
=
(
char
*
)
rt_malloc
(
length
);
if
(
pg_name
==
RT_NULL
)
return
-
RT_ENOMEM
;
/* no memory */
if
(
pg_name
==
RT_NULL
)
return
-
RT_ENOMEM
;
/* copy command0 */
memcpy
(
pg_name
,
cmd_line
,
cmd_length
);
pg_name
[
cmd_length
]
=
'\0'
;
/* copy command0 */
memcpy
(
pg_name
,
cmd_line
,
cmd_length
);
pg_name
[
cmd_length
]
=
'\0'
;
if
(
strstr
(
pg_name
,
".mo"
)
!=
RT_NULL
||
strstr
(
pg_name
,
".MO"
)
!=
RT_NULL
)
{
/* try to open program */
if
(
fd
<
0
)
{
fd
=
open
(
pg_name
,
O_RDONLY
,
0
);
}
fd
=
open
(
pg_name
,
O_RDONLY
,
0
);
/* search in /bin path */
if
(
fd
<
0
)
...
...
@@ -220,16 +222,13 @@ int msh_exec_module(char* cmd_line, int size)
/* add .mo and open program */
/* try to open program */
if
(
fd
<
0
)
{
strcat
(
pg_name
,
".mo"
);
fd
=
open
(
pg_name
,
O_RDONLY
,
0
);
}
strcat
(
pg_name
,
".mo"
);
fd
=
open
(
pg_name
,
O_RDONLY
,
0
);
/* search in /bin path */
if
(
fd
<
0
)
{
rt_snprintf
(
pg_name
,
length
-
1
,
"/bin/%.*s.mo"
,
cmd_length
,
cmd_line
);
rt_snprintf
(
pg_name
,
length
-
1
,
"/bin/%.*s.mo"
,
cmd_length
,
cmd_line
);
fd
=
open
(
pg_name
,
O_RDONLY
,
0
);
}
}
...
...
@@ -239,57 +238,93 @@ int msh_exec_module(char* cmd_line, int size)
/* found program */
close
(
fd
);
rt_module_exec_cmd
(
pg_name
,
cmd_line
,
size
);
ret
=
0
;
}
else
{
r
t_kprintf
(
"%s: program not found.
\n
"
,
cmd_line
)
;
r
et
=
-
1
;
}
rt_free
(
pg_name
);
return
0
;
return
ret
;
}
#endif
int
msh_exec
(
char
*
cmd
,
rt_size_t
length
)
static
int
_msh_exec_cmd
(
char
*
cmd
,
rt_size_t
length
,
int
*
retp
)
{
int
argc
;
char
*
argv
[
RT_FINSH_ARG_MAX
];
int
cmd0_size
=
0
;
cmd_function_t
cmd_func
;
char
*
argv
[
RT_FINSH_ARG_MAX
];
/* strim the beginning of command */
while
(
*
cmd
==
' '
||
*
cmd
==
'\t'
){
cmd
++
;
length
--
;}
/* find the size of first command */
RT_ASSERT
(
cmd
);
RT_ASSERT
(
retp
);
/* find the size of first command */
while
((
cmd
[
cmd0_size
]
!=
' '
&&
cmd
[
cmd0_size
]
!=
'\t'
)
&&
cmd0_size
<
length
)
cmd0_size
++
;
if
(
cmd0_size
==
0
)
return
-
1
;
/* no command found */
if
(
cmd0_size
==
0
)
return
-
RT_ERROR
;
/* try to get built-in command */
cmd_func
=
msh_get_cmd
(
cmd
,
cmd0_size
);
if
(
cmd_func
==
RT_NULL
)
{
#ifdef RT_USING_MODULE
msh_exec_module
(
cmd
,
length
);
#else
argv
[
0
]
=
cmd
;
while
(
*
cmd
!=
' '
)
{
if
(
*
cmd
==
0
)
break
;
cmd
++
;
}
if
(
*
cmd
==
' '
)
*
cmd
=
0
;
rt_kprintf
(
"%s: command not found.
\n
"
,
argv
[
0
]);
#endif
return
-
1
;
}
return
-
RT_ERROR
;
/* split arguments */
memset
(
argv
,
0x00
,
sizeof
(
argv
));
argc
=
msh_split
(
cmd
,
length
,
argv
);
if
(
argc
==
0
)
return
-
1
;
if
(
argc
==
0
)
return
-
RT_ERROR
;
/* exec this command */
return
cmd_func
(
argc
,
argv
);
*
retp
=
cmd_func
(
argc
,
argv
);
return
0
;
}
int
msh_exec
(
char
*
cmd
,
rt_size_t
length
)
{
int
cmd_ret
;
/* strim the beginning of command */
while
(
*
cmd
==
' '
||
*
cmd
==
'\t'
)
{
cmd
++
;
length
--
;
}
/* Exec sequence:
* 1. built-in command
* 2. module(if enabled)
* 3. chdir to the directry(if possible)
*/
if
(
_msh_exec_cmd
(
cmd
,
length
,
&
cmd_ret
)
==
0
)
{
return
cmd_ret
;
}
#ifdef RT_USING_MODULE
if
(
msh_exec_module
(
cmd
,
length
)
==
0
)
{
return
0
;
}
#endif
#ifdef DFS_USING_WORKDIR
if
(
chdir
(
cmd
)
==
0
)
{
return
0
;
}
#endif
/* truncate the cmd at the first space. */
{
char
*
tcmd
;
tcmd
=
cmd
;
while
(
*
tcmd
!=
' '
&&
*
tcmd
!=
'\0'
)
{
tcmd
++
;
}
*
tcmd
=
'\0'
;
}
rt_kprintf
(
"%s: command not found.
\n
"
,
cmd
);
return
-
1
;
}
static
int
str_common
(
const
char
*
str1
,
const
char
*
str2
)
...
...
@@ -316,7 +351,7 @@ void msh_auto_complete_path(char *path)
if
(
full_path
==
RT_NULL
)
return
;
/* out of memory */
ptr
=
full_path
;
if
(
*
path
!=
'/'
)
if
(
*
path
!=
'/'
)
{
getcwd
(
full_path
,
256
);
if
(
full_path
[
rt_strlen
(
full_path
)
-
1
]
!=
'/'
)
...
...
@@ -336,7 +371,7 @@ void msh_auto_complete_path(char *path)
char
*
dest
=
index
;
/* fill the parent path */
ptr
=
full_path
;
ptr
=
full_path
;
while
(
*
ptr
)
ptr
++
;
for
(
index
=
path
;
index
!=
dest
;)
...
...
@@ -361,7 +396,7 @@ void msh_auto_complete_path(char *path)
{
dirent
=
readdir
(
dir
);
if
(
dirent
==
RT_NULL
)
break
;
rt_kprintf
(
"%s
\n
"
,
dirent
->
d_name
);
}
}
...
...
@@ -450,12 +485,21 @@ void msh_auto_complete(char *prefix)
msh_auto_complete_path
(
ptr
+
1
);
break
;
}
ptr
--
;
}
#ifdef RT_USING_MODULE
/* There is a chance that the user want to run the module directly. So
* try to complete the file names. If the completed path is not a
* module, the system won't crash anyway. */
if
(
ptr
==
prefix
)
{
msh_auto_complete_path
(
ptr
);
}
#endif
}
#endif
/* checks in internal command */
{
for
(
index
=
_syscall_table_begin
;
index
<
_syscall_table_end
;
FINSH_NEXT_SYSCALL
(
index
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录