增加删除已注册的cmd和keys的接口
Change-Id: Iedabe119d74f3232a15e206e0b4edf03e8d1ea82
This commit is contained in:
parent
96b9059fa3
commit
f003196438
|
@ -100,6 +100,39 @@ static void cmd_history(int argc, char* argv[])
|
|||
}while(len--);
|
||||
}
|
||||
|
||||
static void cmd_delete_cmd(int argc, char* argv[])
|
||||
{
|
||||
int res = 0;
|
||||
if (argc == 2)
|
||||
{
|
||||
res = xcmd_unregister_cmd(argv[1]);
|
||||
if (res)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
return;
|
||||
error:
|
||||
xcmd_print("Too many parameters are entered or there is no command\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
static void cmd_delete_key(int argc, char* argv[])
|
||||
{
|
||||
int res = 0;
|
||||
if (argc == 2)
|
||||
{
|
||||
res = xcmd_unregister_key(argv[1]);
|
||||
if (res)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
error:
|
||||
xcmd_print("Too many parameters are entered or there is no command\r\n");
|
||||
}
|
||||
|
||||
|
||||
static int cmd_ctr_q(void* pv)
|
||||
{
|
||||
xcmd_print("this is ctr+q\n");
|
||||
|
@ -111,6 +144,8 @@ static xcmd_t cmds[] =
|
|||
{"echo", cmd_echo, "echo anything", NULL},
|
||||
{"history", cmd_history, "show history list", NULL},
|
||||
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
|
||||
{"delcmd", cmd_delete_cmd, "delete cmd [val]", NULL},
|
||||
{"delkey", cmd_delete_key, "delete key [val]", NULL},
|
||||
};
|
||||
|
||||
static xcmd_key_t keys[] =
|
||||
|
|
14
inc/xcmd.h
14
inc/xcmd.h
|
@ -81,6 +81,20 @@ xcmd_t *xcmd_cmdlist_get(void);
|
|||
*/
|
||||
xcmd_key_t *xcmd_keylist_get(void);
|
||||
|
||||
/**
|
||||
* @description: 删除已经注册的cmd
|
||||
* @param {char*} cmd:cmd集
|
||||
* @return {int}:0:success; !0:failed
|
||||
*/
|
||||
int xcmd_unregister_cmd(char *cmd);
|
||||
|
||||
/**
|
||||
* @description:删除已经注册的key
|
||||
* @param {char*} key:key集
|
||||
* @return {int}:0:success; !0:failed
|
||||
*/
|
||||
int xcmd_unregister_key(char *key);
|
||||
|
||||
/**
|
||||
* @description: 手动执行命令
|
||||
* @param {char* } str:命令
|
||||
|
|
34
src/xcmd.c
34
src/xcmd.c
|
@ -592,6 +592,40 @@ xcmd_t *xcmd_cmdlist_get(void)
|
|||
return g_xcmder.cmd_list.head;
|
||||
}
|
||||
|
||||
int xcmd_unregister_cmd(char *cmd)
|
||||
{
|
||||
xcmd_t *p = xcmd_cmdlist_get();
|
||||
xcmd_t *bk = p;
|
||||
while(p)
|
||||
{
|
||||
if(strcmp(cmd, p->name) == 0)
|
||||
{
|
||||
bk->next = p->next;
|
||||
return 0;
|
||||
}
|
||||
bk = p;
|
||||
p = p->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int xcmd_unregister_key(char *key)
|
||||
{
|
||||
xcmd_t *p = xcmd_cmdlist_get();
|
||||
xcmd_t *bk = p;
|
||||
while(p)
|
||||
{
|
||||
if(strcmp(key, p->name) == 0)
|
||||
{
|
||||
bk->next = p->next;
|
||||
return 0;
|
||||
}
|
||||
bk = p;
|
||||
p = p->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void xcmd_set_prompt(const char* prompt)
|
||||
{
|
||||
if(prompt)
|
||||
|
|
Loading…
Reference in New Issue