Skip to content

Commit

Permalink
为了方便测试,实现几个小命令
Browse files Browse the repository at this point in the history
  • Loading branch information
frapples committed Dec 21, 2016
1 parent ecc4560 commit 8381112
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions shell_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,61 @@ int cmd_pwd(int argc, char* argv[])

int cmd_cd(int argc, char* argv[])
{
printf("%d\n", argc);
if (argc <= 0) {
printf("命令有误\n");
return -1;
}

for (int i = 0; i < argc; i++) {
printf("[%s]\n", argv[i]);
if (fs_chdir(argv[0]) == FS_SUCCESS) {
return 0;
} else {
printf("改变失败,可能目录不存在\n");
return -1;
}
return 0;

}

int cmd_ls(int argc, char* argv[])
{
const char* path;
char wd[FS_MAX_FILE_PATH];
if (argc <= 0) {
fs_getcwd(wd, FS_MAX_FILE_PATH);
path = wd;
} else {
path = argv[0];
}

FS_DIR* dir = fs_opendir(path);
if (dir == NULL) {
printf("列出目录信息失败\n");
}

char name[32];
do {
fs_readdir(dir, name);
printf("%s ", name);
} while(name[0] != '\0');
printf("\n");

fs_closedir(dir);

return 0;
}

int cmd_mkdir(int argc, char* argv[])
{
return 0;
if (argc <= 0) {
printf("命令有误\n");
return -1;
}

if (fs_mkdir(argv[0]) == FS_SUCCESS) {
return 0;
} else {
printf("建立失败\n");
return -1;
}
}

int cmd_rmdir(int argc, char* argv[])
Expand Down

0 comments on commit 8381112

Please sign in to comment.