增加删除已注册的cmd和keys的接口

Change-Id: Iedabe119d74f3232a15e206e0b4edf03e8d1ea82
This commit is contained in:
weidonglin 2021-10-05 18:19:35 +08:00
parent 96b9059fa3
commit f003196438
3 changed files with 83 additions and 0 deletions

View File

@ -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[] =

View File

@ -81,6 +81,20 @@ xcmd_t *xcmd_cmdlist_get(void);
*/
xcmd_key_t *xcmd_keylist_get(void);
/**
* @description: cmd
* @param {char*} cmdcmd集
* @return {int}0success !0failed
*/
int xcmd_unregister_cmd(char *cmd);
/**
* @description:key
* @param {char*} keykey集
* @return {int}0success !0failed
*/
int xcmd_unregister_key(char *key);
/**
* @description:
* @param {char* } str

View File

@ -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)