]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/command.c
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
= &__u_boot_cmd_end
-
76 &__u_boot_cmd_start
; /* pointer arith! */
77 cmd_tbl_t
*cmd_array
[cmd_items
];
80 /* Make array of commands from .uboot_cmd section */
81 cmdtp
= &__u_boot_cmd_start
;
82 for (i
= 0; i
< cmd_items
; i
++) {
83 cmd_array
[i
] = cmdtp
++;
86 /* Sort command list (trivial bubble sort) */
87 for (i
= cmd_items
- 1; i
> 0; --i
) {
89 for (j
= 0; j
< i
; ++j
) {
90 if (strcmp (cmd_array
[j
]->name
,
91 cmd_array
[j
+ 1]->name
) > 0) {
94 cmd_array
[j
] = cmd_array
[j
+ 1];
95 cmd_array
[j
+ 1] = tmp
;
103 /* print short help (usage) */
104 for (i
= 0; i
< cmd_items
; i
++) {
105 const char *usage
= cmd_array
[i
]->usage
;
107 /* allow user abort */
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
)
184 cmd_tbl_t
*cmdtp_temp
= &__u_boot_cmd_start
; /*Init value */
190 * Some commands allow length modifiers (like "cp.b");
191 * compare command name only until first dot.
193 len
= ((p
= strchr(cmd
, '.')) == NULL
) ? strlen (cmd
) : (p
- cmd
);
195 for (cmdtp
= &__u_boot_cmd_start
;
196 cmdtp
!= &__u_boot_cmd_end
;
198 if (strncmp (cmd
, cmdtp
->name
, len
) == 0) {
199 if (len
== strlen (cmdtp
->name
))
200 return cmdtp
; /* full match */
202 cmdtp_temp
= cmdtp
; /* abbreviated command ? */
206 if (n_found
== 1) { /* exactly one match */
210 return NULL
; /* not found or ambiguous command */