123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #include "cmd.h"
- #include <libc/string.h>
- #include <libc/stdio.h>
- #include <libc/stddef.h>
- char *shell_current_path = NULL;
- struct built_in_cmd_t shell_cmds[] =
- {
- {"cd", shell_cmd_cd},
- {"cat", shell_cmd_cat},
- {"exec", shell_cmd_exec},
- {"ls", shell_cmd_ls},
- {"mkdir", shell_cmd_mkdir},
- {"pwd", shell_cmd_pwd},
- {"rm", shell_cmd_rm},
- {"rmdir", shell_cmd_rmdir},
- {"reboot", shell_cmd_reboot},
- {"touch", shell_cmd_touch},
- };
- const static int total_built_in_cmd_num = sizeof(shell_cmds) / sizeof(struct built_in_cmd_t);
- int shell_find_cmd(char *main_cmd)
- {
- for (int i = 0; i < total_built_in_cmd_num; ++i)
- {
- if (strcmp(main_cmd, shell_cmds[i].name) == 0)
- return i;
- }
-
- return -1;
- }
- void shell_run_built_in_command(int index, int argc, char **argv)
- {
- if (index >= total_built_in_cmd_num)
- return;
-
- shell_cmds[index].func(argc, argv);
- }
- int shell_cmd_cd(int argc, char **argv) {}
- int shell_cmd_ls(int argc, char **argv) {}
- int shell_cmd_pwd(int argc, char **argv)
- {
- if (shell_current_path)
- printf("%s\n", shell_current_path);
- }
- int shell_cmd_cat(int argc, char **argv) {}
- int shell_cmd_touch(int argc, char **argv) {}
- int shell_cmd_rm(int argc, char **argv) {}
- int shell_cmd_mkdir(int argc, char **argv) {}
- int shell_cmd_rmdir(int argc, char **argv) {}
- int shell_cmd_exec(int argc, char **argv) {}
- int shell_cmd_reboot(int argc, char **argv) {}
|