修改指令和按键链表插入方式,由原来的头插改为尾插

This commit is contained in:
hqm 2021-09-16 23:35:40 +08:00
parent 1bc1c6d0b4
commit 6cd8b8d757
1 changed files with 20 additions and 17 deletions

View File

@ -25,14 +25,15 @@ struct
struct struct
{ {
uint16_t len; uint16_t len;
xcmd_t *next; xcmd_t *head;
xcmd_t *tail; xcmd_t *tail;
}cmd_list; }cmd_list;
struct struct
{ {
uint16_t len; uint16_t len;
xcmd_key_t *next; xcmd_key_t *head;
xcmd_key_t *tail;
}key_list; }key_list;
struct struct
@ -79,7 +80,7 @@ static int xcmd_get_param(char* msg, char*delim, char* get[], int max_num)
static void xcmd_cmd_match(int argc, char*argv[]) static void xcmd_cmd_match(int argc, char*argv[])
{ {
xcmd_t *p = g_xcmder.cmd_list.next; xcmd_t *p = g_xcmder.cmd_list.head;
uint8_t flag = 0; uint8_t flag = 0;
while(p) while(p)
{ {
@ -112,7 +113,7 @@ static void xcmd_cmd_match(int argc, char*argv[])
static void xcmd_key_match(XCMD_KEY_T key) static void xcmd_key_match(XCMD_KEY_T key)
{ {
xcmd_key_t *p = g_xcmder.key_list.next; xcmd_key_t *p = g_xcmder.key_list.head;
uint8_t flag = 0; uint8_t flag = 0;
while(p) while(p)
{ {
@ -459,16 +460,17 @@ int xcmd_key_register(xcmd_key_t *keys, uint16_t number)
uint16_t i=0; uint16_t i=0;
if(g_xcmder.key_list.len == 0) if(g_xcmder.key_list.len == 0)
{ {
g_xcmder.key_list.next = &keys[i++]; g_xcmder.key_list.head = &keys[i++];
g_xcmder.key_list.next->next = NULL; g_xcmder.key_list.head->next = NULL;
g_xcmder.key_list.tail = g_xcmder.key_list.head;
++g_xcmder.key_list.len; ++g_xcmder.key_list.len;
} }
while(i<number) while(i<number)
{ {
xcmd_key_t *p = g_xcmder.key_list.next; g_xcmder.key_list.tail->next = &keys[i];
g_xcmder.key_list.next = &keys[i]; g_xcmder.key_list.tail = g_xcmder.key_list.tail->next;
keys[i].next = p; keys[i].next = NULL;
++g_xcmder.key_list.len; ++g_xcmder.key_list.len;
++i; ++i;
} }
@ -480,16 +482,17 @@ int xcmd_cmd_register(xcmd_t *cmds, uint16_t number)
uint16_t i=0; uint16_t i=0;
if(g_xcmder.cmd_list.len == 0) if(g_xcmder.cmd_list.len == 0)
{ {
g_xcmder.cmd_list.next = &cmds[i++]; g_xcmder.cmd_list.head = &cmds[i++];
g_xcmder.cmd_list.next->next = NULL; g_xcmder.cmd_list.head->next = NULL;
g_xcmder.cmd_list.tail = g_xcmder.cmd_list.head;
++g_xcmder.cmd_list.len; ++g_xcmder.cmd_list.len;
} }
while(i<number) while(i<number)
{ {
xcmd_t *p = g_xcmder.cmd_list.next; g_xcmder.cmd_list.tail->next = &cmds[i];
g_xcmder.cmd_list.next = &cmds[i]; g_xcmder.cmd_list.tail = g_xcmder.cmd_list.tail->next;
cmds[i].next = p; cmds[i].next = NULL;
++g_xcmder.cmd_list.len; ++g_xcmder.cmd_list.len;
++i; ++i;
} }
@ -498,12 +501,12 @@ int xcmd_cmd_register(xcmd_t *cmds, uint16_t number)
xcmd_key_t *xcmd_keylist_get(void) xcmd_key_t *xcmd_keylist_get(void)
{ {
return g_xcmder.key_list.next; return g_xcmder.key_list.head;
} }
xcmd_t *xcmd_cmdlist_get(void) xcmd_t *xcmd_cmdlist_get(void)
{ {
return g_xcmder.cmd_list.next; return g_xcmder.cmd_list.head;
} }
void xcmd_init( int (*get_c)(uint8_t*), int (*put_c)(uint8_t)) void xcmd_init( int (*get_c)(uint8_t*), int (*put_c)(uint8_t))
@ -517,7 +520,7 @@ void xcmd_init( int (*get_c)(uint8_t*), int (*put_c)(uint8_t))
g_xcmder.parser.cursor = 0; g_xcmder.parser.cursor = 0;
g_xcmder.parser.encode_case_stu = 0; g_xcmder.parser.encode_case_stu = 0;
g_xcmder.cmd_list.len = 0; g_xcmder.cmd_list.len = 0;
g_xcmder.cmd_list.next = NULL; g_xcmder.cmd_list.head = NULL;
if(g_xcmder._initOK == 0) if(g_xcmder._initOK == 0)
{ {