Esempio n. 1
0
const char *_get_copy_function_func(char *input, size_t size, ndxml *dataNode)
{
	char *org = input;
	*input = 0;
	int subNodes = ndxml_getsub_num(dataNode);
	for (int n = 0; n < subNodes; ++n) {
		int len = 0;
		ndxml *node1 = ndxml_refsubi(dataNode, n);
		int bIsString = false;
		const char *pType = ndxml_getattr_val(node1, "type");
		if (0 == ndstricmp((char*)pType, (char*)"string") || 0 == ndstricmp((char*)pType, (char*)"char")) {
			bIsString = true;
		}
		const char *pArray = ndxml_getattr_val(node1, "isArray");
		const char *pValName = ndxml_getattr_val(node1, "name");
		if (pArray && pArray[0] && pArray[0] == '1') {
			if (!bIsString) {
				len = snprintf(input, size, "\t\tfor(int i=0;i<r.%sCount;i++) { \n"
					"\t\t\t%s[i]=r.%s[i];\n\t\t} \n"
					"\t\t%sCount=r.%sCount;\n"
					, pValName, pValName, pValName, pValName, pValName);
			}
			else {
				len = snprintf(input, size, "\t\tstrncpy(%s,r.%s,sizeof(%s));\n", pValName, pValName, pValName);
			}
		}
		else {
			len = snprintf(input, size, "\t\t%s = r.%s ;\n", pValName, pValName);
		}
		input += len;
		size -= len;
	}
	return  org;
}
Esempio n. 2
0
int _check_is_run_helper(int argc, const char *argv[], const char *help_tips)
{
	int i ;
	for (i=1; i<argc; i++) {
		if ( ndstricmp((char*)argv[i], (char*)"-h")==0 || ndstricmp((char*)argv[i], (char*) "--help")==0) {
			fprintf(stdout, "\t%s\n", help_tips) ;
			return 0;
		}
	}
	return -1;
}
Esempio n. 3
0
int apoAttrCalcHelper::place_param_name(char *input, char *buf, int size)
{
	int i;

	if (!input || *input == 0) {
		nd_logfatal("parse error input param is NUMM\n");
		return -1;
	}

	role_attr_description  *pwa = m_wahelper_bufs;
	for (i = 0; i<m_wa_num; i++, pwa++) {
		if (pwa->wa_id == INVALID_ATTR_ID || !pwa->name.c_str()) {
			continue;
		}
		if (0 == strcmp(input, pwa->name.c_str()) || 0 == ndstricmp(input, pwa->real_name.c_str())) {
			snprintf(buf, size, "[%d]", pwa->wa_id);
			if (m_current_parse != i) {
				//pwa->infections[(pwa->infection_num)++] = i;		
				//m_wahelper_bufs[m_current_parse].need_buf[(m_wahelper_bufs[m_current_parse].need_num)++] = i;		

				pwa->infections.push_back(m_current_parse);
				m_wahelper_bufs[m_current_parse].need_buf.push_back(i);
			}
			return 0;
		}
	}

	//
	nd_logfatal("parse error :can not find[%s]\n" AND input);
	return -1;
}
Esempio n. 4
0
NDUINT32 nd_msgentry_get_id(nd_handle handle, const char *msgname)
{
	int i, x;
	struct nd_msgentry_root *root_entry = (struct nd_msgentry_root *) nd_get_msg_hadle(handle);
	if (!root_entry){
		return (NDUINT32)-1;
	}
	if (!msgname || !msgname[0]){
		return (NDUINT32)-1;
	}

	for ( i = 0; i < root_entry->main_num; i++)	{
		for (x = 0; x < SUB_MSG_NUM; x++){
			struct nd_msg_entry_node*node = &(root_entry->sub_buf[i].msg_buf[x]);
			if (!node->name[0]){
				continue;
			}
			if (ndstricmp((char*)msgname, node->name)==0 ) {
				NDUINT32 maxid = root_entry->msgid_base + i;
				return ND_MAKE_DWORD(maxid, x);
			}
		}
	}

	return (NDUINT32)-1;
}
Esempio n. 5
0
LogicObjectBase *apoLogicObject4Game::getObjectMgr(const char* destName)
{
	if (0 == ndstricmp(destName, "owner")) {
		return  this;
	}
	m_error = LOGIC_ERR_AIM_OBJECT_NOT_FOUND;
	PARSE_TRACE("logic_engine_test: getObjectMgr(%s) \n", destName);
	return NULL;
}
Esempio n. 6
0
	bool getOtherObject(const char*objName, DBLDataNode &val)
	{
		bool ret = ClientMsgHandler::ApoConnectScriptOwner::getOtherObject(objName, val);
		if (ret) {
			return ret;
		}

// 		else if (0 == ndstricmp(objName, "connector") || 0 == ndstricmp(objName, "session")){
// 			if (!m_netHandler) {
// 				return false;
// 			}
// 			val.InitSet((void*)m_netHandler, OT_OBJ_NDHANDLE);
// 			return true;
// 		}

// 		else if (0==ndstricmp(objName, "LogFunction")) {
// 			val.InitSet((void*)apoPrintf);
// 			return true;
// 		}
// 		else if (0==ndstricmp(objName, "LogFile")) {
// 			val.InitSet((void*)NULL);
// 			return true;
// 		}

		else if (0==ndstricmp(objName, "LogPath")) {
			//std::string mypath = cocos2d::FileUtils::getInstance()->getWritablePath();
			std::string mypath = ApoClient::getInstant()->getPath();
			val.InitSet(mypath.c_str());
			return true;
		}
		else if (0==ndstricmp(objName, "WritablePath")) {
			//std::string mypath = cocos2d::FileUtils::getInstance()->getWritablePath();
			std::string mypath = ApoClient::getInstant()->getPath();
			val.InitSet(mypath.c_str());
			return true;
		}

		else if (0 == ndstricmp(objName, "DataPath")) {
			std::string mypath = ApoClient::getInstant()->getPath();
			val.InitSet(mypath.c_str());
			return true;
		}
		return false;
	}
