From 156c2c238962d7ce9eb93ade824acf2500708b2d Mon Sep 17 00:00:00 2001 From: fslongjin Date: Wed, 25 May 2022 23:18:30 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8Dshell=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=88=B7=E5=8F=AF=E4=BB=A5=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E5=AD=97=E7=AC=A6=E7=9A=84bug?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A\b=E4=BC=9A=E8=A2=AB=E5=BD=95?= =?UTF-8?q?=E5=85=A5=E5=88=B0=E5=8F=82=E6=95=B0=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/apps/shell/cmd.c | 14 +++++++++++--- user/apps/shell/shell.c | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index 43d09390..7d868b2f 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -141,11 +141,19 @@ int shell_cmd_cd(int argc, char **argv) return 0; } else - goto fail;; // 出错则直接忽略 + goto fail; + ; // 出错则直接忽略 } 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) { @@ -160,7 +168,7 @@ int shell_cmd_cd(int argc, char **argv) if (current_dir_len > 1) new_path[current_dir_len] = '/'; - strcat(new_path, argv[1]); + strcat(new_path, argv[1] + dest_offset); if (chdir(new_path) == 0) // 成功切换目录 { diff --git a/user/apps/shell/shell.c b/user/apps/shell/shell.c index a2e2624b..070adbc1 100644 --- a/user/apps/shell/shell.c +++ b/user/apps/shell/shell.c @@ -65,7 +65,6 @@ static void main_loop(int kb_fd) printf("\n"); if (cmd_num >= 0) shell_run_built_in_command(cmd_num, argc, argv); - } else printf("\n"); @@ -104,8 +103,20 @@ int shell_readline(int fd, char *buf) if (key) { - buf[count++] = key; - printf("%c", key); + if (key == '\b') + { + if (count > 0) + { + buf[--count] = 0; + printf("%c", '\b'); + } + } + else + { + buf[count++] = key; + + printf("%c", key); + } } // 输入缓冲区满了之后,直接返回