[Feature][ZXW-88]merge P50 version

Only Configure: No
Affected branch: master
Affected module: unknown
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I34667719d9e0e7e29e8e4368848601cde0a48408
diff --git a/ap/app/socket_demo/linklist.c b/ap/app/socket_demo/linklist.c
new file mode 100755
index 0000000..ff055a7
--- /dev/null
+++ b/ap/app/socket_demo/linklist.c
@@ -0,0 +1,354 @@
+#include "linklist.h"

+

+

+linklist create_linklist(void)

+{

+	linklist L;

+	if((L=(linklist)malloc(sizeof(listnode))) == NULL)

+	{

+		printf("malloc no memmory!\n");

+		return NULL;

+	}

+	L->data.fd = 0;

+	bzero(L->data.ipv4_addr,sizeof(L->data.ipv4_addr));

+	L->data.port = 0;

+

+	L->next = NULL;

+	return L;

+}

+linklist create_n_linklist(void)

+{

+	linklist L,H,r;

+	datatype x;

+	if((L=(linklist)malloc(sizeof(listnode))) == NULL)

+	{

+		printf("malloc no memmory!\n");

+		return NULL;

+	}

+	L->data.fd = 0;

+	bzero(L->data.ipv4_addr,sizeof(L->data.ipv4_addr));

+	L->data.port = 0;

+	L->next = NULL;

+	r = L;

+	while(1)

+	{

+		printf("Please input a NUM_NL80211_WOWLAN_TRIGber(-1 exit :");

+		while(scanf("%d",&x.fd) != 1)

+		{

+			printf("Please INPUT_PROP_CNTut a number(-1 exit :");

+			getchar();

+		}

+

+		if(x.fd == -1)break;

+

+		if((H=(linklist)malloc(sizeof(listnode))) == NULL)

+		{

+			printf("malloc nexto memmory!\n");

+			return L;

+		}

+		H->data = x;

+		H->next = NULL;

+		r->next = H;

+		r=H;

+	}

+	return L;

+

+}

+int delete_pos_linklist(linklist L,int pos)

+{

+	linklist r,p;

+	int i=-1;

+	if(pos < 0 ||pos >=get_length_linklist(L))

+	{

+		printf("input pos is invalid!\n");

+		return -1;

+	}

+	r = L;

+	while(i < pos-1)

+	{

+		i++;

+		r = r->next;

+	}

+	if(r == NULL || r->next==NULL)

+	{

+		printf("argc is iavalid!\n");

+		return -1;

+	}

+	else

+	{

+		p = r->next;

+		r->next = p->next;

+		p->next = NULL;

+		free(p);

+		return 0;

+	}

+}

+int delete_locate_linklist(linklist L,datatype x)

+{

+	linklist r,p;

+	if(L->next == NULL)

+	{

+		printf("list is NULL!\n");

+		return -1;

+	}

+	r = L;

+	while(r->next->data.fd != x.fd)

+	{

+		if(r->next == NULL)

+		{

+			printf("value is not in list!\n");

+			return -1;

+		}

+		r = r->next;

+	}

+	p = r->next;

+	r->next = p->next;

+	p->next = NULL;

+	free(p);

+

+	return 0;

+}

+

+void clear_linklist(linklist L)

+{

+	while(get_length_linklist(L))

+	{

+		delete_pos_linklist(L,get_length_linklist(L)-1);

+	}

+	free(L);

+	L->next = NULL;

+	L = NULL;

+}

+int get_length_linklist(linklist L)

+{

+	int i=0;

+	linklist r;

+	r = L;

+	while(r->next)

+	{

+		r = r->next;

+		i++;

+	}

+	return i++;

+}

+linklist get_list_pos_linklist(linklist L,int pos)

+{

+	int i=0;

+	linklist r;

+	if(L->next == NULL)

+	{

+		printf("list is NULL!\n");

+		return NULL;

+	}

+	if(pos<0 || pos>=get_length_linklist(L))

+	{

+		printf("input is invalid!\n");

+		return NULL;

+	}

+	r = L->next;

+	while(i<pos)

+	{

+		r = r->next;

+		i++;

+	}

+	return r;

+}

+linklist get_list_locate_linklist(linklist L,datatype x)

