2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * Command Processor Table
32 do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
34 extern char version_string[];
35 printf ("\n%s\n", version_string);
40 do_echo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
44 for (i = 1; i < argc; i++) {
49 while ((c = *p++) != '\0') {
50 if (c == '\\' && *p == 'c') {
65 * Use puts() instead of printf() to avoid printf buffer overflow
66 * for long help messages
68 int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
73 if (argc == 1) { /*show list of commands */
75 int cmd_items = (((int) &__u_boot_cmd_end) -
76 ((int) &__u_boot_cmd_start)) /
79 cmd_tbl_t *cmd_array[(cmd_items + 1)];
82 /* Make list of commands from .uboot_cmd section */
83 cmdtp = (cmd_tbl_t *) & __u_boot_cmd_start;
84 for (i = 1; i <= cmd_items; i++) {
88 /* Sort command list */
90 for (i = 1; end_sort != 1 || i <= cmd_items - 1; i++) {
91 if (i == cmd_items) { /* Last command */
96 if (strcmp (cmd_array[i]->name, cmd_array[i + 1]->name) > 0) {
98 *cmd_array[0] = *cmd_array[i];
99 *cmd_array[i] = *cmd_array[i + 1];
100 *cmd_array[i + 1] = *cmd_array[0];
104 /* print short help (usage) */
105 for (cmdtp = (cmd_tbl_t *) & __u_boot_cmd_start;
106 cmdtp != (cmd_tbl_t *) & __u_boot_cmd_end; cmdtp++) {
107 /* allow user abort */
110 if (cmdtp->usage == NULL)
117 * command help (long version)
119 for (i = 1; i < argc; ++i) {
120 if ((cmdtp = find_cmd (argv[i])) != NULL) {
122 /* found - print (long) help info */
128 puts ("- No help available.\n");
132 #else /* no long help available */
135 #endif /* CFG_LONGHELP */
137 printf ("Unknown command '%s' - try 'help'"
138 " without arguments for list of all"
139 " known commands\n\n", argv[i]
148 cmd_tbl_t U_BOOT_CMD(HELP) = MK_CMD_ENTRY(
149 "help", CFG_MAXARGS, 1, do_help,
150 "help - print online help\n",
152 " - show help information (for 'command')\n"
153 "'help' prints online help for the monitor commands.\n\n"
154 "Without arguments, it prints a short usage message for all commands.\n\n"
155 "To get detailed help information for specific commands you can type\n"
156 "'help' with one or more command names as arguments.\n"
159 cmd_tbl_t U_BOOT_CMD(QUES) = MK_CMD_ENTRY(
160 "?", CFG_MAXARGS, 1, do_help,
161 "? - alias for 'help'\n",
165 cmd_tbl_t U_BOOT_CMD(VERS) = MK_CMD_ENTRY(
166 "version", 1, 1, do_version,
167 "version - print monitor version\n",
171 cmd_tbl_t U_BOOT_CMD(ECHO) = MK_CMD_ENTRY(
172 "echo", CFG_MAXARGS, 1, do_echo,
173 "echo - echo args to console\n",
175 " - echo args to console; \\c suppresses newline\n"
178 /***************************************************************************
179 * find command table entry for a command
181 cmd_tbl_t *find_cmd (const char *cmd)
185 cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
186 int one_cmd_name = 0;
188 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
189 if ((strncmp (cmd, cmdtp->name, strlen (cmd)) == 0) &&
190 (strlen (cmd) == strlen (cmdtp->name)))
192 else if (strncmp (cmd, cmdtp->name, strlen (cmd)) == 0) {
197 if (one_cmd_name == 1)
200 return NULL; /* not found || one_cmd_name >2 */