int register_commands(struct command_context *cmd_ctx, struct command *parent, const struct command_registration *cmds) { int retval = ERROR_OK; unsigned i; for (i = 0; cmds[i].name || cmds[i].chain; i++) { const struct command_registration *cr = cmds + i; struct command *c = NULL; if (NULL != cr->name) { c = register_command(cmd_ctx, parent, cr); if (NULL == c) { retval = ERROR_FAIL; break; } } if (NULL != cr->chain) { struct command *p = c ? : parent; retval = register_commands(cmd_ctx, p, cr->chain); if (ERROR_OK != retval) break; } } if (ERROR_OK != retval) { for (unsigned j = 0; j < i; j++) unregister_command(cmd_ctx, parent, cmds[j].name); } return retval; }
struct command *register_command(struct command_context *context, struct command *parent, const struct command_registration *cr) { if (!context || !cr->name) return NULL; const char *name = cr->name; struct command **head = command_list_for_parent(context, parent); struct command *c = command_find(*head, name); if (NULL != c) { /* TODO: originally we treated attempting to register a cmd twice as an error * Sometimes we need this behaviour, such as with flash banks. * http://www.mail-archive.com/[email protected]/msg11152.html */ LOG_DEBUG("command '%s' is already registered in '%s' context", name, parent ? parent->name : "<global>"); return c; } c = command_new(context, parent, cr); if (NULL == c) return NULL; int retval = ERROR_OK; if (NULL != cr->jim_handler && NULL == parent) { retval = Jim_CreateCommand(context->interp, cr->name, cr->jim_handler, cr->jim_handler_data, NULL); } else if (NULL != cr->handler || NULL != parent) retval = register_command_handler(context, command_root(c)); if (ERROR_OK != retval) { unregister_command(context, parent, name); c = NULL; } return c; }
static __exit void cd_cmd_exit(void) { unregister_command(&cmd_cd); }
static __exit void reboot_cmd_exit(void) { unregister_command(&cmd_reboot); }
static __exit void memtest_cmd_exit(void) { unregister_command(&cmd_memtest); }
static __exit void sync_cmd_exit(void) { unregister_command(&cmd_sync); }
static __exit void rm_cmd_exit(void) { unregister_command(&cmd_rm); }
static __exit void maskrom_cmd_exit(void) { unregister_command(&cmd_maskrom); }
static __exit void fileram_cmd_exit(void) { unregister_command(&cmd_fileram); }
static __exit void poweroff_cmd_exit(void) { unregister_command(&cmd_poweroff); }
static __exit void echo_cmd_exit(void) { unregister_command(&cmd_echo); }
static __exit void write_cmd_exit(void) { unregister_command(&cmd_write); }
static __exit void go_cmd_exit(void) { unregister_command(&cmd_go); }
static __exit void delay_cmd_exit(void) { unregister_command(&cmd_delay); }
static __exit void mw_cmd_exit(void) { unregister_command(&cmd_mw); }