mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 11:16:47 +00:00
bugfix: 修复shell中,用户可以删除多余的字符的bug,以及\b会被录入到参数字符串的bug
This commit is contained in:
parent
37669ebf87
commit
156c2c2389
@ -141,11 +141,19 @@ int shell_cmd_cd(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto fail;; // 出错则直接忽略
|
goto fail;
|
||||||
|
; // 出错则直接忽略
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int new_len = current_dir_len + dest_len;
|
int dest_offset = 0;
|
||||||
|
if (dest_len > 2)
|
||||||
|
{
|
||||||
|
if (argv[1][0] == '.' && argv[1][1] == '/') // 相对路径
|
||||||
|
dest_offset = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int new_len = current_dir_len + dest_len - dest_offset;
|
||||||
// ======进入相对路径=====
|
// ======进入相对路径=====
|
||||||
if (new_len >= SHELL_CWD_MAX_SIZE - 1)
|
if (new_len >= SHELL_CWD_MAX_SIZE - 1)
|
||||||
{
|
{
|
||||||
@ -160,7 +168,7 @@ int shell_cmd_cd(int argc, char **argv)
|
|||||||
|
|
||||||
if (current_dir_len > 1)
|
if (current_dir_len > 1)
|
||||||
new_path[current_dir_len] = '/';
|
new_path[current_dir_len] = '/';
|
||||||
strcat(new_path, argv[1]);
|
strcat(new_path, argv[1] + dest_offset);
|
||||||
|
|
||||||
if (chdir(new_path) == 0) // 成功切换目录
|
if (chdir(new_path) == 0) // 成功切换目录
|
||||||
{
|
{
|
||||||
|
@ -65,7 +65,6 @@ static void main_loop(int kb_fd)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
if (cmd_num >= 0)
|
if (cmd_num >= 0)
|
||||||
shell_run_built_in_command(cmd_num, argc, argv);
|
shell_run_built_in_command(cmd_num, argc, argv);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -104,8 +103,20 @@ int shell_readline(int fd, char *buf)
|
|||||||
|
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
buf[count++] = key;
|
if (key == '\b')
|
||||||
printf("%c", key);
|
{
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
buf[--count] = 0;
|
||||||
|
printf("%c", '\b');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buf[count++] = key;
|
||||||
|
|
||||||
|
printf("%c", key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输入缓冲区满了之后,直接返回
|
// 输入缓冲区满了之后,直接返回
|
||||||
|
Loading…
x
Reference in New Issue
Block a user