X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcommand.c;h=b57f8dfc81f5d40e8686208d8b2613c7dc95fb25;hb=168f7cfe562001d5d7c2c724b8232a1dfb2d3463;hp=c3966484f9a87eaf7b4d2b04f633b0e4665ee157;hpb=62c3ae7c6ef215b1afa614abdf61acf077752207;p=u-boot diff --git a/common/command.c b/common/command.c index c3966484f9..b57f8dfc81 100644 --- a/common/command.c +++ b/common/command.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2000-2003 + * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this @@ -38,8 +38,8 @@ do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) U_BOOT_CMD( version, 1, 1, do_version, - "version - print monitor version\n", - NULL + "print monitor version", + "" ); #if defined(CONFIG_CMD_ECHO) @@ -71,9 +71,9 @@ do_echo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) U_BOOT_CMD( echo, CONFIG_SYS_MAXARGS, 1, do_echo, - "echo - echo args to console\n", + "echo args to console", "[args..]\n" - " - echo args to console; \\c suppresses newline\n" + " - echo args to console; \\c suppresses newline" ); #endif @@ -203,9 +203,8 @@ do_test (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) U_BOOT_CMD( test, CONFIG_SYS_MAXARGS, 1, do_test, - "test - minimal test like /bin/sh\n", - "[args..]\n" - " - test functionality\n" + "minimal test like /bin/sh", + "[args..]" ); int @@ -222,8 +221,8 @@ do_exit (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) U_BOOT_CMD( exit, 2, 1, do_exit, - "exit - exit script\n", - " - exit functionality\n" + "exit script", + "" ); @@ -233,20 +232,19 @@ U_BOOT_CMD( * Use puts() instead of printf() to avoid printf buffer overflow * for long help messages */ -int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) + +int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int + flag, int argc, char *argv[]) { int i; int rcode = 0; if (argc == 1) { /*show list of commands */ - - int cmd_items = &__u_boot_cmd_end - - &__u_boot_cmd_start; /* pointer arith! */ cmd_tbl_t *cmd_array[cmd_items]; int i, j, swaps; /* Make array of commands from .uboot_cmd section */ - cmdtp = &__u_boot_cmd_start; + cmdtp = cmd_start; for (i = 0; i < cmd_items; i++) { cmd_array[i] = cmdtp++; } @@ -277,7 +275,8 @@ int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 1; if (usage == NULL) continue; - puts (usage); + printf("%-*s- %s\n", CONFIG_SYS_HELP_CMD_WIDTH, + cmd_array[i]->name, usage); } return 0; } @@ -285,22 +284,8 @@ int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) * command help (long version) */ for (i = 1; i < argc; ++i) { - if ((cmdtp = find_cmd (argv[i])) != NULL) { -#ifdef CONFIG_SYS_LONGHELP - /* found - print (long) help info */ - puts (cmdtp->name); - putc (' '); - if (cmdtp->help) { - puts (cmdtp->help); - } else { - puts ("- No help available.\n"); - rcode = 1; - } - putc ('\n'); -#else /* no long help available */ - if (cmdtp->usage) - puts (cmdtp->usage); -#endif /* CONFIG_SYS_LONGHELP */ + if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) { + rcode |= cmd_usage(cmdtp); } else { printf ("Unknown command '%s' - try 'help'" " without arguments for list of all" @@ -312,29 +297,36 @@ int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return rcode; } +int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) +{ + return _do_help(&__u_boot_cmd_start, + &__u_boot_cmd_end - &__u_boot_cmd_start, + cmdtp, flag, argc, argv); +} + U_BOOT_CMD( help, CONFIG_SYS_MAXARGS, 1, do_help, - "help - print online help\n", + "print online help", "[command ...]\n" " - show help information (for 'command')\n" "'help' prints online help for the monitor commands.\n\n" "Without arguments, it prints a short usage message for all commands.\n\n" "To get detailed help information for specific commands you can type\n" - "'help' with one or more command names as arguments.\n" + "'help' with one or more command names as arguments." ); -/* This do not ust the U_BOOT_CMD macro as ? can't be used in symbol names */ +/* This does not use the U_BOOT_CMD macro as ? can't be used in symbol names */ #ifdef CONFIG_SYS_LONGHELP cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = { "?", CONFIG_SYS_MAXARGS, 1, do_help, - "? - alias for 'help'\n", - NULL + "alias for 'help'", + "" }; #else cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = { "?", CONFIG_SYS_MAXARGS, 1, do_help, - "? - alias for 'help'\n" + "alias for 'help'" }; #endif /* CONFIG_SYS_LONGHELP */ @@ -379,9 +371,22 @@ cmd_tbl_t *find_cmd (const char *cmd) return find_cmd_tbl(cmd, &__u_boot_cmd_start, len); } -void cmd_usage(cmd_tbl_t *cmdtp) +int cmd_usage(cmd_tbl_t *cmdtp) { - printf("Usage:\n%s\n", cmdtp->usage); + printf("%s - %s\n\n", cmdtp->name, cmdtp->usage); + +#ifdef CONFIG_SYS_LONGHELP + printf("Usage:\n%s ", cmdtp->name); + + if (!cmdtp->help) { + puts ("- No additional help available.\n"); + return 1; + } + + puts (cmdtp->help); + putc ('\n'); +#endif /* CONFIG_SYS_LONGHELP */ + return 0; } #ifdef CONFIG_AUTO_COMPLETE