调整源码结构,修复警告

This commit is contained in:
hqm 2022-01-28 16:32:48 +08:00 committed by qmfr
parent 6c1a6674cf
commit b22c2f7976
6 changed files with 71 additions and 63 deletions

View File

@ -3,10 +3,10 @@ BIN = xcmder
OBJ += xcmd.o \
xcmd_default_keys.o \
xcmd_default_cmds.o \
xcmd_platform.o \
linux_main.o \
test.o \
ex_keys.o \
ex_list.o \
ex_cmds.o \
socket_cmds.o \
diskio.o \
@ -18,6 +18,7 @@ OBJ += xcmd.o \
VPATH := ../../src \
../../extensions/test \
../../extensions/ex_keys \
../../extensions/ex_list \
../../extensions/ex_cmds \
../../extensions/net_cmds \
./FatFs/source \
@ -27,6 +28,7 @@ INC += -I./ \
-I../../inc \
-I../../extensions/test \
-I../../extensions/ex_keys \
-I../../extensions/ex_list \
-I../../extensions/ex_cmds \
-I../../extensions/net_cmds \
-IFatFs/source \

View File

@ -14,6 +14,7 @@
#include "test.h"
#include "ex_keys.h"
#include "ex_cmds.h"
#include "ex_list.h"
#include "fs_cmds.h"
#include "socket_cmds.h"
#include "ff.h"
@ -154,7 +155,7 @@ int main(void)
ex_cmds_init();
socket_cmds_init();
fs_cmds_init();
linux_cmd_init();
ex_list_init();
while (1)
{
xcmd_task();

View File

@ -1,7 +1,6 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "xcmd_platform.h"
#include "xcmd.h"
#include "list.h"
struct student
@ -14,21 +13,20 @@ struct student
static int list_test(int argc, char* argv[])
{
struct student *p;
struct student *q;
struct student stu1;
struct student stu2;
struct list_head *pos;
//链表的初始化
//链表的初始化
INIT_LIST_HEAD(&stu1.stu_list);
INIT_LIST_HEAD(&stu2.stu_list);
//头插法创建stu stu1链表
//头插法创建stu stu1链表
for (int i = 0;i < 6;i++) {
p = (struct student *)malloc(sizeof(struct student));
p->ID=i;
p->math = i+80;
//头插法
//头插法
list_add(&p->stu_list,&stu1.stu_list);
//尾插法
//尾插法
//list_add_tail(&p->list,&stu.list);
}
@ -37,14 +35,14 @@ static int list_test(int argc, char* argv[])
printf("ID = %d,math = %d\n",((struct student*)pos)->ID,((struct student*)pos)->math);
}
//尾插法创建stu stu1链表
//尾插法创建stu stu1链表
for (int i = 0;i < 6;i++) {
p = (struct student *)malloc(sizeof(struct student));
p->ID=i;
p->math = i+80;
//头插法
//头插法
//list_add(&p->stu_list,&stu1.stu_list);
//尾插法
//尾插法
list_add_tail(&p->stu_list,&stu2.stu_list);
}
@ -59,25 +57,24 @@ static int list_test(int argc, char* argv[])
static int list_note_del(int argc, char* argv[])
{
struct student *p;
struct student *q;
struct student stu1;
struct student stu2;
struct list_head *pos1;
//注意这里的pos2后面会解释为什么定义为
//注意这里的pos2后面会解释为什么定义为
struct student *pos2;
//stu = (struct student*)malloc(sizeof(struct student));
//链表的初始化
//链表的初始化
INIT_LIST_HEAD(&stu1.stu_list);
INIT_LIST_HEAD(&stu2.stu_list);
LIST_HEAD(stu);
//头插法创建stu stu1链表
//头插法创建stu stu1链表
for (int i = 0;i < 6;i++) {
p = (struct student *)malloc(sizeof(struct student));
p->ID=i;
p->math = i+80;
//头插法
//头插法
list_add(&p->stu_list,&stu1.stu_list);
//尾插法
//尾插法
//list_add_tail(&p->list,&stu.list);
}
@ -86,7 +83,7 @@ static int list_note_del(int argc, char* argv[])
printf("ID = %d,math = %d\n",((struct student*)pos1)->ID,((struct student*)pos1)->math);
}
//删除
//删除
list_for_each_entry(pos2,&stu1.stu_list,stu_list) {
if (pos2->ID == 4) {
list_del(&pos2->stu_list);
@ -104,25 +101,24 @@ static int list_note_del(int argc, char* argv[])
static int list_note_rep(int argc, char* argv[])
{
struct student *p;
struct student *q;
struct student stu1;
struct student stu2;
struct list_head *pos1;
struct student *pos2;
struct student new_obj={.ID=100,.math=100};
//stu = (struct student*)malloc(sizeof(struct student));
//链表的初始化
//链表的初始化
INIT_LIST_HEAD(&stu1.stu_list);
INIT_LIST_HEAD(&stu2.stu_list);
LIST_HEAD(stu);
//头插法创建stu stu1链表
//头插法创建stu stu1链表
for (int i = 0;i < 6;i++) {
p = (struct student *)malloc(sizeof(struct student));
p->ID=i;
p->math = i+80;
//头插法
//头插法
list_add(&p->stu_list,&stu1.stu_list);
//尾插法
//尾插法
//list_add_tail(&p->list,&stu.list);
}
printf("list_add: \r\n");
@ -130,7 +126,7 @@ static int list_note_rep(int argc, char* argv[])
printf("ID = %d,math = %d\n",((struct student*)pos1)->ID,((struct student*)pos1)->math);
}
//替换
//替换
list_for_each_entry(pos2,&stu1.stu_list,stu_list) {
if (pos2->ID == 4) {
list_replace(&pos2->stu_list,&new_obj.stu_list);
@ -148,25 +144,23 @@ static int list_note_rep(int argc, char* argv[])
static int list_note_del_insert(int argc, char* argv[])
{
struct student *p;
struct student *q;
struct student stu1;
struct student stu2;
struct list_head *pos1;
struct student *pos2;
struct student new_obj={.ID=100,.math=100};
//stu = (struct student*)malloc(sizeof(struct student));
//链表的初始化
//链表的初始化
INIT_LIST_HEAD(&stu1.stu_list);
INIT_LIST_HEAD(&stu2.stu_list);
LIST_HEAD(stu);
//头插法创建stu stu1链表
//头插法创建stu stu1链表
for (int i = 0;i < 6;i++) {
p = (struct student *)malloc(sizeof(struct student));
p->ID=i;
p->math = i+80;
//头插法
//头插法
list_add(&p->stu_list,&stu1.stu_list);
//尾插法
//尾插法
//list_add_tail(&p->list,&stu.list);
}
printf("list_add: \r\n");
@ -174,7 +168,7 @@ static int list_note_del_insert(int argc, char* argv[])
printf("ID = %d,math = %d\n",((struct student*)pos1)->ID,((struct student*)pos1)->math);
}
//移位替换
//移位替换
list_for_each_entry(pos2,&stu1.stu_list,stu_list) {
if (pos2->ID == 0) {
list_move(&pos2->stu_list,&stu1.stu_list);
@ -195,35 +189,33 @@ static int List_to_merge(int argc, char* argv[])
struct student stu1;
struct student stu2;
struct list_head *pos1;
struct student *pos2;
struct student new_obj={.ID=100,.math=100};
//stu = (struct student*)malloc(sizeof(struct student));
//链表的初始化
//链表的初始化
INIT_LIST_HEAD(&stu1.stu_list);
INIT_LIST_HEAD(&stu2.stu_list);
LIST_HEAD(stu);
//头插法创建stu1 list链表
//头插法创建stu1 list链表
for (int i = 0;i < 6;i++) {
p = (struct student *)malloc(sizeof(struct student));
p->ID=i;
p->math = i+80;
//头插法
//头插法
list_add(&p->stu_list,&stu1.stu_list);
//尾插法
//尾插法
//list_add_tail(&p->list,&stu.list);
}
printf("stu1: \r\n");
list_for_each(pos1, &stu1.stu_list) {
printf("ID = %d,math = %d\n",((struct student*)pos1)->ID,((struct student*)pos1)->math);
}
//头插法创建stu2 list 链表
//头插法创建stu2 list 链表
for (int i = 0;i < 3;i++) {
q = (struct student *)malloc(sizeof(struct student));
q->ID=i;
q->math = i+80;
//头插法
//头插法
list_add(&q->stu_list,&stu2.stu_list);
//尾插法
//尾插法
//list_add_tail(&p->list,&stu.list);
}
printf("stu2: \r\n");
@ -231,7 +223,7 @@ static int List_to_merge(int argc, char* argv[])
printf("ID = %d,math = %d\n",((struct student*)pos1)->ID,((struct student*)pos1)->math);
}
//合并
//合并
list_splice(&stu1.stu_list,&stu2.stu_list);
printf("list_splice\r\n");
list_for_each(pos1, &stu2.stu_list) {
@ -245,25 +237,22 @@ static int List_to_merge(int argc, char* argv[])
static int List_traverse(int argc, char* argv[])
{
struct student *p;
struct student *q;
struct student stu1;
struct student stu2;
struct list_head *pos1;
struct student *pos2;
struct student new_obj={.ID=100,.math=100};
//stu = (struct student*)malloc(sizeof(struct student));
//链表的初始化
//链表的初始化
INIT_LIST_HEAD(&stu1.stu_list);
INIT_LIST_HEAD(&stu2.stu_list);
LIST_HEAD(stu);
//头插法创建stu stu1链表
//头插法创建stu stu1链表
for (int i = 0;i < 6;i++) {
p = (struct student *)malloc(sizeof(struct student));
p->ID=i;
p->math = i+80;
//头插法
//头插法
list_add(&p->stu_list,&stu1.stu_list);
//尾插法
//尾插法
//list_add_tail(&p->list,&stu.list);
}
printf("stu1: \r\n");
@ -281,16 +270,16 @@ static int List_traverse(int argc, char* argv[])
static xcmd_t cmds[] =
{
{"list", list_test, "list test demo", NULL}, //链表增加节点
{"list1", list_note_del, "list note del demo", NULL}, //链表删除节点
{"list2", list_note_rep, "list note replace demo", NULL}, //链表替换节点
{"list3", list_note_del_insert, "list note del and insert demo", NULL}, //链表删除并插入节点
{"list4", List_to_merge, "List to merge", NULL}, //链表的合并
{"list5", List_traverse, "List to merge", NULL}, //链表的遍历
{"list", list_test, "list test demo", NULL}, //链表增加节点
{"list1", list_note_del, "list note del demo", NULL}, //链表删除节点
{"list2", list_note_rep, "list note replace demo", NULL}, //链表替换节点
{"list3", list_note_del_insert, "list note del and insert demo", NULL}, //链表删除并插入节点
{"list4", List_to_merge, "List to merge", NULL}, //链表的合并
{"list5", List_traverse, "List to merge", NULL}, //链表的遍历
};
void linux_cmd_init(void)
void ex_list_init(void)
{
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
}

View File

@ -0,0 +1,14 @@
#ifndef EX_LIST_H
#define EX_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
void ex_list_init(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -18,7 +18,7 @@ static int x_inet_send_to(int fd, char* ip, uint16_t port, void* data, uint16_t
return ret;
}
static void xcmd_udp_client(int argc ,char**argv)
static int xcmd_udp_client(int argc ,char**argv)
{
if(argc >= 4)
{
@ -26,7 +26,7 @@ static void xcmd_udp_client(int argc ,char**argv)
if(udp<0)
{
xcmd_print("Open socket error!!\r\n");
return;
return -1;
}
char* ip = argv[1];
uint16_t port = atoi(argv[2]);
@ -36,7 +36,7 @@ static void xcmd_udp_client(int argc ,char**argv)
{
xcmd_print("Send msg error\r\n");
close(udp);
return;
return -1;
}
close(udp);
}
@ -44,9 +44,10 @@ static void xcmd_udp_client(int argc ,char**argv)
{
xcmd_print("Usage: udp_client ip port msg");
}
return 0;
}
void xcmd_udp_service(int argc, char** argv)
static int xcmd_udp_service(int argc, char** argv)
{
struct sockaddr_in addrin;
addrin.sin_family = AF_INET;
@ -75,7 +76,7 @@ void xcmd_udp_service(int argc, char** argv)
{
xcmd_print("Bind error\r\n");
close(udp);
return;
return -1;
}
struct sockaddr_in client_addr;
@ -90,6 +91,7 @@ void xcmd_udp_service(int argc, char** argv)
xcmd_print(rcv_buf);
}
close(udp);
return 0;
}
static xcmd_t cmds[] =