⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preuser.cc

📁 可以对从数据库导出的数据文件进行纠错处理
💻 CC
📖 第 1 页 / 共 3 页
字号:
	while(1)	{		pTemp = pToken;		pToken = strchr(pToken, '|');		if ( pToken == NULL ) break;		*pToken++ = 0;				acct.push_back(TVecType(pTemp));	}}// 获得占用资源信息void getServAcctInfo(const string& strServAcct, TServAcct* serv_acct){	char*	pToken;	char*	pTemp;	char	strTemp[LINE_MAX_LEN];	int		iTemp;		strTemp[0] = 0;		snprintf(strTemp, LINE_MAX_LEN, "%s", strServAcct.c_str());			pToken = strTemp;	iTemp = 1;	while(1)	{		pTemp = pToken;		pToken = strchr(pToken, '|');		if ( pToken == NULL ) break;		*pToken++ = 0;		switch(iTemp)		{			case SERV_ACCT_SERV_ID_POS :				// 获得用户标识				snprintf(serv_acct->serv_id, sizeof(serv_acct->serv_id), "%s", pTemp);				//cout << "serv_acct->serv_id = " << serv_acct->serv_id << endl;				break;			case SERV_ACCT_SEQ_NBR_POS :				// 获得seq_nbr				snprintf(serv_acct->seq_nbr, sizeof(serv_acct->seq_nbr), "%s", pTemp);				//cout << "serv_acct->seq_nbr = " << serv_acct->seq_nbr << endl;				break;			case SERV_ACCT_ACCT_ID_POS :				// 获得帐户标识				snprintf(serv_acct->acct_id, sizeof(serv_acct->acct_id), "%s", pTemp);				//cout << "serv_acct->acct_id = " << serv_acct->acct_id << endl;				break;			case SERV_ACCT_ACCT_ITEM_TYPE_ID_POS :				// 获得账目类型标识				snprintf(serv_acct->acct_item_type_id, sizeof(serv_acct->acct_item_type_id), "%s", pTemp);				//cout << "serv_acct->acct_item_type_id = " << serv_acct->acct_item_type_id << endl;				break;			case SERV_ACCT_STATE_POS :				// 获得状态				snprintf(serv_acct->state, sizeof(serv_acct->state), "%s", pTemp);				//cout << "serv_acct->state = " << serv_acct->state << endl;				break;		}		iTemp++;	}}// 获得占用资源信息void getServProdInfo(const string& strServProd, TServProd* serv_prod){	char*	pToken;	char*	pTemp;	char	strTemp[LINE_MAX_LEN];	int		iTemp;		strTemp[0] = 0;		snprintf(strTemp, LINE_MAX_LEN, "%s", strServProd.c_str());			pToken = strTemp;	iTemp = 1;	while(1)	{		pTemp = pToken;		pToken = strchr(pToken, '|');		if ( pToken == NULL ) break;		*pToken++ = 0;		switch(iTemp)		{			case SERV_PROD_SERV_ID_POS :				// 获得用户标识				snprintf(serv_prod->serv_id, sizeof(serv_prod->serv_id), "%s", pTemp);				//cout << "serv_prod->serv_id = " << serv_prod->serv_id << endl;				break;			case SERV_PROD_PRODUCT_ID_POS :				// 获得资源标识				snprintf(serv_prod->product_id, sizeof(serv_prod->product_id), "%s", pTemp);				//cout << "serv_prod->product_id = " << serv_prod->product_id << endl;				break;			case SERV_PROD_SEQ_NBR_POS :				// 获得序列号				snprintf(serv_prod->seq_nbr, sizeof(serv_prod->seq_nbr), "%s", pTemp);				//cout << "serv_prod->seq_nbr = " << serv_prod->seq_nbr << endl;				break;			case SERV_PROD_PRODUCT_QUANTITY_POS :				// 获得资源数量				snprintf(serv_prod->product_quantity, sizeof(serv_prod->product_quantity), "%s", pTemp);				//cout << "serv_prod->product_quantity = " << serv_prod->product_quantity << endl;				break;			case SERV_PROD_STATE_POS :				// 获得状态				snprintf(serv_prod->state, sizeof(serv_prod->state), "%s", pTemp);				//cout << "serv_prod->state = " << serv_prod->state << endl;				break;		}		iTemp++;	}}// 拆分处理过的帐务关系数据void splitServAcctInfo(const string& strServAcct, TServAcct1& serv_acct){	char*	pToken;	char*	pTemp;	char	strTemp[LINE_MAX_LEN];		strTemp[0] = 0;	snprintf(strTemp, LINE_MAX_LEN, "%s", strServAcct.c_str());	pToken = strTemp;		pTemp = pToken;	pToken = strchr(pToken, '|');	*pToken++ = 0;	snprintf(serv_acct.serv_id, sizeof(serv_acct.serv_id), "%s", pTemp);		pTemp = pToken;	pToken = strchr(pToken, '|');	*pToken++ = 0;	snprintf(serv_acct.acct_id, sizeof(serv_acct.acct_id), "%s", pTemp);	}// 拆分处理过的占用资源数据void splitServProdInfo(const string& strServProd, TServProd1& serv_prod){	char*	pToken;	char*	pTemp;	char	strTemp[LINE_MAX_LEN];		strTemp[0] = 0;	snprintf(strTemp, LINE_MAX_LEN, "%s", strServProd.c_str());	pToken = strTemp;		pTemp = pToken;	pToken = strchr(pToken, '|');	*pToken++ = 0;	snprintf(serv_prod.serv_id, sizeof(serv_prod.serv_id), "%s", pTemp);		pTemp = pToken;	pToken = strchr(pToken, '|');	*pToken++ = 0;	snprintf(serv_prod.product_id, sizeof(serv_prod.product_id), "%s", pTemp);		pTemp = pToken;	pToken = strchr(pToken, '|');	*pToken++ = 0;	snprintf(serv_prod.product_quantity, sizeof(serv_prod.product_quantity), "%s", pTemp);	}// 装载帐务关系信息void loadServAcctInfo(){	FILE*		stream;	char		strBuff[FILTER_LINE_LEN];	char*		strLine;	int			iLineNo;	TServAcct1	serv_acct;		iLineNo = 0;		stream = fopen(mapFileDir["serv_acct_out"].c_str(), "r");	if( stream == NULL )	{		rlogit(PREUSER_ERR(-3), "%s [%s].", "Could not open file", mapFileDir["serv_acct_out"].c_str());		return;	}		while(!feof(stream))	{		memset(strBuff, 0, FILTER_LINE_LEN);		iLineNo++;		if(fgets(strBuff, FILTER_LINE_LEN, stream) == NULL) continue;		strLine = trim(strBuff);				if(strlen(strLine) == 0) continue;				// 拆分帐务关系信息		splitServAcctInfo(strLine, serv_acct);				// 插入帐务关系全局数据结构		mapServAcct1.insert(TServAcct1Maptype(serv_acct.serv_id, serv_acct));	}	fclose(stream);}// 装载帐户信息void loadAcctInfo(){	FILE*		stream;	char		strBuff[FILTER_LINE_LEN];	char*		strLine;	int			iLineNo;		iLineNo = 0;		stream = fopen(mapFileDir["acct_out"].c_str(), "r");	if( stream == NULL )	{		rlogit(PREUSER_ERR(-3), "%s [%s].", "Could not open file", mapFileDir["acct_out"].c_str());		return;	}		while(!feof(stream))	{		memset(strBuff, 0, FILTER_LINE_LEN);		iLineNo++;		if(fgets(strBuff, FILTER_LINE_LEN, stream) == NULL) continue;		strLine = trim(strBuff);				if(strlen(strLine) == 0) continue;				// 拆分帐务关系信息		char*	pToken;		char*	pTemp;		char	strAcctId[17];		char	strAcctName[61];				strAcctId[0] = 0;		strAcctName[0] = 0;			pToken = strLine;				pTemp = pToken;		pToken = strchr(pToken, '|');		*pToken++ = 0;		snprintf(strAcctId, sizeof(strAcctId), "%s", pTemp);				pTemp = pToken;		pToken = strchr(pToken, '|');		*pToken++ = 0;		snprintf(strAcctName, sizeof(strAcctName), "%s", pTemp);				// 插入帐户全局数据结构		mapAcct1.insert(TMaptype(strAcctId, strAcctName));	}	fclose(stream);}// 装载客户信息void loadCustInfo(){	FILE*		stream;	char		strBuff[FILTER_LINE_LEN];	char*		strLine;	int			iLineNo;		iLineNo = 0;		stream = fopen(mapFileDir["cust_out"].c_str(), "r");	if( stream == NULL )	{		rlogit(PREUSER_ERR(-3), "%s [%s].", "Could not open file", mapFileDir["cust_out"].c_str());		return;	}		while(!feof(stream))	{		memset(strBuff, 0, FILTER_LINE_LEN);		iLineNo++;		if(fgets(strBuff, FILTER_LINE_LEN, stream) == NULL) continue;		strLine = trim(strBuff);				if(strlen(strLine) == 0) continue;				// 拆分帐务关系信息		char*	pToken;		char*	pTemp;		TVector cust;				pToken = strLine;				while(1)		{			pTemp = pToken;			pToken = strchr(pToken, '|');			if ( pToken == NULL ) break;			*pToken++ = 0;						cust.push_back(TVecType(pTemp));		}				mapCust1.insert(TCustMaptype(cust[CUST_CUST_ID_1_POS], cust));	}	fclose(stream);}// 装载占用资源信息void loadServProdInfo(){	FILE*		stream;	char		strBuff[FILTER_LINE_LEN];	char*		strLine;	int			iLineNo;	TServProd1	serv_prod;		iLineNo = 0;		stream = fopen(mapFileDir["serv_prod_out"].c_str(), "r");	if( stream == NULL )	{		rlogit(PREUSER_ERR(-3), "%s [%s].", "Could not open file", mapFileDir["serv_prod_out"].c_str());		return;	}		while(!feof(stream))	{		memset(strBuff, 0, FILTER_LINE_LEN);		iLineNo++;		if(fgets(strBuff, FILTER_LINE_LEN, stream) == NULL) continue;		strLine = trim(strBuff);				if(strlen(strLine) == 0) continue;				// 拆分占用资源信息		splitServProdInfo(strLine, serv_prod);				// 插入占用资源全局数据结构		mapServProd1.insert(TServProd1Maptype(serv_prod.serv_id, serv_prod));	}}void writeErrorInfo(const string& strLine, const string& strErrInfo){	FILE*	stream;	string	strTemp;	string	strFileName;		stream = fopen(mapFileDir["err_info"].c_str(), "a");	if( stream == NULL )	{		rlogit(PREUSER_ERR(-6), "Could not open file [%s].\n", mapFileDir["err_info"].c_str());		exit(-1);	}		fprintf(stream, "error reason: [%s]	data: [%s].\n", strErrInfo.c_str(), strLine.c_str());	fclose(stream);}// 去掉右边的空格void rtrim(char *strIn){	char * p = strIn, * p1;	for(p1=strIn; *p1 != 0; p1 ++)		if(!isspace(*p1)) {			p = p1;			p ++;		}	*p = 0;}// 去掉左边的空格char* ltrim(char *strIn){	char * p;	for(p = strIn; *p != 0 ; p ++)		if(!isspace(*p)) 			break;	return p;}// 去掉左右的空格char* trim(char *strIn){	rtrim(strIn);	return ltrim(strIn);}// 判断是否是注释int IsComment(const char *strLine){	const char * p = strLine;	while(*p && isspace(*p))p++;	return *p=='#';}// 获得配置信息键值对int GetInfoBySection(const string& strFileName, const string& strSection, TMap& mapInfo){	static const char *func = "GetInfoBySection";	FILE	*stream;	char	strLine[LINE_MAX_LEN];	int		iLineNo;	int		iFound;	char	*strTemp;	char	*strKey;	char	*strValue;		// 打开配置文件	stream = fopen(strFileName.c_str(), "r");	if(stream == NULL)	{		rlogit(PREUSER_ERR(-1), "Could not open file [%s].", strFileName.c_str());		return -1;	}		memset(strLine, 0, LINE_MAX_LEN);		iLineNo = 0;	iFound = 0;	// 确定配置段	while(!feof(stream))	{		iLineNo++;		if(fgets(strLine, LINE_MAX_LEN, stream) == NULL) continue;		if(strlen(strLine) == LINE_MAX_LEN - 1)		{			fclose(stream);			rlogit(PREUSER_ERR(-2), "file [%s] line [%d] is too long.", strFileName.c_str(), iLineNo);			return -2;		}				if(strLine[0] != '[') continue;		// 如果找到段标记		if(strncmp(strLine, strSection.c_str(), strSection.length()) == 0)		{			iFound = 1;			break;		}	}	/* end while */		if(iFound == 0) 	{		fclose(stream);		rlogit(PREUSER_ERR(-3), "not found section [%s].", strSection.c_str());		return -3;	}		// 获得段中的所有关键字	while(!feof(stream))	{		iLineNo++;		// 从文件中读取一行数据		if(fgets(strLine, LINE_MAX_LEN, stream) == NULL) continue;		// 判断文件行的是否超出最大长度		if(strlen(strLine) == LINE_MAX_LEN - 1)		{			fclose(stream);			rlogit(PREUSER_ERR(-4), "file [%s] line [%d] is too long.", strFileName.c_str(), iLineNo);			return -4;		}		// 读到注释行退出		if(IsComment(strLine)) continue;		// 读到下一个段退出		if(strLine[0] == '[') break;		// 查找行尾注释		strTemp = strchr(strLine, '#');		if(strTemp != NULL)			*strTemp = '\0';		// 按=号分割		strKey = strtok(strLine, "=");		// 读到空行		if(strKey == NULL) continue;		// 获得关键字,去掉空格		strKey = trim(strKey);		//获得值,去掉空格		strValue = strtok(NULL, "=");		if(strValue != NULL)			strValue = trim(strValue);		else			strValue = "";		// 向属性对HASH表中添加属性对		mapInfo.insert(TMaptype(strKey, strValue));			}	/* end while */		fclose(stream);	return 0;}// 日志处理函数void _rlogit(int iErrorId, const char *format, ...){	FILE	*ostream = NULL;	va_list	ap;	char	strBuffer[1024];	char	strTime[21];	time_t	tNow, tTemp;		memset(strBuffer, 0, 1024);	memset(strTime, 0, 21);		time(&tNow);	strftime(strTime, 21, "%Y-%m-%d %H:%M:%S", localtime(&tNow));	va_start(ap, format);	vsprintf(strBuffer, format, ap);		#ifdef	_LOG_DEBUG_		printf("%s: error_code: %d, error_info: %s\n", strTime, iErrorId, strBuffer);	#endif		#ifdef	_LOG_FILE_		if((ostream = fopen(mapFileDir["log_file"].c_str(), "a")) == NULL)		{			printf("open log file error.\n");			return;		}		fprintf(ostream, "%s: error_code: %d, error_info: %s\n", strTime, iErrorId, strBuffer);		fflush(ostream);		fclose(ostream);	#endif		va_end(ap);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -