cmd_tbl_t *find_cmd (const char *cmd)
{
cmd_tbl_t *cmdtp;
#定义段的起始地址
cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
const char *p;
int len;
int n_found = 0;
/*
* Some commands allow length modifiers (like "cp.b");
* compare command name only until first dot.
*/
#计算命令的长度,没有点就直接返回命令长度
len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);
#遍历段查找命令
for (cmdtp = &__u_boot_cmd_start;
cmdtp != &__u_boot_cmd_end;
cmdtp++) {
#判断命令是否相等
if (strncmp (cmd, cmdtp->name, len) == 0) {
#判断命令长度是否相等
if (len == strlen (cmdtp->name))
#返回命令的函数指针
return cmdtp; /* full match */
cmdtp_temp = cmdtp; /* abbreviated command ? */
n_found++;
}
}
if (n_found == 1) { /* exactly one match */
#返回命令的函数指针
return cmdtp_temp;
}
return NULL; /* not found or ambiguous command */
}