Пример #1
0
static int exp_enum(ndxml *node, FILE *pf)
{
	int total =(int) ndxml_getsub_num(node) ;
	for (int i=0; i<total; ++i) {
		ndxml *sub = ndxml_getnodei(node, i);
		nd_assert(sub) ;
		
		const char *pcomment = ndxml_getattr_val(sub, "comment") ;
		if (pcomment) {
			fprintf(pf, "// %s \n", pcomment) ;
		}
		
		fprintf(pf, "enum %s { \n", ndxml_getname(sub)) ;
		for (int x=0; x< ndxml_getsub_num(sub); ++x) {
			ndxml *element = ndxml_getnodei(sub, x) ;
			pcomment = ndxml_getattr_val(element, "comment") ;
			const char *pvalue = ndxml_getattr_val(element, "value") ;
			
			if (pvalue && pvalue[0] ) {
				fprintf(pf, "\t%s =%s,//%s\n", ndxml_getname(element),pvalue, pcomment?pcomment:"\t " ) ;
			}
			else {
				fprintf(pf, "\t%s,//%s\n", ndxml_getname(element),  pcomment?pcomment:"\t ");
			}
		}
		
		fprintf(pf, "};\n\n\n") ;
	}
	
	return 0;
}
Пример #2
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;
			}
		}

	}
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
int read_config(ndxml *xmlroot, const char *name, struct server_config *scfg) 
{
	ndxml *xml_sub,*xml_listen ;
	
	int base_port = read_base_port(xmlroot) ;

	memset(scfg, 0, sizeof(scfg)) ;
	if (0==base_port) {
		return -1;
	}
	
	xml_sub = ndxml_refsub(xmlroot,name) ;
	if (!xml_sub){
		T_ERROR("read base port error") ;
	}

	if(-1== read_instance_info(xml_sub, &scfg->i_cfg)) {
		return -1 ;
	}


	xml_listen = ndxml_refsub(xml_sub,"listen") ;
	if (!xml_listen){
		T_ERROR("read base port error") ;
	}	
	if(-1== read_listen_cfg(xml_listen,  base_port,&scfg->l_cfg) ) {
		return -1 ;
	}
	//

	scfg->reliable_num = 0;
	xml_listen = ndxml_refsub(xml_sub,"reliable_host") ;
	if (xml_listen){
		read_iplist(xml_listen, scfg->reliable_hosts, MAX_RELIABLE_HOST ) ;
		for(int i=0; i<MAX_RELIABLE_HOST; i++) {
			union {
				ndip_t ip ;
				NDUINT8 buf[4] ;
			}readip,ipmask;

			readip.ip = scfg->reliable_hosts[i] ;
			if (readip.ip ==0){
				break ;
			}
			ipmask.ip = 0xffffffff;
			for (int x=0; x<4; x++)	{
				if (0xff== readip.buf[x]){
					ipmask.buf[x] = 0 ;
				}
			}
			scfg->reliable_ipmask[i] = ipmask.ip;
			scfg->reliable_num++;
		}
		//get netmask
	}
	//read connectors
	
	xml_listen = ndxml_refsub(xml_sub,"connectors") ;
	if (xml_listen){
		for (int i=0; i< ND_CONNECT_OTHER_HOSTR_NUM && i<ndxml_num(xml_listen); i++) {
			ndxml *pnode = ndxml_getnodei(xml_listen, i) ;
			
			if(0== read_connect_cfg(pnode,  base_port, &scfg->i_cfg.connectors[i]) ) {
				const char *pname = ndxml_getattr_val(pnode, "name") ;
				if (pname && pname[0]) {
					strncpy(scfg->i_cfg.connectors[i].connector_name, pname,sizeof(scfg->i_cfg.connectors[i].connector_name)) ;
				}
				else {
					pname = ndxml_getname(pnode) ;
					strncpy(scfg->i_cfg.connectors[i].connector_name, pname,sizeof(scfg->i_cfg.connectors[i].connector_name)) ;
				}
			}
		}
	}
	
	return 0 ;
}
Пример #6
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 ;
}