Exemple #1
0
int build_dataTypeForUE4(ndxml_root *xmlfile, const char *out_file)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	ndxml *xInfo = ndxml_getnode(xmlfile, "DataDesc") ;
	if (!xInfo) {
		return -1;
	}
	
	name_list_t res_list ;
	get_name_sort(xmlfile, res_list);
	
	char buf[128] ;
	snprintf(buf, sizeof(buf), "%s.h",out_file );
	FILE *pf = fopen(buf, "w") ;
	if (!pf){
		fprintf(stderr, " open out put file %s error \n", buf ) ;
		return -1 ;
	}
	snprintf(buf, sizeof(buf), "%s.cpp",out_file );
	FILE *pfCpp = fopen(buf, "w") ;
	if (!pf){
		fprintf(stderr, " open out put file %s error \n", buf ) ;
		return -1 ;
	}
	
	_OUT_PUT_TIME(pfCpp) ;
	fprintf(pfCpp, "\n\n#include \"netMessage/dataStream.h\"\n" );
	fprintf(pfCpp, "#include \"netMessage/netStreamAutoDefine.h\"\n\n\n" );
	//fprintf(pfCpp, "namespace NetMessage \n{\n" );
	
	_OUT_PUT_TIME(pf) ;
	fprintf(pf, "#ifndef _NET_STREAM_AUTO_DEFINE_H_\n" );
	fprintf(pf, "#define _NET_STREAM_AUTO_DEFINE_H_\n" );;
	fprintf(pf, "#include \"Object.h\" \n\nclass NDIStreamMsg;\nclass  NDOStreamMsg;\n\n") ;
	//fprintf(pf, "#include \"dataStream.h\"\n\n") ;
	//fprintf(pf, "#define DATA_IN_DB_VERSION %s \n\n", version );
	//fprintf(pf, "namespace NetMessage \n{\n" );
	
	int total =(int) res_list.size(); //ndxml_getsub_num(xnode) ;
	for (int i=0; i<total; ++i) {
		ndxml *sub = ndxml_refsub(xnode,res_list[i].name.c_str()) ;
		_out_data_forUE(sub,  pf,pfCpp) ;
		fprintf(pf, "\n") ;
	}
	
	fprintf(pf,"\n#endif\n\n") ;
	fclose(pf) ;
	
	//fprintf(pfCpp,"};\n\n") ;
	fclose(pfCpp) ;

	return 0 ;
}
Exemple #2
0
const char *startDialog::getScriptSetting(ndxml *scriptXml, const char *settingName)
{
	ndxml *moduleInfo = ndxml_getnode(scriptXml, "moduleInfo");
	if (moduleInfo){
		ndxml *node = ndxml_getnode(moduleInfo, settingName);
		if (node){
			return ndxml_getval(node);
		}
	}
	return NULL;
}
Exemple #3
0
bool startDialog::getScriptExpDebugInfo(ndxml *scriptXml)
{
	ndxml *moduleInfo = ndxml_getnode(scriptXml, "moduleInfo");
	if (moduleInfo){
		ndxml *node = ndxml_getnode(moduleInfo, "script_with_debug");
		if (node){
			return ndxml_getval_int(node) ? true : false;
		}
	}
	return false;
}
Exemple #4
0
int startDialog::getScriptExpEncodeType(ndxml *scriptXml)
{
	ndxml *moduleInfo = ndxml_getnode(scriptXml, "moduleInfo");
	if (moduleInfo){
		ndxml *node = ndxml_getnode(moduleInfo, "script_out_encode");
		if (node){
			return ndxml_getval_int(node);
		}
	}
	return 0;
}
Exemple #5
0
void CNewfileDlg::OnBnClickedButtonNew()
{
	CString filter;
	filter = " default Files (*.xml)| *.xml||";
	CFileDialog myfile(false, _T("*.xml"),NULL, OFN_OVERWRITEPROMPT, (LPCTSTR)filter, NULL);
	if (myfile.DoModal() != IDOK)	{
		return ;
	}

	CString strFile = myfile.GetPathName();
	if (strFile.IsEmpty())	{
		return;
	}
	ndxml_root *xml = ndxml_getnode(&m_xmlRoot, "script_file_manager");
	if (!xml){
		AfxMessageBox(_T("文件损坏"));
		return;
	}
	if (-1 == nd_cpfile(m_fileTemplate, (LPCTSTR)strFile)) {
		AfxMessageBox(_T("不能保存文件"));
		return;
	}
	ndxml *newNode = ndxml_addnode(xml, "file", (LPCTSTR)strFile);
	if (newNode){
		CString cName = myfile.GetFileTitle();
		ndxml_addattrib(newNode, "name", (LPCTSTR)cName);
	}
	SaveXmlFile();
	ShowFileList();
}
Exemple #6
0
bool CNewfileDlg::ShowFileList()
{
	m_tree.DeleteAllItems();
	HTREEITEM hRootItem = m_tree.InsertItem(_T("文件"));


	ndxml_root *xml = ndxml_getnode(&m_xmlRoot, "script_file_manager");
	if (!xml){
		AfxMessageBox(_T("文件损坏"));
		return false;
	}
	int num = ndxml_num(xml);
	for (int i = 0; i < num; i++) {
		ndxml *node = ndxml_getnodei(xml, i);
		if (!node )
			continue;
		const char *dispName = ndxml_getattr_val(node, "name");
		if (!dispName)	{
			dispName = ndxml_getval(node);
		}
		HTREEITEM 	hNode = m_tree.InsertItem(dispName, hRootItem, TVI_LAST);

		m_tree.SetItemData(hNode, (DWORD_PTR)node);
	}
	m_tree.Expand(hRootItem, TVE_EXPAND);

	return true;
}
Exemple #7
0
//read config from file
int NDInstanceBase::ReadConfig(const char *configname) 
{
	int ret;
	ndxml *xmlroot ;
	ndxml_root xmlfile;

	ret = ndxml_load(config_file, &xmlfile) ;
	if(0!=ret) {
		nd_logfatal("load xml from file\n") ;
		return -1;
	}

	xmlroot = ndxml_getnode(&xmlfile,"root") ;
	if(!xmlroot) {		
		ndxml_destroy(&xmlfile);
		nd_logfatal("xml read error : root-node can not found \n") ;
		return -1;
	}

	if(-1==read_config(xmlroot, configname, &m_config) ) {
		ndxml_destroy(&xmlfile);
		nd_logfatal("xml config error %s node \n", configname) ;
		return -1;
	}

	ndxml_destroy(&xmlfile);
    
	return 0;

}
Exemple #8
0
void startDialog::on_Connect_clicked()
{
    //ui->LogText->clear();
    dialogCloseHelper _helperClose(this) ;
	
    WriteLog("begin connect to server....");

    std::string filename = getPathFromConfig("gm_send_msg");
	std::string client_script = getPathFromConfig("connect_script");
	std::string package_file = getPathFromConfig("game_data_package_file");

	_LOAD_XML(xmlSend, filename.c_str(), "utf8", 0);


    ConnectDialog dlg(NULL) ;
	
    dlg.m_editor_setting = apoEditorSetting::getInstant()->getConfig() ;
    dlg.m_gmCfg = &xmlSend;
	
	if (!dlg.LoadClientScript(client_script.c_str(), package_file.c_str()))	{
		QMessageBox::warning(this, "Error", "load message data type error!", QMessageBox::Ok);
	}

    dlg.exec();

	ndxml *msgRoot = ndxml_getnode(&xmlSend, "send_msg_list");
	if (msgRoot){
		ndxml_delnode(msgRoot, "history");
	}

    ndxml_save_encode(&xmlSend, filename.c_str(), E_SRC_CODE_UTF_8, E_SRC_CODE_UTF_8);
    ndxml_destroy(&xmlSend) ;

    WriteLog("...\n connect server end!");
}
Exemple #9
0
void CNewfileDlg::OnBnClickedButtonDeltet()
{
	// TODO: Add your control notification handler code here
	HTREEITEM hCurItem = m_tree.GetSelectedItem();
	if (hCurItem){
		ndxml *xml = (ndxml*)(m_tree.GetItemData(hCurItem));
		if (!xml) {
			return;			
		}
		ndxml_root *xmlfiles = ndxml_getnode(&m_xmlRoot, "script_file_manager");
		if (!xmlfiles){
			return;
		}
		int num = ndxml_num(xmlfiles);
		for (int i = 0; i < num; i++) {
			ndxml *node = ndxml_getnodei(xmlfiles, i);
			if (node == xml) {
				if (IDYES != AfxMessageBox("是否要删除?", MB_YESNO))	{
					return;
				}
				nd_rmfile(ndxml_getval(node));
				ndxml_delxml(node, xmlfiles);

				SaveXmlFile();
				ShowFileList();
				return;
			}
		}

	}
}
Exemple #10
0
//get save db list
int get_saveDB_sort(ndxml_root *xmlfile,name_list_t &res_list,name_list_t &save_list)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	name_list_t save_input ;
	
	
	int add_new = 1 ;
	while (add_new > 0) {
		add_new = 0 ;
		for (name_list_t::iterator it= res_list.begin(); it!=res_list.end(); ++it) {
			if (it->is_saveDB && it->is_used==0) {
				it->is_used = 1;
				++add_new ;
			}
			if (!it->is_used) {
				continue ;
			}
			
			ndxml *subNode1 = ndxml_refsub(xnode,it->name.c_str()) ;
			int sub_num = ndxml_getsub_num(subNode1) ;
			
			for (int i=0; i<sub_num; ++i) {
				ndxml *subNode2 = ndxml_refsubi(subNode1,i) ;
				const char *myName = ndxml_getattr_val(subNode2, "type") ;
				
				const char *ret = get_type_from_alias(myName,alias_type, sizeof(alias_type)/sizeof(alias_type[0]) ) ;
				if (ret) {
					continue ;
				}
				
				for (name_list_t::iterator it_sub= res_list.begin(); it_sub!=res_list.end(); ++it_sub) {
					if (it_sub->is_used) {
						continue;
					}
					if (0== strcmp(myName, it_sub->name.c_str()) ) {
						if (it_sub->is_used==0) {
							it_sub->is_used = 1 ;
							++add_new;
							break ;
						}
					}
				}
			}
			
		}
	}
	
	for (name_list_t::iterator it= res_list.begin(); it!=res_list.end(); ++it) {
		if (it->is_used) {
			save_list.push_back(*it) ;
		}
	}
	return 0;
}
Exemple #11
0
bool startDialog::compile()
{
	std::string script_root = getPathFromConfig("script_root");
	
	/*
	if (!nd_absolute_filename(script_root.c_str(), tmpbuf, sizeof(tmpbuf))) {
		nd_logerror("can not found file %s\n", script_root.c_str());
		return false;
	}
	
	char tmpbuf[ND_FILE_PATH_SIZE];
	std::string absPath = tmpbuf;
	absPath = nd_getpath(absPath.c_str(), tmpbuf, sizeof(tmpbuf));
	*/

	ndxml_root xmlEntry;
	ndxml_initroot(&xmlEntry);
	if (-1 == ndxml_load_ex(script_root.c_str(), &xmlEntry, apoEditorSetting::getInstant()->m_encodeName.c_str())) {
		return false;
	}

	ndxml_root *xml = ndxml_getnode(&xmlEntry, "script_file_manager");
	if (!xml){
		return false;
	}
	

	char projPath[ND_FILE_PATH_SIZE];
	nd_getpath(script_root.c_str(), projPath, sizeof(projPath));

	WorkingPathSwitchHelper __pathHelper(projPath);
	
	bool ret = true;
	int num = ndxml_num(xml);
	for (int i = 0; i < num; i++) {
		ndxml *node = ndxml_getnodei(xml, i);
		if (!node)
			continue;
		std::string scriptPath = ndxml_getval(node);
		if (scriptPath.size() > 0) {
			scriptPath += "/";
		}
		scriptPath += ndxml_getattr_val(node, "main_file");

		if (!compileScript(scriptPath.c_str(),__pathHelper.workingPath())) {
			ret = false;
			break;
		}
	}

	ndxml_destroy(&xmlEntry);

	return true;
}
Exemple #12
0
const char *startDialog::_getFromIocfg(const char *cfgName,const char *rootName)
{
	//return	apoEditorSetting::getInstant()->getValueFromSetting(cfgName);
	apoEditorSetting *setting = apoEditorSetting::getInstant();

	if (!rootName) {
		rootName ="project_config";
	}

	ndxml *node = ndxml_getnode(setting->getIoConfig(), rootName);
	if (node) {
		ndxml *cfgxml = ndxml_getnode(node, cfgName);
		if (cfgxml) {
			return ndxml_getval(cfgxml);
		}
	}
	return NULL;


}
Exemple #13
0
int build_messageID(ndxml_root *xmlfile, const char *out_file)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "MessageDefine") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	FILE *pf = fopen(out_file, "w") ;
	if (!pf){
		fprintf(stderr, " open out put file %s error \n", out_file ) ;
		
		return -1 ;
	}
	
	_OUT_PUT_TIME(pf) ;
	
	int total = ndxml_getsub_num(xnode) ;
	
	for (int x = 0; x < total; x++)	{
		ndxml *mainMessage = ndxml_refsubi(xnode, x);
		int subNum = ndxml_getsub_num(mainMessage);

		NDUINT8 maxID = 0, minID = 0;

		const char *p = ndxml_getattr_val(mainMessage, "maxMessageId");
		if (!p || !*p)	{
			continue;
		}
		maxID = atoi(p);
		fprintf(pf, "\n\n\n// %s\n", ndxml_getattr_val(mainMessage,"name"));


		for (int i = 0; i < subNum; ++i) {
			ndxml *sub = ndxml_refsubi(mainMessage, i);
			
			const char *dataInfo = ndxml_getattr_val(sub, "body");
			if (!dataInfo || !*dataInfo) {
				dataInfo = "none";
			}
			fprintf(pf, "_APOLLO_MSG_ID_DEFINE(%s, 0x%x , \"%s\") //(%d,%d)%s,data-format:%s\n", 
				ndxml_getattr_val(sub, "id"),ND_MAKE_WORD(maxID, minID), 
				dataInfo, maxID, minID,ndxml_getattr_val(sub, "comment"), dataInfo);
			++minID;
		}

	}
	
	//fprintf(pf,"};\n#endif\n") ;
	
	fclose(pf) ;
	return 0 ;
}
Exemple #14
0
int build_marco(ndxml_root *xmlfile, const char *out_file)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "MarcoDefine") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	FILE *pf = fopen(out_file, "w") ;
	if (!pf){
		fprintf(stderr, " open out put file %s error \n", out_file ) ;

		return -1 ;
	}
	
	_OUT_PUT_TIME(pf) ;
	fprintf(pf, "#ifndef _AUTO_MACRO_DEFINE_H_\n" );
	fprintf(pf, "#define _AUTO_MACRO_DEFINE_H_\n" );
	fprintf(pf, "namespace NetMessage \n{\n" );
			
	int total = ndxml_getsub_num(xnode) ;
	
	for (int i=0; i<total; ++i) {
		ndxml *sub = ndxml_refsubi(xnode, i) ;
		fprintf(pf,"#define \t %s  \t\t%s \t\t//%s \n\n", ndxml_getattr_val(sub, "name"),
				ndxml_getattr_val(sub, "value"),
				ndxml_getattr_val(sub, "comment") ) ;
	}
	//enum define
	ndxml *pEnumXml = ndxml_getnode(xmlfile, "EnumDefine") ;
	if (pEnumXml) {
		exp_enum(pEnumXml, pf) ;
	}
	fprintf(pf,"};\n#endif\n") ;
	
	fclose(pf) ;
	return 0 ;
}
Exemple #15
0
int read_remote_proxy(char *file, struct nd_proxy_info *proxy_info )
{
	int ret;
	ndxml  *xml_node, *xml_read ;
	ndxml_root xmlroot;

	nd_assert(file) ;
	ret = ndxml_load(file, &xmlroot) ;
	if(0!=ret) {
		return -1;
	}
	xml_node = ndxml_getnode(&xmlroot,"server_config") ;
	if(!xml_node) {		
		ndxml_destroy(&xmlroot);
		return -1;
	}

	//read proxy
	xml_read = ndxml_refsub(xml_node, "proxy") ;
	if(xml_read) {

		ndxml *xmltmp = ndxml_refsub(xml_read, "proxy_type") ;
		if (!xmltmp) 	goto CFG_EXIT ;		
		proxy_info->proxy_type = ndxml_getval_int(xmltmp);
		if(0==proxy_info->proxy_type )goto CFG_EXIT ;

		xmltmp = ndxml_refsub(xml_read, "proxy_host") ;
		if (!xmltmp) 	goto CFG_EXIT ;		
		ndxml_getval_buf(xmltmp, proxy_info->proxy_host, sizeof(proxy_info->proxy_host)) ;


		xmltmp = ndxml_refsub(xml_read, "proxy_port") ;
		if (!xmltmp) 	goto CFG_EXIT ;		
		proxy_info->proxy_port = ndxml_getval_int(xmltmp) ;

		xmltmp = ndxml_refsub(xml_read, "proxy_user") ;
		if (xmltmp)
			ndxml_getval_buf(xmltmp, proxy_info->user, sizeof(proxy_info->user)) ;

		xmltmp = ndxml_refsub(xml_read, "proxy_password") ;
		if (xmltmp) 
			ndxml_getval_buf(xmltmp, proxy_info->password, sizeof(proxy_info->password)) ;
	}

CFG_EXIT:
	ndxml_destroy(&xmlroot);
	return 0;

}
Exemple #16
0
int read_dbconfig(const char *fileName, const char *dbCfgname ,struct nd_db_config *db_cfg)
{
	//ND_TRACE_FUNC() ;
	
	int ret = -1;
	ndxml *xmlroot, *xmlsub, *xmlnode ;
	ndxml_root xmlfile;
	
#define GET_VAL(name)                       \
	xmlnode = ndxml_refsub(xmlsub, #name) ; \
	if (!xmlnode){                          \
		ret = -1;                               \
		goto READ_EXIT ;                        \
	}                                       \
	strncpy(db_cfg->db_##name, ndxml_getval(xmlnode), sizeof(db_cfg->db_##name) )
	
	
	if ( 0 != ndxml_load(fileName , &xmlfile ) ){
		nd_logfatal("read file %s error %s\n", fileName, nd_last_error() ) ;
		return -1;
	}
	
	xmlroot = ndxml_getnode( &xmlfile, "root" ) ;
	if ( !xmlroot )   {
		goto READ_EXIT;
	}
	//read connect config
	xmlsub = ndxml_refsub( xmlroot, dbCfgname ) ;
	if ( !xmlsub )   {
		goto READ_EXIT;
	}
	
	GET_VAL( host ) ;
	GET_VAL( database ) ;
	GET_VAL( user ) ;
	GET_VAL( password) ;
	ret = 0 ;
	
	
READ_EXIT:
	ndxml_destroy( &xmlfile );
	return ret ;
}
Exemple #17
0
int get_name_sort(ndxml_root *xmlfile,name_list_t &res_list)
{
	name_list_t org_list ;
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	
	int total = ndxml_getsub_num(xnode) ;
	
	//get original list
	for (int i=0; i<total; ++i) {
		ndxml *sub = ndxml_refsubi(xnode,i) ;
		ref_order_t node ;
		node.name = ndxml_getname(sub) ;
		node.is_used = 0 ;
		const char *saveDB = ndxml_getattr_val(sub, "saveDB") ;
		if (saveDB) {
			node.is_saveDB = atoi(saveDB) ;
		}
		else {
			node.is_saveDB = 0 ;
		}
		org_list.push_back(node) ;
	}
	//check name 
	for (name_list_t::iterator it= org_list.begin(); it!=org_list.end();++it ) {
		for (name_list_t::iterator it_sub= it + 1; it_sub!=org_list.end();++it_sub ) {
			if (it->name == it_sub->name) {
				fprintf(stderr, "%s name duplicate\n", it->name.c_str());
				exit(1) ;
			}
			
		}
	}
	
	//check  is ref not after this
	int free_numb =(int) org_list.size() ;
	while (free_numb > 0) {
		free_numb = 0 ;
		
		for (name_list_t::iterator it= org_list.begin(); it!=org_list.end();++it ) {
			//cheng reference by other
			if (it->is_used) {
				continue ;
			}
			ndxml *subNode1 = ndxml_refsub(xnode,it->name.c_str()) ;
			int sub_num = ndxml_getsub_num(subNode1) ;
			
			bool is_ref = false ;
			
			for (int i=0; i<sub_num; ++i) {
				ndxml *subNode2 = ndxml_refsubi(subNode1,i) ;
				const char *myName = ndxml_getattr_val(subNode2, "type") ;
				
				for (name_list_t::iterator it_sub= org_list.begin(); it_sub!=org_list.end(); ++it_sub) {
					if (it_sub->is_used || it==it_sub) {
						continue ;
					}
					if (0== strcmp(myName, it_sub->name.c_str()) ) {
						is_ref = true ;
						break ;
					}
				}
			}
			
			if (is_ref==false) {
				res_list.push_back(*it) ;
				it->is_used = 1;
			}
			else {
				++free_numb ;
			}
		}
	}
	return 0;
	
}
Exemple #18
0
//build datatype
int build_dataType(ndxml_root *xmlfile, const char *out_file,bool saveDB)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	ndxml *xInfo = ndxml_getnode(xmlfile, "DataDesc") ;
	if (!xInfo) {
		return -1;
	}
	const char *version = ndxml_getattr_val(xInfo, "version");
	if (!version) {
		return -1;
	}
	const char *comm_version = ndxml_getattr_val(xInfo, "comm_version");
	
	const char *nameSpace = ndxml_getattr_val(xnode, "namespace"); 

	name_list_t res_list ;
	get_name_sort(xmlfile, res_list);
	
	NDUINT64 nowTime = (NDUINT64) time(NULL);
	if (saveDB) {
		
		char buf[128] ;
		snprintf(buf, sizeof(buf), "%s_v%s.h",out_file, version );
		FILE *pf = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error \n", buf ) ;
			return -1 ;
		}
		snprintf(buf, sizeof(buf), "%s_v%s.cpp",out_file, version  );
		FILE *pfCpp = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error \n", buf ) ;
			return -1 ;
		}
		
		_OUT_PUT_TIME(pfCpp) ;
		fprintf(pfCpp, "\n\n#include \"netMessage/dataStream.h\"\n");
		fprintf(pfCpp, "\n\n#include \"netMessage/auto_dataTypeDb_v%s.h\"\n", version );
		//fprintf(pfCpp, "namespace NetMessage \n{\n" );
		if (nameSpace) {
			fprintf(pfCpp, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pfCpp, "/* undefined namespace*/\n{\n");
		}


		
		_OUT_PUT_TIME(pf) ;
		fprintf(pf, "#ifndef _AUTO_DATA_TYPE_DEFINE_DB_%s_H_\n",version );
		fprintf(pf, "#define _AUTO_DATA_TYPE_DEFINE_DB_%s_H_\n",version );
		fprintf(pf, "#include \"netMessage/auto_macroDefine.h\"\n\n") ;
		fprintf(pf, "#include \"netMessage/dataStream.h\"\n\n");
		fprintf(pf, "#include \"netMessage/dataBinary.h\"\n\n");

		if (nameSpace) {
			fprintf(pf, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pf, "/* undefined namespace*/\n{\n");
		}
		
		
		name_list_t save_list;
		get_saveDB_sort(xmlfile,res_list,save_list);
		
		int total =(int) save_list.size(); //ndxml_getsub_num(xnode) ;
		for (int i=0; i<total; ++i) {
			ndxml *sub = ndxml_refsub(xnode,save_list[i].name.c_str()) ;
			_save_dataTypeNode(sub,  pf,pfCpp ,version, true) ;
			fprintf(pf, "\n\n") ;
		}
		fprintf(pf,"};\n\n#endif\n\n") ;
		fclose(pf) ;
		
		fprintf(pfCpp,"};\n\n") ;
		fclose(pfCpp) ;
		
	}
	else {
		
		char buf[128] ;
		snprintf(buf, sizeof(buf), "%s.h",out_file );
		FILE *pf = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error: %s \n", buf , nd_last_error() ) ;
			return -1 ;
		}
		snprintf(buf, sizeof(buf), "%s.cpp",out_file );
		FILE *pfCpp = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error: %s \n", buf, nd_last_error());
			return -1 ;
		}

		_OUT_PUT_TIME(pfCpp) ;
		fprintf(pfCpp, "\n\n#include \"netMessage/auto_dataType.h\"\n" );
		//fprintf(pfCpp, "namespace NetMessage \n{\n" );

		if (nameSpace) {
			fprintf(pfCpp, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pfCpp, "/* undefined namespace*/\n{\n");
		}

		
		_OUT_PUT_TIME(pf) ;
		fprintf(pf, "#ifndef _AUTO_DATA_TYPE_DEFINE_H_\n" );
		fprintf(pf, "#define _AUTO_DATA_TYPE_DEFINE_H_\n" );;
		fprintf(pf, "#include \"netMessage/auto_macroDefine.h\"\n\n") ;
		fprintf(pf, "#include \"netMessage/dataStream.h\"\n\n") ;
		fprintf(pf, "#include \"netMessage/dataBinary.h\"\n\n");

		fprintf(pf, "#define DATA_IN_DB_VERSION %s \n\n", version);
		fprintf(pf, "#define NET_COMMUNATION_VERSION %s \n\n", comm_version);
		fprintf(pf, "#define NET_MESSAGE_EXPORT_TM %lld \n", nowTime);
		

		if (nameSpace) {
			fprintf(pf, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pf, "/* undefined namespace*/\n{\n");
		}

		int total =(int) res_list.size(); //ndxml_getsub_num(xnode) ;
		for (int i=0; i<total; ++i) {
			ndxml *sub = ndxml_refsub(xnode,res_list[i].name.c_str()) ;
// 			if (0 == ndstricmp(sub->name, "CityBase")) {
// 				ND_DebugBreak();
// 			}
			_save_dataTypeNode(sub,  pf,pfCpp, NULL, false) ;
			fprintf(pf, "\n") ;
		}
		
		fprintf(pf,"};\n\n#endif\n\n") ;
		fclose(pf) ;
		
		fprintf(pfCpp,"};\n\n") ;
		fclose(pfCpp) ;
	}

	return 0 ;
}
Exemple #19
0
int set_xml_value(char *file, char *node_name_list, char *attr_name, char*attr_val, char *node_val)
{
    int ret;
    ndxml_root xmlfile;
    
    ndxml *xnode = 0 ;
    
    char *p = node_name_list;
    char name[128] ;
    
    ret = ndxml_load(file, &xmlfile) ;
    if(0!=ret) {
        fprintf(stderr,"load xml from %s\n", file) ;
        return -1;
    }
    
    p = (char*)ndstr_nstr_end(p, name, '.', sizeof(name)) ;
    
    if (IS_NUMERALS(name[0])) {
		xnode = ndxml_getnodei(&xmlfile, ndstr_atoi_hex(name));
    }
    else {
        xnode = ndxml_getnode(&xmlfile, name) ;
    }
    if (!xnode) {
        fprintf(stderr,"read xml-node %s error \n", name) ;
    }
    
    bool success = true ;
    while (p && *p) {
        
        if (*p == '.') {
            ++p ;
            if (!*p) {
                break ;
            }
        }
        
        p = (char*) ndstr_nstr_end(p, name, '.', sizeof(name)) ;
        
        if (IS_NUMERALS(name[0])) {
			xnode = ndxml_refsubi(xnode, ndstr_atoi_hex(name));
        }
        else {
            xnode = ndxml_refsub(xnode, name) ;
        }
        if (!xnode) {
            fprintf(stderr,"read xml-node %s error \n", name) ;
            success = false ;
            break ;
        }
        
        
    }
    if (success) {
        success = false;
        if (attr_name && attr_name[0] && attr_val && attr_val[0]) {
            ndxml_setattrval(xnode,attr_name, attr_val ) ;
            success = true ;
        }
        if (node_val && node_val[0]) {
            ndxml_setval(xnode, node_val) ;
            success = true ;
        }
        if (success) {
            ndxml_save(&xmlfile,file) ;
        }
    }
    
    ndxml_destroy(&xmlfile);
    return success ? 0: -1 ;
}