Esempio n. 7
0
static const char *get_type_from_alias(const char *in_alias,type_name_info *info, int size)
{
	for (int i=0; i< size; ++i) {
		if (0==ndstricmp((char*) info[i].alias, (char*)in_alias)) {
			return info[i].type ;
		}
	}
	return NULL;
	
}
Esempio n. 8
0
const char *_get_construction_func(char *input,size_t size, ndxml *dataNode)
{
	char *org = input;
	*input = 0;
	int subNodes = ndxml_getsub_num(dataNode);
	for (int n = 0; n < subNodes; ++n) {
		int len = 0;
		ndxml *node1 = ndxml_refsubi(dataNode, n);
		int bIsString = false;
		const char *pType = ndxml_getattr_val(node1, "type");
		if (0 == ndstricmp((char*)pType, (char*)"string") || 0 == ndstricmp((char*)pType, (char*)"char")) {
			bIsString = true;
		}
		const char *pArray = ndxml_getattr_val(node1, "isArray");
		const char *pValName = ndxml_getattr_val(node1, "name");
		const char *pDftVal = ndxml_getattr_val(node1, "default");

		if (pArray && pArray[0] && pArray[0] == '1') {
			if (!bIsString) {
				len = snprintf(input, size, "\t\t%sCount = 0 ;\n", pValName);
			}
			else {
				if (pDftVal) {

					len = snprintf(input, size, "\t\tstrncpy(%s,\"%s\",sizeof(%s));\n", pValName,pDftVal,pValName);
				}
				else {
					len = snprintf(input, size, "\t\t%s[0] = 0 ;\n", pValName);
				}
			}
		}
		else {
			if (is_base_type(pType)) {
				len = snprintf(input, size, "\t\t%s = %s ;\n", pValName, pDftVal ? pDftVal : "0");
			}
		}
		input += len;
		size -= len;
	}
	return  org;
}
Esempio n. 9
0
connect_config *NDInstanceBase::getConnectorInfo(const char *name)
{
	for (int i=0; i<ND_CONNECT_OTHER_HOSTR_NUM; ++i) {
		if (m_config.i_cfg.connectors[i].port == 0) {
			continue ;
		}
		if (0==ndstricmp(m_config.i_cfg.connectors[i].connector_name, name)) {
			return &m_config.i_cfg.connectors[i] ;
		}
	}
	return NULL ;
}
Esempio n. 10
0
bool apoLogicObject4Game::opCheck(const LogicDataObj& id, const  LogicDataObj &val)
{
	if (val.GetDataType() == OT_STRING) {
		const char *pText = val.GetText();
		if (pText && *pText) {
			if (0 == ndstricmp(pText, "test-error")) {
				m_error = NDERR_SUCCESS;
				return false;
			}
		}
	}
	return true;
}
Esempio n. 11
0
int _command_line(struct nd_cmdline_root *root, int argc,  const char *argv[])
{
	int i = 0 ;
	int ret = -1;
	
	for (i=0; i< root->number; ++i) {
		if (ndstricmp(root->entries[i].name, (char*)argv[0]) == 0) {
			ret = root->entries[i].entry(root, argc, argv) ;
			break ;
		}
	}
		
	return  ret;
}
Esempio n. 12
0
const char *NDHttpRequest::getHeader(const char *hdrname)
{
//	HttpHeader_t::iterator it = m_header.find(std::string(hdrname) ) ;
//	if (it == m_header.end()) {
//		return NULL ;
//	}
//	return (it->second.c_str() );
	
	HttpHeader_t::iterator it ;
	for (it = m_header.begin(); it!=m_header.end(); ++it) {
		if (ndstricmp((char*)it->name.c_str(), (char*) hdrname) == 0) {
			return it->value.c_str() ;
		}
	}
	return  NULL ;
	
}
Esempio n. 13
0
attrid_t apoAttrCalcHelper::GetID(const char *name)
{
	if (!name || !*name) {
		return INVALID_ATTR_ID;
	}
	role_attr_description  *pwa = m_wahelper_bufs;
	for (int i = 0; i<m_wa_num; i++, pwa++) {
		if (pwa->wa_id == INVALID_ATTR_ID) {
			continue;
		}
		else if (0 == strcmp(name, pwa->name.c_str())) {
			return pwa->wa_id;
		}
		else if (0 == ndstricmp(name, pwa->real_name.c_str())) {
			return pwa->wa_id;
		}
	}

	return INVALID_ATTR_ID;
}
Esempio n. 14
0
int ipaddr_mac_cmp(const char *input_addr)
{
	int fd, intrface, ret = -1;
	struct ifreq buf[32];
	struct arpreq arp;
	struct ifconf ifc;
	char ma_buf[128] ;

	if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) >= 0) {
		ifc.ifc_len = sizeof buf;
		ifc.ifc_buf = (caddr_t) buf;
		if (!ioctl (fd, SIOCGIFCONF, (char *) &ifc)) {
			intrface = ifc.ifc_len / sizeof (struct ifreq);
			while (intrface-- > 0){
				if (!(ioctl (fd, SIOCGIFHWADDR, (char *) &buf[intrface])))	{

					snprintf(ma_buf, 128, "%02x-%02x-%02x-%02x-%02x-%02x",
						(unsigned char)buf[intrface].ifr_hwaddr.sa_data[0],
						(unsigned char)buf[intrface].ifr_hwaddr.sa_data[1],
						(unsigned char)buf[intrface].ifr_hwaddr.sa_data[2],
						(unsigned char)buf[intrface].ifr_hwaddr.sa_data[3],
						(unsigned char)buf[intrface].ifr_hwaddr.sa_data[4],
						(unsigned char)buf[intrface].ifr_hwaddr.sa_data[5]);
					if(0==ndstricmp(ma_buf,(char*)input_addr)) {
						ret = 0 ;
						break ;
					}
				}

			}
		} 
		else
			ret = -1;

	} 
	else
		ret = -1;

	close(fd);
	return ret;
}
Esempio n. 15
0
int read_iplist(ndxml *xmlnode, ndip_t *ipbuf, int num )
{
	int real_num = 0;
	for (int i=0; i<ndxml_getsub_num(xmlnode) && real_num<num; i++){
		ndip_t ip =0;
		ndxml *xmlip = ndxml_refsubi(xmlnode,i) ;
		const char *p = ndxml_getval(xmlip) ;
		if (p) {
			if (0 == ndstricmp(p, "localhost")) {
				ip = 0x0100007f;
			}
			else if(0!=ndstr_get_ip(p, &ip) ) {
				ip =nd_inet_aton(p) ;
			}
			if (ip){
				ipbuf[real_num++] = ip ;
			}
		}
	}
	return 0;

}
Esempio n. 16
0
//replace name on running
static int apo_place_name_runtime(char *input, char *buf, int size, void *user_data)
{
	int i;
	if (!input || *input == 0) {
		nd_logfatal("parse error input param is NUMM\n");
		return -1;
	}
	apoAttrCalcHelper *waHelper = (apoAttrCalcHelper*)user_data;
	role_attr_description  *pwa = waHelper->m_wahelper_bufs;
	for (i = 0; i < waHelper->m_wa_num; i++, pwa++) {
		if (pwa->wa_id == INVALID_ATTR_ID) {
			continue;
		}
		if (0 == strcmp(input, pwa->name.c_str()) || 0 == ndstricmp(input, pwa->real_name.c_str())) {
			snprintf(buf, size, "[%d]", pwa->wa_id);
			return 0;
		}
	}


	nd_logfatal("parse error, can not found[%s]\n" AND input);
	return -1;
}
Esempio n. 17
0
int ipaddr_mac_cmp(const char *input_addr) 
{
	PIP_ADAPTER_INFO pAdapterInfo;
	PIP_ADAPTER_INFO pAdapter = NULL;
	DWORD dwRetVal = 0;

	pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) );
	ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);

	dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) ;
	if ( dwRetVal != ERROR_SUCCESS) 	{
		free (pAdapterInfo);
		pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
	}
	if((dwRetVal=GetAdaptersInfo(pAdapterInfo ,&ulOutBufLen))==NO_ERROR){
		pAdapter= pAdapterInfo;
		while(pAdapter)	{
			char mac_buf[128] ;
			char *p = mac_buf ;
			for(UINT i=0;i<pAdapter->AddressLength;i++)	{
				p +=snprintf(p,128 , "%02x-" , pAdapter->Address[i]) ;
			}
			--p ;
			*p = 0 ;
			if (0==ndstricmp((char*)mac_buf,(char*) input_addr)){
				return 0 ;
			}
			pAdapter=pAdapter->Next;
		}
	}
	else {
		nd_logerror("last error  :%s\n" AND nd_last_error()) ;
	}

	free (pAdapterInfo);
	return -1;
}
Esempio n. 18
0
bool apoLogicObject4Game::getOtherObject(const char*objName, LogicDataObj &val)
{
	if (0 == ndstricmp(objName, "machineInfo")) {
		char buf[256];
		val.InitSet(nd_common_machine_info(buf, sizeof(buf)));
	}
	else if (0 == ndstricmp(objName, "FormatMsgData")) {
		val.InitSet((void*)&getGlobalNetMsgFormat());
	}
	else if (0 == ndstricmp(objName, "self")) {
		val.InitSet((void*)this, OT_OBJ_BASE_OBJ);
	}

	else if (0 == ndstricmp(objName, "settingFile")) {
		const char *pSettingFile = LogicCompiler::get_Instant()->getConfigFileName();
		val.InitSet(pSettingFile);
	}
	else if (0 == ndstricmp(objName, "globalParser")) {
		LogicParserEngine &parser = LogicEngineRoot::get_Instant()->getGlobalParser();
		val.InitSet(&parser);
	}
	else if (0 == ndstricmp(objName, "WritablePath")) {
		val.InitSet(nd_getcwd());
	}
	else if (0 == ndstricmp(objName, "myParser")) {
		LogicParserEngine *parser = getScriptHandler();
		if (parser) {
			val.InitSet(&parser);
		}
		else {
			m_error = LOGIC_ERR_AIM_OBJECT_NOT_FOUND;
			return false;
		}
	}
	else {
		return _myBase::getOtherObject(objName, val);
	}
	return true;
}
Esempio n. 19
0
int parser_args(int argc, char *argv[])
{
	for (int i = 1; i < argc; i++) {
		if (0 == ndstricmp(argv[i], "--runEditor")) {
			__run_type = 0;
		}
		else if (0 == ndstricmp(argv[i], "--rungmtool")) {
			__run_type = 1;
		}
		else if (0 == ndstricmp(argv[i], "--runBaseEditor")) {
			__run_type = 2;
		}
		else if (0 == ndstricmp(argv[i], "--workdir")) {
			__in_working_path = argv[++i];
		}
		else if (0 == ndstricmp(argv[i], "--porjdir")) {
			__in_proj_path = argv[++i];
		}
		else if (0 == ndstricmp(argv[i], "-f")) {
			__in_config = argv[++i];
		}
	}
	return 0;
}
Esempio n. 20
0
int _save_dataTypeNode(ndxml *sub, FILE *pf,FILE *pfCpp, const char *version, bool SaveDB)
{
	const char *pName = ndxml_getname(sub) ;
	if (!pName) {
		return-1 ;
	}
	char name_buf[256] ;
	char construct_func[1024*16];
	
	const char *pComment = ndxml_getattr_val(sub, "comment");
	if (pComment) {
		fprintf(pf, "// %s\n", pComment) ;
	}
	
	if (SaveDB) {
		snprintf(name_buf, sizeof(name_buf), "%s_v%s",pName,version) ;
		pName = name_buf ;
		
		//fprintf(pf, "struct %s \n{\n ", pName) ;
		//fprintf(pf, "\t%s() \n\t{\n\t\tmemset(this, 0, sizeof(*this) ); \n\t}\n\n",pName, ) ;
	}
	else {
		//fprintf(pf, "struct %s \n{\n ", pName) ;
		//fprintf(pf, "\t%s() \n\t{\n\t\tmemset(this, 0, sizeof(*this) ); \n\t}\n\n",pName) ;
	}
	fprintf(pf, "struct %s \n{\n ", pName);
	fprintf(pf, "\t%s() \n\t{\n%s\t}\n\n", pName, _get_construction_func(construct_func, sizeof(construct_func), sub));
	fprintf(pf, "\t%s& operator=(const %s &r)\n\t{\n%s\t\treturn *this;\n\t}\n\n",
		pName, pName, _get_copy_function_func(construct_func, sizeof(construct_func), sub));


	char buf_read_func[4096] ;
	char buf_write_func[4096];
	char buf_toUser_func[4096];
	char buf_fromUser_func[4096];

	char buf_toJson_func[4096];

	char *pReadStream = buf_read_func;
	char *pWriteStream = buf_write_func ;
	char *pTouserStream = buf_toUser_func;
	char *pFromuserStream = buf_fromUser_func;

	char *pToJsonStream = buf_toJson_func;

	size_t read_size = sizeof(buf_read_func);
	size_t write_size = sizeof(buf_write_func);

	size_t toUser_size = sizeof(buf_toUser_func);
	size_t fromUser_size = sizeof(buf_fromUser_func);
	size_t toJson_size = sizeof(buf_toJson_func);

	int subNodes = ndxml_getsub_num(sub) ;
	for (int n=0; n<subNodes; ++n) {
		ndxml *node1 = ndxml_refsubi(sub,n) ;
		int bIsString =false ;
		const char *pType = ndxml_getattr_val(node1, "type");
		if (0==ndstricmp((char*)pType, (char*)"string")||0==ndstricmp((char*)pType, (char*)"char") ) {
			pType = "char" ;
			bIsString = true ;
		}
		const char *pArray = ndxml_getattr_val(node1,"isArray") ;
		const char *pValName = ndxml_getattr_val(node1, "name") ;

// 		if (is_base_type(pType)) {
// 			int size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_NODE_NEW_LINE(p, outSize);\n");
// 			pToJsonStream += size;
// 			toJson_size -= size;
// 		}

		if (pArray && pArray[0] && pArray[0]=='1') {
			
			if (bIsString) {
				
				fprintf(pf,"\t%s  %s[%s]; \t//%s \n",getType(pType,version), pValName,
						ndxml_getattr_val(node1, "arrayMarco"),ndxml_getattr_val(node1, "comment") ) ;
				
				//read-string function
				int size = snprintf(pReadStream, read_size, "\t\tREAD_STREAM_STRING(inmsg, data.%s, %s);\n",pValName , ndxml_getattr_val(node1, "arrayMarco")) ;
				pReadStream += size ;
				read_size -= size;
				
				//write string function
				size = snprintf(pWriteStream, write_size, "\t\tWRITE_STREAM(omsg,data.%s);\n",pValName ) ;
				pWriteStream += size ;
				write_size -= size;
				
				//write to userdefine function
				size = snprintf(pTouserStream, toUser_size, "\t\tTO_USER_DEF_TEXT(paramUserData, %s, paramInputData);\n", pValName);
				pTouserStream += size;
				toUser_size -= size;

				size = snprintf(pFromuserStream, fromUser_size, "\t\tFROM_USER_DEF_TEXT(paramUserData, %s, paramInputData, %s);\n", pValName, ndxml_getattr_val(node1, "arrayMarco"));
				pFromuserStream += size;
				fromUser_size -= size;

				//to json char *pToJsonStream = buf_toJson_func; 		size_t PrintJson(char *buf, size_t bufsize, const char *name, NDUINT8 &data);
				size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_BASE_PRINT_TOBUF(p, outSize, \"%s\", (const char*)data.%s);\n", pValName, pValName);
				pToJsonStream += size;
				toJson_size -= size;

			}
			else {
				
				fprintf(pf,"\tNDUINT16  %sCount; \t \n", pValName ) ;
				fprintf(pf,"\t%s  %s[%s]; \t//%s \n",getType(pType,version), pValName,
						ndxml_getattr_val(node1, "arrayMarco"),
						ndxml_getattr_val(node1, "comment") ) ;
				
				//write push function
				fprintf(pf, "\tbool push_%s(const %s &val)\n\t{\n", pValName, getType(pType, version));
				fprintf(pf, "\t\tif (%sCount < %s)	{\n", pValName, ndxml_getattr_val(node1, "arrayMarco"));
				fprintf(pf, "\t\t\t%s[%sCount++] = val;\n", pValName, pValName);
				fprintf(pf, "\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n");

				//read array string fucntion
				int size = snprintf(pReadStream, read_size,
								   "\n\t\tREAD_STREAM(inmsg,data.%sCount);\n"
								   "\t\tif( data.%sCount > %s ) {\n\t\t\treturn -1;\n\t\t}\n ",
								   pValName,pValName, ndxml_getattr_val(node1, "arrayMarco") ) ;
				pReadStream += size ;
				read_size -= size;

				size = snprintf(pReadStream, read_size,
							   "\t\tfor(int i =0; i<data.%sCount;++i )"
							   "{\n\t\t\tREAD_STREAM(inmsg,data.%s[i]);\n\t\t}\n ",
							   pValName, pValName ) ;
				pReadStream += size ;
				read_size -= size;
				
				//write array string function
				size = snprintf(pWriteStream, write_size,
								"\n\t\tif(data.%sCount > %s) {\n\t\t\treturn -1; \n\t\t} \n ",
								pValName, ndxml_getattr_val(node1, "arrayMarco") ) ;
				pWriteStream += size ;
				write_size -= size;
				
				size = snprintf(pWriteStream, write_size,
								"\t\tWRITE_STREAM(omsg,data.%sCount);\n"
								"\t\tfor(int i =0 ; i < data.%sCount;++i){\n"
								"\t\t\tWRITE_STREAM(omsg,data.%s[i]); \n\t\t} \n",
								pValName,pValName,pValName ) ;
				
				pWriteStream += size ;
				write_size -= size;
				
				//usef define function 
				if (is_base_type(pType)) {
					size = snprintf(pTouserStream, toUser_size, "\t\tTO_USER_DEF_BASE_ARR(paramUserData, %s, paramInputData);\n", pValName);
					pTouserStream += size;
					toUser_size -= size;

					size = snprintf(pFromuserStream, fromUser_size, "\t\tFROM_USER_DEF_BASE_ARR(paramUserData, %s, paramInputData, %s);\n", pValName, ndxml_getattr_val(node1, "arrayMarco"));
					pFromuserStream += size;
					fromUser_size -= size;

					size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_BASEARRAY_PRINT_TOBUF(p, outSize, \"%s\", data.%s,data.%sCount);\n", pValName, pValName, pValName);
					pToJsonStream += size;
					toJson_size -= size;
				}
				else {
					size = snprintf(pTouserStream, toUser_size, "\t\tTO_USER_DEF_NODE_ARR(paramUserData, %s, paramInputData);\n", pValName);
					pTouserStream += size;
					toUser_size -= size;

					size = snprintf(pFromuserStream, fromUser_size, "\t\tFROM_USER_DEF_NODE_ARR(paramUserData, %s, paramInputData, %s);\n", pValName, ndxml_getattr_val(node1, "arrayMarco"));
					pFromuserStream += size;
					fromUser_size -= size;

					size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_ARRAY_PRINT_TOBUF(p, outSize, \"%s\", data.%s,data.%sCount);\n", pValName, pValName, pValName);
					pToJsonStream += size;
					toJson_size -= size;
				}

			}
		}
		else {
			
			fprintf(pf,"\t%s  %s; \t//%s \n",getType(pType,version), pValName,
					ndxml_getattr_val(node1, "comment") ) ;
			
			//readstream
			int size = snprintf(pReadStream, read_size, "\t\tREAD_STREAM(inmsg, data.%s);\n", pValName);
			pReadStream += size ;
			read_size -= size;
			
			size = snprintf(pWriteStream, write_size, "\t\tWRITE_STREAM(omsg,data.%s);\n", pValName);
			pWriteStream += size ;
			write_size -= size;

			if (is_base_type(pType) || ndstricmp("binaryData",pType)==0) {
				size = snprintf(pTouserStream, toUser_size, "\t\tTO_USER_DEF_ELE(paramUserData, %s, paramInputData);\n", pValName);
				pTouserStream += size;
				toUser_size -= size;

				size = snprintf(pFromuserStream, fromUser_size, "\t\tFROM_USER_DEF_ELE(paramUserData, %s, paramInputData);\n", pValName);
				pFromuserStream += size;
				fromUser_size -= size;

				size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_BASE_PRINT_TOBUF(p, outSize, \"%s\", data.%s);\n", pValName, pValName);
				pToJsonStream += size;
				toJson_size -= size;
			}
			else {
				size = snprintf(pTouserStream, toUser_size, "\t\tTO_USER_DEF_NODE(paramUserData, %s, paramInputData);\n", pValName);
				pTouserStream += size;
				toUser_size -= size;

				size = snprintf(pFromuserStream, fromUser_size, "\t\tFROM_USER_DEF_NODE(paramUserData, %s, paramInputData);\n", pValName);
				pFromuserStream += size;
				fromUser_size -= size;


				size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_NODE_PRINT_TOBUF(p, outSize, \"%s\", data.%s);\n", pValName, pValName);
				pToJsonStream += size;
				toJson_size -= size;
			}

		}
		
		if (n==subNodes-1) {
			/*int size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_NODE_NEW_LINE(p, outSize);\n");
			pToJsonStream += size;
			toJson_size -= size;*/
		}
		else {
			int size = snprintf(pToJsonStream, toJson_size, "\t\tJSON_NODE_INTERVAL(p, outSize);\n");
			pToJsonStream += size;
			toJson_size -= size;
		}
	}
	
	fprintf(pf, "};\n") ;

	fprintf(pfCpp, "\n\tint ReadStream(NDIStreamMsg &inmsg,NetMessage::%s &data)\n\t{\n", pName) ;
	fprintf(pfCpp, "%s\n\t\tTRYTO_MOVE_STRUCT_END(inmsg);\n\t\treturn 0; \n\t}\n", buf_read_func) ;
	
	fprintf(pfCpp, "\tint WriteStream(NDOStreamMsg &omsg,const NetMessage::%s &data)\n\t{\n", pName) ;
	fprintf(pfCpp, "\t\t\n");
	fprintf(pfCpp, "%s\n\t\tEND_STRUCT_STREAM(omsg); \n\t\treturn 0; \n\t}\n", buf_write_func) ;
	
	fprintf(pf, "int ReadStream(NDIStreamMsg &inmsg,NetMessage::%s &data);\n", pName) ;
	fprintf(pf, "int WriteStream(NDOStreamMsg &omsg,const NetMessage::%s &data);\n", pName) ;
	
	//write json 	size_t PrintJson(char *buf, size_t bufsize, const char *name, const char*data);
	fprintf(pf, "size_t PrintJson(char *buf, size_t bufsize, const char *, %s &data);\n", pName);
	fprintf(pfCpp, "\n\tsize_t PrintJson(char *outBuf, size_t outSize, const char *name, %s &data)\n ", pName);	
	fprintf(pfCpp, "\t{\n\t\tchar *p = outBuf;\n\t\tJSON_NODE_OUT_BEGIN(p,outSize);\n");
	fprintf(pfCpp, "%s\n\t\tJSON_NODE_OUT_END(p,outSize);\n\t\treturn (p-outBuf); \n\t}\n", buf_toJson_func);

	//write to user-define data paramUserData, %s, paramInputData
	fprintf(pfCpp, "#ifndef WITHOUT_LOGIC_PARSER\n");
	fprintf(pfCpp, "\n\tint ToUserDef(LogicUserDefStruct &paramUserData,const NetMessage::%s &paramInputData)\n\t{\n", pName);
	fprintf(pfCpp, "%s\n\t\treturn 0; \n\t}\n", buf_toUser_func);

	fprintf(pfCpp, "\tint  FromUserDef(const LogicUserDefStruct &paramUserData, NetMessage::%s &paramInputData)\n\t{\n", pName);
	fprintf(pfCpp, "%s\n\t\treturn 0; \n\t}\n", buf_fromUser_func);
	fprintf(pfCpp, "#endif\n\n");


	fprintf(pf, "#ifndef WITHOUT_LOGIC_PARSER\n");
	fprintf(pf, "int ToUserDef(LogicUserDefStruct &userData,const NetMessage::%s &data);\n", pName);
	fprintf(pf, "int FromUserDef(const LogicUserDefStruct &userData, NetMessage::%s &data);\n", pName);
	fprintf(pf, "#endif\n\n\n");

	return 0;
}
Esempio n. 21
0
int _out_data_forUE(ndxml *sub, FILE *pf,FILE *pfCpp)
{
	const char *pName = ndxml_getname(sub) ;
	if (!pName) {
		return-1 ;
	}
	//char name_buf[256] ;
	
	const char *pComment = ndxml_getattr_val(sub, "comment");
	if (pComment) {
		fprintf(pf, "// %s\n", pComment) ;
	}
	fprintf(pf, "USTRUCT(BlueprintType)\nstruct %s \n{\n\tGENERATED_USTRUCT_BODY();\n", pName) ;
	
	char buf_read_func[4096] ;
	char buf_write_func[4096] ;
	char *pReadStream = buf_read_func;
	char *pWriteStream = buf_write_func ;
	size_t read_size = sizeof(buf_read_func);
	size_t write_size = sizeof(buf_write_func);
	
	int subNodes = ndxml_getsub_num(sub) ;
	for (int n=0; n<subNodes; ++n) {
		ndxml *node1 = ndxml_refsubi(sub,n) ;
		int bIsString =false ;
		const char *pType = ndxml_getattr_val(node1, "type");
		if (0==ndstricmp((char*)pType, (char*)"string")||0==ndstricmp((char*)pType, (char*)"char") ) {
			pType = "char" ;
			bIsString = true ;
		}
		const char *pArray = ndxml_getattr_val(node1,"isArray") ;
		const char *pValName = ndxml_getattr_val(node1, "name") ;
		fprintf(pf,"\tUPROPERTY(EditAnywhere, BlueprintReadWrite, Category = \"%s\")\n ", "NetStream") ;
		if (pArray && pArray[0] && pArray[0]=='1') {
			
			
			if (bIsString) {
				fprintf(pf,"\t%s  %s[%s]; \t//%s \n\n",getTypeForUE4(pType), pValName,
						ndxml_getattr_val(node1, "arrayMarco"),ndxml_getattr_val(node1, "comment") ) ;
				
				//read-string function
				int size = snprintf(pReadStream, read_size, "\tREAD_STREAM_STRING(inmsg, data.%s, %s);\n",pValName , ndxml_getattr_val(node1, "arrayMarco")) ;
				pReadStream += size ;
				read_size -= size;
				
				//write string function
				size = snprintf(pWriteStream, write_size, "\tWRITE_STREAM(omsg,data.%s);\n",pValName ) ;
				pWriteStream += size ;
				write_size -= size;
				
			}
			else {
				
				fprintf(pf,"\tuint16  %sCount; \t \n", pValName ) ;
				fprintf(pf,"\tUPROPERTY(EditAnywhere, BlueprintReadWrite, Category = \"%s\")\n ", "NetStream") ;
				fprintf(pf,"\t%s  %s[%s]; \t//%s \n\n",getTypeForUE4(pType), pValName,
						ndxml_getattr_val(node1, "arrayMarco"),
						ndxml_getattr_val(node1, "comment") ) ;
				
				//write push function
				//
				fprintf(pf, "\tUFUNCTION(BlueprintPure, Category = \"%s\")\n", "NetStream") ;
				fprintf(pf, "\tbool push_%s(const %s &val)\n\t{\n", pValName, getTypeForUE4(pType));
				fprintf(pf, "\t\tif (%sCount < %s)	{\n", pValName, ndxml_getattr_val(node1, "arrayMarco"));
				fprintf(pf, "\t\t\t%s[%sCount++] = val;\n", pValName, pValName);
				fprintf(pf, "\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n");
				
				//read array string fucntion
				int size = snprintf(pReadStream, read_size,
									"\n\tREAD_STREAM(inmsg,data.%sCount);\n"
									"\tif( data.%sCount > %s ) {\n\t\treturn -1;\n\t}\n ",
									pValName,pValName, ndxml_getattr_val(node1, "arrayMarco") ) ;
				pReadStream += size ;
				read_size -= size;
				
				size = snprintf(pReadStream, read_size,
								"\tfor(int i =0; i<data.%sCount;++i )"
								"{\n\t\tREAD_STREAM(inmsg,data.%s[i]);\n\t}\n ",
								pValName, pValName ) ;
				pReadStream += size ;
				read_size -= size;
				
				//write array string function
				size = snprintf(pWriteStream, write_size,
								"\n\tif(data.%sCount > %s) {\n\t\treturn -1; \n\t} \n ",
								pValName, ndxml_getattr_val(node1, "arrayMarco") ) ;
				pWriteStream += size ;
				write_size -= size;
				
				size = snprintf(pWriteStream, write_size,
								"\tWRITE_STREAM(omsg,data.%sCount);\n"
								"\tfor(int i =0 ; i < data.%sCount;++i){\n"
								"\t\tWRITE_STREAM(omsg,data.%s[i]); \n\t} \n",
								pValName,pValName,pValName ) ;
				
				pWriteStream += size ;
				write_size -= size;
				
			}
		}
		else {
			fprintf(pf,"\t%s  %s; \t//%s \n",getTypeForUE4(pType), pValName,
					ndxml_getattr_val(node1, "comment") ) ;
			
			//readstream
			int size = snprintf(pReadStream, read_size, "\tREAD_STREAM(inmsg, data.%s);\n", pValName);
			pReadStream += size ;
			read_size -= size;
			
			size = snprintf(pWriteStream, write_size, "\tWRITE_STREAM(omsg,data.%s);\n", pValName);
			pWriteStream += size ;
			write_size -= size;
		}
		
		fprintf(pf,"\n") ;
	}
	
	fprintf(pf, "\tUFUNCTION(BlueprintPure, Category = \"%s\")\n","NetStream") ;
	fprintf(pf, "\tint ReadStream_%s(NDIStreamMsg &inmsg);\n\n", pName) ;
	
	fprintf(pf, "\tUFUNCTION(BlueprintPure, Category = \"%s\"\n", "NetStream") ;
	fprintf(pf, "\tint WriteStream_%s(NDOStreamMsg &omsg) const;\n\n",pName) ;
	
	//out function body
	fprintf(pfCpp, "int %s::ReadStream_%s(NDIStreamMsg &inmsg)\n{\n", pName, pName) ;
	fprintf(pfCpp, "\treturn ReadStream(inmsg,*this);\n}\n\n") ;
	
	fprintf(pfCpp, "int %s::WriteStream_%s(NDOStreamMsg &omsg) const\n{\n",pName,pName) ;
	fprintf(pfCpp, "\treturn WriteStream(omsg,*this);\n}\n\n") ;
	
	fprintf(pf, "};\n") ;
	
	fprintf(pfCpp, "\nint ReadStream(NDIStreamMsg &inmsg,%s &data)\n{\n", pName) ;
	fprintf(pfCpp, "%s\n\tTRYTO_MOVE_STRUCT_END(inmsg);\n\treturn 0; \n}\n\n", buf_read_func) ;
	
	fprintf(pfCpp, "int WriteStream(NDOStreamMsg &omsg,const %s &data)\n{\n",pName) ;
	fprintf(pfCpp, "%s\n\tEND_STRUCT_STREAM(omsg); \n\treturn 0; \n}\n", buf_write_func);
	
	fprintf(pf, "int ReadStream(NDIStreamMsg &inmsg,%s &data);\n", pName) ;
	fprintf(pf, "int WriteStream(NDOStreamMsg &omsg,const %s &data);\n",pName) ;
	
	return 0;
}