

#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "parseCsv.h"

#include <iostream>
#include <list>
using namespace std;


typedef struct {
	int		id;
	char 		name[10];
	short	num;
	short	count;
} test_fix;

typedef struct {
	int		id;
	char 		name[10];
} test_loop;


int main(int argc, char *argv[])
{
	int errcode;
	int i;
	
	test_fix	data_fix;
	test_loop	data_loop[10];
	

	parseData	parsefix[]={
		{PARSE_TYPE_INT,	offsetof(test_fix, id) ,		membersizeof(test_fix, id)},
		{PARSE_TYPE_CHAR,	offsetof(test_fix, name) ,	membersizeof(test_fix, name)},
		{PARSE_TYPE_SHORT,	offsetof(test_fix, num) ,	membersizeof(test_fix, num)},
		{PARSE_TYPE_END,	0 ,		0},
	};
	parseData	parseloop[]={
		{PARSE_TYPE_INT,	offsetof(test_loop, id) ,		membersizeof(test_loop, id)},
		{PARSE_TYPE_CHAR,	offsetof(test_loop, name) ,		membersizeof(test_loop, name)},
		{PARSE_TYPE_END,	0 ,		0},
	};

	parseList	parselist[]={
		{PARSE_TBL_FIXED,	&data_fix,		NULL,		PARSE_TYPE_NULL,	sizeof(test_fix),		parsefix},
		{PARSE_TBL_LOOP,	&data_loop,	&data_fix.count,	PARSE_TYPE_SHORT,	sizeof(test_loop),	parseloop},
		{PARSE_TBL_END,	NULL ,		NULL,		PARSE_TYPE_NULL,	0	,			NULL},
	};

	char test_data[]="1000,name,22,4,001,name1,002,name2,003,name3,004,name4";
	//printf("%s\n",argv[1]);
	//errcode=parseMsg(parselist,argv[1],-1);
	errcode=parseMsg(parselist,test_data,-1);
	printf("errcode=%d\n",errcode);
	printf("data_fix.id[%d]\n",data_fix.id);
	printf("data_fix.name[%s]\n",data_fix.name);
	printf("data_fix.num[%d]\n",data_fix.num);
	printf("data_fix.count[%d]\n",data_fix.count);
	for(i=0;i<5;i++)
	{
		// char test_tmp[20];
		// unsigned short *ppp;
		//uint16_t ppp=30;

		// snprintf(test_tmp,sizeof(test_tmp),"%u",ppp);
		printf("data_loop-%d.id[%d]\n",i+1,data_loop[i].id);
		printf("data_loop-%d.name[%s]\n",i+1,data_loop[i].name);
	}
	//char test_tmp[20];
	//unsigned int ppp=30;

	//snprintf(test_tmp,sizeof(test_tmp),"%d",ppp);

	return  (0);
}
