Beispiel #1
0
void LFMessageBox::alert(string title,string msg)
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
	string out1;
	string out2;
	utf8_to_gbk(title,out1);
	utf8_to_gbk(msg,out2);
	CCMessageBox(out2.c_str(),out1.c_str());
#else
	CCMessageBox(msg.c_str(),title.c_str());
#endif
}
Beispiel #2
0
void CSvsFile::LoadXML()
{
	UnloadXML();
	TiXmlDocument XmlDoc;
	XmlDoc.SetCondenseWhiteSpace(false);
	ifstream iXML( m_strFile.c_str() );
	if (!iXML)
	{
		GenErr("技能配置表转换文件读取错误", m_strFile);
	}
	iXML>>XmlDoc;
	iXML.close();

	TiXmlNode* pBody = XmlDoc.FirstChild("body");
	TiXmlNode* pTable = pBody->FirstChild("table");

	for ( TiXmlNode* pTr = pTable->FirstChild(); pTr; pTr = pTr->NextSibling() )
	{
		TiXmlElement* pElemet = pTr->ToElement();
		if (!pElemet)
			continue;

		if(pElemet->ValueStr() != "tr")
			continue;

		m_vecTR.resize(m_vecTR.size() + 1);
		TableRow& vecTD = m_vecTR.back();		
		for ( TiXmlNode* pTd = pTr->FirstChild(); pTd; pTd=pTd->NextSibling() )
		{
			TiXmlElement* pElemet = pTd->ToElement();
			if (!pElemet)
				continue;

			if(pElemet->ValueStr() != "td")
				continue;

			TiXmlNode* pParagraph = pTd->FirstChild();
			TiXmlElement* pParaElemet = pParagraph->ToElement();
			if(!pParaElemet || pParaElemet->ValueStr() != "p")
			{
				GenErr("<td>读取<p>不存在");
			}

			TableData aTD;

			aTD.m_eTDType = GetTableDataType(pParaElemet->Attribute("t"));
			if(pParaElemet->FirstChild())
			{
				aTD.m_sTDValue = utf8_to_gbk(pParaElemet->GetText());
				XMLDecode(aTD.m_sTDValue);
			}

			vecTD.push_back(aTD);
		}
	}
}
//========================================================================================================================
void lcd_display_handle(unsigned char *dat, unsigned short len)
{
	unsigned short  display_buf_len = len;
	unsigned char   display_buff[MAX_DISPLAY_BUFF_SIZE/2];
	unsigned short  tmpLen = 0;

	//display_gb18030_string(dat, len, 0, 0);
	memset(display_buff, 0x00, MAX_DISPLAY_BUFF_SIZE/2);
	if (utf8BuffLen2)
	{
		unsigned char slen = utf8BuffLen1-utf8BuffLen2;
		if ( (utf8BuffLen1-utf8BuffLen2) > display_buf_len)
		{
			memcpy(utf8Buff+utf8BuffLen2, &dat[0], display_buf_len);
			utf8BuffLen2 += display_buf_len;
			return;
		}
		memcpy(utf8Buff+utf8BuffLen2, &dat[0], utf8BuffLen1-utf8BuffLen2);

		display_buf_len = utf8_to_gbk(utf8Buff, utf8BuffLen1, display_buff, utf8Buff, &utf8BuffLen1, &utf8BuffLen2);
		copy_display_data_to_buff( display_buff, display_buf_len);
		display_buf_len = len - slen;
		tmpLen = slen;
		memset(utf8Buff, 0x00, sizeof(utf8Buff));
		utf8BuffLen1 = 0;
		utf8BuffLen2 = 0;
	}
	memset(display_buff, 0x00, MAX_DISPLAY_BUFF_SIZE/2);
	display_buf_len = utf8_to_gbk(&dat[0+ tmpLen], display_buf_len, display_buff, utf8Buff, &utf8BuffLen1, &utf8BuffLen2);


	LcdDispPara.lcd_page = 0;
	LcdDispPara.lcd_col = 0;
	copy_display_data_to_buff( display_buff, display_buf_len);
	//display_gb18030_string(display_buff, display_buf_len, 0, 0);
	/*************************************************************************************/
}
Beispiel #4
0
int SXmlDocument::SaveToString(std::string &str)
{	
	xmlChar *xmlbuff=NULL;
	int buffersize;
	std::string output="";

	if (!_doc)
		return -1;
	int ret=0;
	xmlDocDumpFormatMemory(_doc, &xmlbuff, &buffersize, 1);
	if(!xmlbuff){
		return -1;
	}
	char * buf = (char *)xmlbuff;
	for (int i=0;i<buffersize;i++)
		output += buf[i];
	
	
	//WEBSEARCH_DEBUG((LM_ERROR, "SXmlDocument::SaveToString : %s\n",output.c_str()));
	if (_encoding == "utf-16"){	

		ret = ChangeEncodeDeclaration(output,output,"utf-8","utf-16");		
		ret = utf8_to_utf16(output,output);
		if (ret<0){
			xmlFree(xmlbuff);
			return -1;
		}
			
	}else if (_encoding == "gbk"){
		
		ret = utf8_to_gbk(output,output);
		
		if (ret < 0){
			xmlFree(xmlbuff);
			return -1;
		}
		ret = ChangeEncodeDeclaration(output,output,"utf-8","gbk");		
		//WEBSEARCH_DEBUG((LM_ERROR, "SXmlDocument::SaveToString : %s\n",_encoding.c_str()));
	}else if (_encoding == "utf-8"){

	}else{
	}
	
	str = output;
	xmlFree(xmlbuff);
	
	return 0;
}
Beispiel #5
0
void utf8_gbk_test(void)
{
    //char buf[512] = "外边的字到底怎么为什么有的时候通不过呢";
    //utf8_to_gbk(buf, sizeof(buf));
    //gbk_to_utf8(buf, sizeof(buf));

    char line[MAX_LINE];
    int ret = 0;
    FILE* fp = fopen("input.txt","r");
    FILE* fp_gbk = fopen("out.gbk", "w");

    rewind(fp);
    while((ret = st_getline(line, fp)) > 0)
	{
        utf8_to_gbk(line, MAX_LINE);
        fputs(line, fp_gbk);
    }
    fclose(fp);
    fclose(fp_gbk);

    fp_gbk = fopen("out.gbk", "r");
    FILE* fp_utf8 = fopen("out.utf8", "w");
    rewind(fp_gbk);
    while((ret = st_getline(line, fp_gbk)) > 0)
    {
        gbk_to_utf8(line, MAX_LINE);
        fputs(line, fp_utf8);
    }


    fclose(fp_gbk);
    fclose(fp_utf8);

    st_print("TEST TERMINATED!\n");

    return;
}
Beispiel #6
0
int SXmlDocument::SaveToStringWithEncode(std::string &str,std::string out_encode)
{	
	xmlChar *xmlbuff;
	int buffersize;
	std::string output="";
	toLower(out_encode);

	if (!_doc)
		return -1;
	xmlDocDumpFormatMemory(_doc, &xmlbuff, &buffersize, 1);
	char * buf = (char *)xmlbuff;
	for (int i=0;i<buffersize;i++)
		output += buf[i];	
	
	int ret = 0;

	//WEBSEARCH_DEBUG((LM_ERROR, "SXmlDocument::SaveToString : %s\n",output.c_str()));
	if (out_encode == "utf-16"){	

		ret = ChangeEncodeDeclaration(output,output,"utf-8","utf-16");		
		utf8_to_utf16(output,output);
	}else if (out_encode == "gbk" || out_encode == "gb18030"){
		
		utf8_to_gbk(output,output);
		ret = ChangeEncodeDeclaration(output,output,"utf-8",out_encode);		
		//WEBSEARCH_DEBUG((LM_ERROR, "SXmlDocument::SaveToString : %s\n",_encoding.c_str()));
	}else if (_encoding == "utf-8"){

	}else{
	}
	
	str = output;
	xmlFree(xmlbuff);
	
	return ret;
}
Beispiel #7
0
void* 
thread_recv(void* args){
	assert(args);
	assert(g_apex_cfg);   
	assert(g_zmq_context);

	char* broker = (char*)args; 

	char temp[256];
	sprintf(temp, "%s", broker);
	char* host = strtok(temp, ":");
	char* portstr = strtok(NULL, ":");
	assert(host);
	assert(portstr);
	int port = atoi(portstr);   

	zbusconn_cfg_t conn_cfg; 
	memset(&conn_cfg, 0, sizeof(conn_cfg));
	conn_cfg.ctx = g_zmq_context;
	conn_cfg.verbose = g_apex_cfg->debug; 
	strcpy(conn_cfg.host, host);
	conn_cfg.port = port; 

	zbusconn_t* zbus_conn = zbusconn_new(&conn_cfg);   

	zbuswrk_cfg_t wrk_cfg;
	memset(&wrk_cfg, 0, sizeof(wrk_cfg));
	strcpy(wrk_cfg.service, g_apex_cfg->service_name);
	strcpy(wrk_cfg.reg_token, g_apex_cfg->service_regtoken);
	strcpy(wrk_cfg.acc_token, g_apex_cfg->service_acctoken);
	strcpy(wrk_cfg.mode, MODE_LB);

	zbuswrk_t* worker = zbuswrk_new(&wrk_cfg);
	assert(worker);

	int rc; 
	char value_data[VALUE_MAX_LEN];
	char msg_data[VALUE_MAX_LEN];

	
	HANDLE_CONN apex_conn = Fix_Connect(g_apex_cfg->apex_address,
		g_apex_cfg->apex_user,g_apex_cfg->apex_pwd, g_apex_cfg->apex_timeout);
	if(apex_conn){
		zlog("APEX Connected\n");
	}
	while(1){   
		while(!apex_conn){
			zlog("APEX(%s) down, reconnecting...\n", g_apex_cfg->apex_address);
			apex_conn = Fix_Connect(g_apex_cfg->apex_address,
				g_apex_cfg->apex_user,g_apex_cfg->apex_pwd,g_apex_cfg->apex_timeout);
			if(apex_conn){
				zlog("APEX Connected\n");
			}
			zclock_sleep(g_apex_cfg->apex_reconnect);
		}
		zmsg_t* request = zbuswrk_recv(zbus_conn, worker);
		if(!request) break;  

		zframe_t* sock_id, *msg_id;
		zbuswrk_get_address(worker, &sock_id, &msg_id);

		if(zmsg_frame_size(request) != 2){
			zmsg_destroy(&request); 
			zmsg_t* reply = zmsg_new(); 
			zmsg_push_back(reply, zframe_newstr("400"));
			zmsg_push_back(reply, zframe_newstr("request format: <funcid> <json_params>"));

			s_client_reply(zbus_conn, sock_id, msg_id, reply);
			continue;
		}

		zframe_t* funcid_frame = zmsg_pop_front(request);
		char* funcid_str = zframe_strdup(funcid_frame);
		long funcid = atol(funcid_str);

		zframe_t* params_frame = zmsg_pop_front(request); 
		char* params_json = zframe_strdup(params_frame);  
		
		HANDLE_SESSION sess = Fix_AllocateSession(apex_conn);
		Fix_SetGYDM(sess, "99999998"); 
		Fix_SetFBDM(sess, "9999");
		Fix_CreateReq(sess, funcid);
		
		cJSON* json = cJSON_Parse(params_json);  
		if(json){
			cJSON* param = json->child;
			while(param && param->string){
				long key = atol(param->string);
				char* val = param->valuestring; 
				if(!val) val = "";
				char* val_utf8 = utf8_to_gbk(val); 
				Fix_SetString(sess, key, val_utf8);
				delete[] val_utf8;

				param = param->next;
			}
			cJSON_Delete(json);
		} else {
			zframe_destroy(&funcid_frame); 
			zfree(funcid_str); 
			zframe_destroy(&params_frame);
			zfree(params_json);
			zmsg_destroy(&request);
			Fix_ReleaseSession(sess);
			continue;
		}

		rc = Fix_Run(sess);     
		if(rc){  
			zmsg_t* reply = zmsg_new(); 
			zmsg_push_back(reply, zframe_newstr("200"));

			cJSON* root = cJSON_CreateArray();
			int rows = Fix_GetCount(sess);
			for(int i=0; i<rows; i++){
				int cols = Fix_GetColumnCount(sess, i);
				cJSON* row = cJSON_CreateObject();
				for(int j=0; j<cols; j++){
					long key = 0; 
					int size = VALUE_MAX_LEN; 
					Fix_GetValWithIdByIndex(sess, i, j, key, value_data, size);
					char key_str[32];
					sprintf(key_str, "%d", key);
					value_data[size] = '\0';
					char* value_data_utf8 = gbk_to_utf8(value_data); 
					cJSON_AddStringToObject(row, key_str, value_data_utf8); 
					delete[] value_data_utf8;
				}
				cJSON_AddItemToArray(root, row);
			} 
			if(rows == 0){
				Fix_GetItem(sess, FID_MESSAGE, msg_data, sizeof(msg_data));
				root->valuestring = msg_data;
			}
			char* json_data = cJSON_Print(root); 
			zmsg_push_back(reply, zframe_newstr(json_data));
			free(json_data);
			s_client_reply(zbus_conn, sock_id, msg_id, reply);
		} else {
			long code = Fix_GetCode(sess);
			Fix_GetErrMsg(sess, msg_data, sizeof(msg_data));
			zlog("WARN: APEX failed(code=%d,msg=%s)\n", code, msg_data);

			zmsg_t* reply = zmsg_new(); 
			zmsg_push_back(reply, zframe_newstr("500"));
			zmsg_push_back(reply, zframe_newstr(msg_data));

			s_client_reply(zbus_conn, sock_id, msg_id, reply);

			zframe_destroy(&sock_id);
			zframe_destroy(&msg_id);
		} 
		Fix_ReleaseSession(sess);


		zframe_destroy(&funcid_frame); 
		zfree(funcid_str); 
		zframe_destroy(&params_frame);
		zfree(params_json);
		zmsg_destroy(&request);  
		
	}   

	zfree(broker);
	zbusconn_destroy(&zbus_conn); 
	Fix_Close(apex_conn);

	return NULL;
} 
Beispiel #8
0
int main(int argc, char* argv[])
{
	if (argc != 2) {
		usage();
		exit(-1);
	}
	char* sample_file = argv[1];
	FILE* fp = fopen(sample_file, "rb");
	if (fp == NULL) {
		printf("open file failed\n");
		exit(-1);
	}
	fseek(fp, 0, SEEK_END);
	int size = ftell(fp);
	fseek(fp, 0, SEEK_SET);
	char* buffer = (char*)malloc(size);
	memset(buffer, 0, size);
	fread(buffer, 1, size, fp);
	int fd = open_dump_buffer((unsigned char*)buffer, size);
	if (fd == INVALID_DUMP_BUFFER) {
		printf("open_dump_buffer failed");
		exit(-1);
	}

	string_t* str = dump_string_first(fd);
	for(; str != NULL; str = dump_string_next(fd)) {
		unsigned int offset = str->offset;
		unsigned char* start = str->offset + (unsigned char*)buffer;
		int len = str->len;
		if (str->codeset == CHARSET_UTF8) {
			//UTF转GB2312
			char* gbk = utf8_to_gbk(start, str->len);
			if (gbk == NULL) {
				printf("UTF8: 0x%08X %d ########\n", offset, len);
			} else {
				printf("UTF8: 0x%08X %d %s\n", offset, len, gbk);	
			}
		} else if(str->codeset == CHARSET_ASCII) {
			printf("ASCII: 0x%08X %d %.*s\n", offset, len,  str->len, start );
		} else if(str->codeset == CHARSET_UNICODE) {
			char* gbk = unicode_to_gbk(start, str->len);
			if (gbk == NULL) {
				printf("UNICODE: 0x%08X %d ########\n", offset, len);
			} else {
				printf("UNICODE: 0x%08X %d %s\n", offset, len, gbk);
			}
		} else if(str->codeset == CHARSET_GB2312) {
			char* gbk = gb2312_to_gbk(start, str->len);
			if (gbk == NULL) {
				printf("GB2312: 0x%08X %d ########\n", offset, len);
			} else {
				printf("GB2312: 0x%08X %d %s\n", offset, len, gbk);
			}
		} else {
			printf("UNKNOWN CHARSET\n");
			continue;
		}
	}

	close_dump_buffer(fd);

	fclose(fp);
}