+{

+	linklist r;

+	if(L->next == NULL)

+	{

+		printf("list is NULL!\n");

+		return NULL;

+	}

+	r = L->next;

+	while(r->data.fd != x.fd)

+	{

+		if(r->next == NULL)

+		{

+			printf("value is not in list!\n");

+			return NULL;

+		}

+		r = r->next;

+	}

+	return r;

+}

+

+int insert_head_linklist(linklist L,datatype x)

+{

+	linklist H;

+	if((H=(linklist)malloc(sizeof(listnode))) == NULL)

+	{

+		printf("malloc no memmory\n");

+		return -1;

+	}

+	H->data = x;

+	H->next = L->next;

+	L->next = H;

+	return 0;

+}

+int insert_n_head_linklist(linklist L)

+{

+	datatype x;

+

+	while(1)

+	{

+		printf("Please input a number(-1 exit:");

+		while(scanf("%d",&x.fd) != 1)

+		{

+			printf("Please input a number:(-1 exit");

+			getchar();

+		}

+		if(x.fd == -1)break;

+		insert_head_linklist(L,x);

+	}

+	return 0;

+}

+int insert_end_linklist(linklist L,datatype x)

+{

+	linklist r,H;

+	if((H = (linklist)malloc(sizeof(listnode))) == NULL)

+	{

+		printf("malloc no memmory!");

+		return -1;

+	}

+	r = L;

+	while(r->next)

+	{

+		r = r->next;

+	}

+	H->next = NULL;

+	H->data = x;

+	r->next = H;

+	return 0;

+}

+int insert_n_end_linklist(linklist L)

+{

+	datatype x;

+

+	while(1)

+	{

+		printf("Please input a number(-1 exit:");

+		while(scanf("%d",&x.fd) != 1)

+		{

+			printf("Please input a number:(-1 exit");

+			getchar();

+		}

+		if(x.fd == -1)break;

+		insert_end_linklist(L,x);

+	}

+	return 0;

+

+}

+int insert_pos_linklist(linklist L,datatype x,int pos)

+{

+	linklist K,r;

+	if(pos == 0)

+	{

+		r = L;

+	}

+	else

+	{

+		r = get_list_pos_linklist(L,pos-1);

+	}

+	if(r == NULL)

+	{

+		printf("argc is invalidateid!\n");

+		return -1;

+	}

+	else

+	{

+		if((K = (linklist)malloc(sizeof(listnode))) == NULL)

+		{

+			printf("malloc no memmory!");

+			return -1;

+										}

+		K->data = x;

+		K->next = r->next;

+		r->next = K;

+	}

+	return 0;

+}

+int insert_order_linklist(linklist L,datatype x)

+{

+	linklist r,H;

+	if((H = (linklist)malloc(sizeof(listnode))) == NULL)

+	{

+		printf("malloc nexto memmory!\n");

+		return -1;

+	}

+	H->data = x;

+

+	r = L;

+	while(r->next && r->next->data.fd < x.fd)

+	{

+		r = r->next;

+	}

+	H->next = r->next;

+	r->next = H;

+	return 0;

+}

+void reverse_linklist(linklist L)

+{

+	linklist r,p;

+

+	if(L->next == NULL)

+	{

+		printf("list is NULL!\n");

+		return ;

+	}

+

+	r = L->next;

+	L->next = NULL;

+	while(r)

+	{

+		p = r;

+		r = r->next;

+

+		p->next = L->next;

+		L->next = p;

+	}

+	return ;

+}

+void sort_linklist(linklist L)

+{

+	linklist r,p,q;

+	if(L == NULL)

+	{

+		printf("list is NULL!\n");

+		return ;

+	}

+	r = L->next;

+	L->next = NULL;

+	while(r)

+	{

+		p = r;

+		r = r->next;

+

+		q = L;

+		while(q->next && q->next->data.fd < p->data.fd)

+		{

+			q = q->next;

+		}

+		p->next = q->next;

+		q->next = p;

+	}

+}

+

+void show_linklist(linklist L)

+{

+	printf("list is:\n");

+	if(L->next == NULL)

+	{

+		printf("\tlist is NULL!list\n");

+		return ;

+	}

+	while(L->next)

+	{

+		printf("\t%d %s %d\t",L->next->data.fd,L->next->data.ipv4_addr,L->next->data.port);

+		L = L->next;

+		puts("");

+	}

+	//puts("");

+	return ;

+}