[tyndur-devel] [PATCH 2/5] shell: Kommandozeile nicht mehr an Builtin-Befehle weitergeben
Kevin Wolf ·
* shell: Auch eingebaute Befehle sollten einfach argc/argv benutzen wie alles andere auch. Es gibt keinen Grund, die Kommandozeile in der Implementierung des Befehls zu parsen. Signed-off-by: Kevin Wolf <kevin at tyndur.org> --- src/modules/c/shell/cmds/bench.c | 2 +- src/modules/c/shell/cmds/bincat.c | 2 +- src/modules/c/shell/cmds/cat.c | 2 +- src/modules/c/shell/cmds/cp.c | 2 +- src/modules/c/shell/cmds/date.c | 2 +- src/modules/c/shell/cmds/dbg_st.c | 2 +- src/modules/c/shell/cmds/echo.c | 2 +- src/modules/c/shell/cmds/free.c | 2 +- src/modules/c/shell/cmds/kill.c | 2 +- src/modules/c/shell/cmds/killall.c | 2 +- src/modules/c/shell/cmds/ln.c | 2 +- src/modules/c/shell/cmds/ls.c | 2 +- src/modules/c/shell/cmds/mkdir.c | 2 +- src/modules/c/shell/cmds/pipe.c | 2 +- src/modules/c/shell/cmds/ps.c | 2 +- src/modules/c/shell/cmds/pstree.c | 2 +- src/modules/c/shell/cmds/pwd.c | 2 +- src/modules/c/shell/cmds/read.c | 2 +- src/modules/c/shell/cmds/readlink.c | 2 +- src/modules/c/shell/cmds/rm.c | 2 +- src/modules/c/shell/cmds/sleep.c | 2 +- src/modules/c/shell/cmds/stat.c | 2 +- src/modules/c/shell/cmds/symlink.c | 2 +- src/modules/c/shell/cmds/sync.c | 2 +- src/modules/c/shell/commands.c | 26 +++++++------- src/modules/c/shell/shell.c | 4 +-- src/modules/c/shell/shell.h | 68 ++++++++++++++++++------------------- 27 files changed, 72 insertions(+), 74 deletions(-) diff --git a/src/modules/c/shell/cmds/bench.c b/src/modules/c/shell/cmds/bench.c index fae16fe..f6fde4b 100644 --- a/src/modules/c/shell/cmds/bench.c +++ b/src/modules/c/shell/cmds/bench.c @@ -49,7 +49,7 @@ static void usage(void) } #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_bench(int argc, char* argv[], const char* args) + int shell_command_bench(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/bincat.c b/src/modules/c/shell/cmds/bincat.c index 71b8b4b..a228e58 100644 --- a/src/modules/c/shell/cmds/bincat.c +++ b/src/modules/c/shell/cmds/bincat.c @@ -48,7 +48,7 @@ void bincat_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_bincat(int argc, char* argv[], const char* args) + int shell_command_bincat(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/cat.c b/src/modules/c/shell/cmds/cat.c index bf5d9bb..87f4358 100644 --- a/src/modules/c/shell/cmds/cat.c +++ b/src/modules/c/shell/cmds/cat.c @@ -45,7 +45,7 @@ void cat_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_cat(int argc, char* argv[], const char* args) + int shell_command_cat(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/cp.c b/src/modules/c/shell/cmds/cp.c index 6c0803b..cd58601 100644 --- a/src/modules/c/shell/cmds/cp.c +++ b/src/modules/c/shell/cmds/cp.c @@ -56,7 +56,7 @@ int cp_file(char* src_path, char* dst_path); int cp_recursive(char* src_path, char* dst_path); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_cp(int argc, char* argv[], const char* args) + int shell_command_cp(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/date.c b/src/modules/c/shell/cmds/date.c index a6759ca..7ecdd8e 100644 --- a/src/modules/c/shell/cmds/date.c +++ b/src/modules/c/shell/cmds/date.c @@ -43,7 +43,7 @@ void date_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_date(int argc, char* argv[], const char* args) + int shell_command_date(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/dbg_st.c b/src/modules/c/shell/cmds/dbg_st.c index 1089759..c87b900 100644 --- a/src/modules/c/shell/cmds/dbg_st.c +++ b/src/modules/c/shell/cmds/dbg_st.c @@ -46,7 +46,7 @@ void dbg_st_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_dbg_st(int argc, char* argv[], const char* args) + int shell_command_dbg_st(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/echo.c b/src/modules/c/shell/cmds/echo.c index a51edf2..d3b7262 100644 --- a/src/modules/c/shell/cmds/echo.c +++ b/src/modules/c/shell/cmds/echo.c @@ -40,7 +40,7 @@ #include <tms.h> #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_echo(int argc, char* argv[], const char* args) + int shell_command_echo(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/free.c b/src/modules/c/shell/cmds/free.c index d4e7d0e..5d79ef7 100644 --- a/src/modules/c/shell/cmds/free.c +++ b/src/modules/c/shell/cmds/free.c @@ -40,7 +40,7 @@ #include <tms.h> #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_free(int argc, char* argv[], const char* args) + int shell_command_free(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/kill.c b/src/modules/c/shell/cmds/kill.c index 0efb567..7aa8029 100644 --- a/src/modules/c/shell/cmds/kill.c +++ b/src/modules/c/shell/cmds/kill.c @@ -45,7 +45,7 @@ static void kill_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_kill(int argc, char* argv[], const char* args) + int shell_command_kill(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/killall.c b/src/modules/c/shell/cmds/killall.c index f14b7a4..d76b437 100644 --- a/src/modules/c/shell/cmds/killall.c +++ b/src/modules/c/shell/cmds/killall.c @@ -46,7 +46,7 @@ static void killall_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_killall(int argc, char* argv[], const char* args) + int shell_command_killall(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/ln.c b/src/modules/c/shell/cmds/ln.c index 2b773eb..4c1b1e2 100644 --- a/src/modules/c/shell/cmds/ln.c +++ b/src/modules/c/shell/cmds/ln.c @@ -44,7 +44,7 @@ void ln_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_ln(int argc, char* argv[], const char* args) + int shell_command_ln(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/ls.c b/src/modules/c/shell/cmds/ls.c index 838ae9a..37076e1 100644 --- a/src/modules/c/shell/cmds/ls.c +++ b/src/modules/c/shell/cmds/ls.c @@ -53,7 +53,7 @@ void ls_display_usage(void); char* format_size(size_t size, bool human_readable); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_ls(int argc, char* argv[], const char* args) + int shell_command_ls(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/mkdir.c b/src/modules/c/shell/cmds/mkdir.c index 38c4598..a6aadf7 100644 --- a/src/modules/c/shell/cmds/mkdir.c +++ b/src/modules/c/shell/cmds/mkdir.c @@ -44,7 +44,7 @@ void mkdir_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_mkdir(int argc, char* argv[], const char* args) + int shell_command_mkdir(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/pipe.c b/src/modules/c/shell/cmds/pipe.c index e7d7ff4..b346c90 100644 --- a/src/modules/c/shell/cmds/pipe.c +++ b/src/modules/c/shell/cmds/pipe.c @@ -44,7 +44,7 @@ void pipe_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_pipe(int argc, char* argv[], const char* args) + int shell_command_pipe(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/ps.c b/src/modules/c/shell/cmds/ps.c index ec6e152..dae0618 100644 --- a/src/modules/c/shell/cmds/ps.c +++ b/src/modules/c/shell/cmds/ps.c @@ -45,7 +45,7 @@ void ps_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_ps(int argc, char* argv[], const char* args) + int shell_command_ps(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/pstree.c b/src/modules/c/shell/cmds/pstree.c index 8420902..d1be08d 100644 --- a/src/modules/c/shell/cmds/pstree.c +++ b/src/modules/c/shell/cmds/pstree.c @@ -47,7 +47,7 @@ void pstree_show_children(pid_t pid, uint8_t depth); task_info_t* task_info; #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_pstree(int argc, char* argv[], const char* args) + int shell_command_pstree(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/pwd.c b/src/modules/c/shell/cmds/pwd.c index ed5cea8..db059ad 100644 --- a/src/modules/c/shell/cmds/pwd.c +++ b/src/modules/c/shell/cmds/pwd.c @@ -43,7 +43,7 @@ void pwd_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_pwd(int argc, char* argv[], const char* args) + int shell_command_pwd(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/read.c b/src/modules/c/shell/cmds/read.c index 4a0414c..7093c58 100644 --- a/src/modules/c/shell/cmds/read.c +++ b/src/modules/c/shell/cmds/read.c @@ -47,7 +47,7 @@ static void read_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_read(int argc, char* argv[], const char* args) + int shell_command_read(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/readlink.c b/src/modules/c/shell/cmds/readlink.c index 51ef146..5be342c 100644 --- a/src/modules/c/shell/cmds/readlink.c +++ b/src/modules/c/shell/cmds/readlink.c @@ -44,7 +44,7 @@ void readlink_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_readlink(int argc, char* argv[], const char* args) + int shell_command_readlink(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/rm.c b/src/modules/c/shell/cmds/rm.c index 91bb0c0..954d6fb 100644 --- a/src/modules/c/shell/cmds/rm.c +++ b/src/modules/c/shell/cmds/rm.c @@ -56,7 +56,7 @@ enum { }; #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_rm(int argc, char* argv[], const char* args) + int shell_command_rm(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/sleep.c b/src/modules/c/shell/cmds/sleep.c index a85dd8b..dad8dbd 100644 --- a/src/modules/c/shell/cmds/sleep.c +++ b/src/modules/c/shell/cmds/sleep.c @@ -44,7 +44,7 @@ void sleep_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_sleep(int argc, char* argv[], const char* args) + int shell_command_sleep(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/stat.c b/src/modules/c/shell/cmds/stat.c index 1a5436d..55c169d 100644 --- a/src/modules/c/shell/cmds/stat.c +++ b/src/modules/c/shell/cmds/stat.c @@ -45,7 +45,7 @@ void stat_display_usage(void); void stat_display_results(const char* path, struct stat* stat_buf); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_stat(int argc, char* argv[], const char* args) + int shell_command_stat(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/symlink.c b/src/modules/c/shell/cmds/symlink.c index b9886f4..aa92d18 100644 --- a/src/modules/c/shell/cmds/symlink.c +++ b/src/modules/c/shell/cmds/symlink.c @@ -45,7 +45,7 @@ void symlink_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_symlink(int argc, char* argv[], const char* args) + int shell_command_symlink(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/cmds/sync.c b/src/modules/c/shell/cmds/sync.c index 8a322f8..d24e789 100644 --- a/src/modules/c/shell/cmds/sync.c +++ b/src/modules/c/shell/cmds/sync.c @@ -41,7 +41,7 @@ static void sync_display_usage(void); #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_sync(int argc, char* argv[], const char* args) + int shell_command_sync(int argc, char* argv[]) #else int main(int argc, char* argv[]) #endif diff --git a/src/modules/c/shell/commands.c b/src/modules/c/shell/commands.c index c36f577..9d0055a 100644 --- a/src/modules/c/shell/commands.c +++ b/src/modules/c/shell/commands.c @@ -98,10 +98,10 @@ static int shell_start_path_app(char* argv[], bool wait) /** * Wird aufgerufen, wenn keiner der internen Befehle passt. */ -int shell_command_default(int argc, char* argv[], const char* cmd) +int shell_command_default(int argc, char* argv[]) { // Leere Kommandozeilen sollen keine Fehlermeldungen bringen - if (strlen(cmd) == 0) { + if (argc == 0) { return 0; } @@ -116,7 +116,7 @@ int shell_command_default(int argc, char* argv[], const char* cmd) /** * Eine ausfuerbare Datei im aktuellen Verzeichnis oder in PATH starten. */ -int shell_command_start(int argc, char* argv[], const char* cmd) +int shell_command_start(int argc, char* argv[]) { DEBUG_MSG("start"); @@ -137,7 +137,7 @@ int shell_command_start(int argc, char* argv[], const char* cmd) /** * */ -int shell_command_help(int argc, char* argv[], const char* args) +int shell_command_help(int argc, char* argv[]) { char** thelp_args; int ret; @@ -208,7 +208,7 @@ int shell_command_help(int argc, char* argv[], const char* args) /** * */ -int shell_command_version(int argc, char* argv[], const char* args) +int shell_command_version(int argc, char* argv[]) { puts("tyndur Shell " TYNDUR_VERSION); return 0; @@ -217,24 +217,22 @@ int shell_command_version(int argc, char* argv[], const char* args) /** * */ -int shell_command_exit(int argc, char* argv[], const char* args) +int shell_command_exit(int argc, char* argv[]) { exit(0); return 0; } -int shell_command_cd(int argc, char* argv[], const char* args) +int shell_command_cd(int argc, char* argv[]) { - char* cd_args = strchr(args, ' '); char* path; DIR* dir; - if (cd_args == NULL) { + if (argc != 2) { goto usage; } - cd_args++; - path = io_get_absolute_path(cd_args); + path = io_get_absolute_path(argv[1]); if (path == NULL) { goto usage; } @@ -256,7 +254,7 @@ usage: return -1; } -int shell_command_source(int argc, char* argv[], const char* args) +int shell_command_source(int argc, char* argv[]) { const char* path; if (argc != 2) { @@ -274,7 +272,7 @@ int shell_command_source(int argc, char* argv[], const char* args) } } -int shell_command_clear(int argc, char* argv[], const char* args) +int shell_command_clear(int argc, char* argv[]) { printf("\033[1;1H\033[2J"); @@ -284,7 +282,7 @@ int shell_command_clear(int argc, char* argv[], const char* args) void set_display_usage(void); void set_list_vars(void); -int shell_command_set(int argc, char* argv[], const char* args) +int shell_command_set(int argc, char* argv[]) { int overwrite = 1; diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index b7ed005..4e07707 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -304,10 +304,10 @@ int shell_do_cmd(void) { command = &shell_commands[i]; if (shell_match_command(command->name, cmdstring) == true) { - return command->handler(argc, argv, cmdstring); + return command->handler(argc, argv); } } - return shell_command_default(argc, argv, cmdstring); + return shell_command_default(argc, argv); } /** * Shell-Skript ausfuehren diff --git a/src/modules/c/shell/shell.h b/src/modules/c/shell/shell.h index 8e94409..f119b63 100644 --- a/src/modules/c/shell/shell.h +++ b/src/modules/c/shell/shell.h @@ -38,7 +38,7 @@ typedef struct shell_command_t { const char* name; - int (*handler)(int argc, char* argv[], const char* args); + int (*handler)(int argc, char* argv[]); } shell_command_t; /** Array mit den Befehlen */ @@ -49,43 +49,43 @@ bool shell_script(const char* path); bool shell_match_command(const char* cmd, const char* cmdline); void completion_init(void); -int shell_command_default(int argc, char* argv[], const char* args); -int shell_command_help(int argc, char* argv[], const char* args); -int shell_command_version(int argc, char* argv[], const char* args); -int shell_command_exit(int argc, char* argv[], const char* args); -int shell_command_start(int argc, char* argv[], const char* args); -int shell_command_cd(int argc, char* argv[], const char* args); -int shell_command_set(int argc, char* argv[], const char* args); -int shell_command_source(int argc, char* argv[], const char* args); -int shell_command_clear(int argc, char* argv[], const char* args); +int shell_command_default(int argc, char* argv[]); +int shell_command_help(int argc, char* argv[]); +int shell_command_version(int argc, char* argv[]); +int shell_command_exit(int argc, char* argv[]); +int shell_command_start(int argc, char* argv[]); +int shell_command_cd(int argc, char* argv[]); +int shell_command_set(int argc, char* argv[]); +int shell_command_source(int argc, char* argv[]); +int shell_command_clear(int argc, char* argv[]); #include <lost/config.h> #ifdef CONFIG_SHELL_BUILTIN_ONLY - int shell_command_bincat(int argc, char* argv[], const char* args); - int shell_command_cat(int argc, char* argv[], const char* args); - int shell_command_date(int argc, char* argv[], const char* args); - int shell_command_echo(int argc, char* argv[], const char* args); - int shell_command_free(int argc, char* argv[], const char* args); - int shell_command_kill(int argc, char* argv[], const char* args); - int shell_command_killall(int argc, char* argv[], const char* args); - int shell_command_ls(int argc, char* argv[], const char* args); - int shell_command_mkdir(int argc, char* argv[], const char* args); - int shell_command_pipe(int argc, char* argv[], const char* args); - int shell_command_ps(int argc, char* argv[], const char* args); - int shell_command_pstree(int argc, char* argv[], const char* args); - int shell_command_pwd(int argc, char* argv[], const char* args); - int shell_command_symlink(int argc, char* argv[], const char* args); - int shell_command_readlink(int argc, char* argv[], const char* args); - int shell_command_dbg_st(int argc, char* argv[], const char* args); - int shell_command_cp(int argc, char* argv[], const char* args); - int shell_command_ln(int argc, char* argv[], const char* args); - int shell_command_rm(int argc, char* argv[], const char* args); - int shell_command_stat(int argc, char* argv[], const char* args); - int shell_command_sleep(int argc, char* argv[], const char* args); - int shell_command_bench(int argc, char* argv[], const char* args); - int shell_command_read(int argc, char* argv[], const char* args); - int shell_command_sync(int argc, char* argv[], const char* args); + int shell_command_bincat(int argc, char* argv[]); + int shell_command_cat(int argc, char* argv[]); + int shell_command_date(int argc, char* argv[]); + int shell_command_echo(int argc, char* argv[]); + int shell_command_free(int argc, char* argv[]); + int shell_command_kill(int argc, char* argv[]); + int shell_command_killall(int argc, char* argv[]); + int shell_command_ls(int argc, char* argv[]); + int shell_command_mkdir(int argc, char* argv[]); + int shell_command_pipe(int argc, char* argv[]); + int shell_command_ps(int argc, char* argv[]); + int shell_command_pstree(int argc, char* argv[]); + int shell_command_pwd(int argc, char* argv[]); + int shell_command_symlink(int argc, char* argv[]); + int shell_command_readlink(int argc, char* argv[]); + int shell_command_dbg_st(int argc, char* argv[]); + int shell_command_cp(int argc, char* argv[]); + int shell_command_ln(int argc, char* argv[]); + int shell_command_rm(int argc, char* argv[]); + int shell_command_stat(int argc, char* argv[]); + int shell_command_sleep(int argc, char* argv[]); + int shell_command_bench(int argc, char* argv[]); + int shell_command_read(int argc, char* argv[]); + int shell_command_sync(int argc, char* argv[]); #endif #endif -- 2.1.4