/* function name: ParseLine * function parameter : * cpLine: any strings of any lines * cpParam: The specified parameter name * cpValue:The specified parameter value * function description: From the value of parameter specifies the parameter name string in a given string line (从给定行字符串中解析出指定参数名的参数值) * returned value: the pointer to the specified parameter value */ static char *ParseLine(char *cpLine, char *cpParam, char *cpValue) { char *cpTmp = NULL; char *cpPtr = NULL; unsigned long ulSepLoc = 0; /*去掉行首的空格*/ cpTmp = TrimLeft(cpLine); /*过滤注释行,即以 # 开头的行, 第一个字符不可以是 = */ if('#' == *cpTmp || '=' == *cpTmp) { return NULL; } /*查找 # 号,移除行末注释*/ ulSepLoc = 0; while(ulSepLoc < strlen(cpTmp)) { if('#' == cpTmp[ulSepLoc]) { break; } ulSepLoc++; } cpTmp[ulSepLoc] = '\0'; /*查找 = */ ulSepLoc = 0; while(ulSepLoc < strlen(cpTmp)) { if('=' == cpTmp[ulSepLoc]) { break; } ulSepLoc++; } if(ulSepLoc == strlen(cpTmp)) { return NULL; } /*获取参数*/ cpTmp[ulSepLoc] = '\0'; cpPtr = TrimStr(cpTmp); if(strcmp(cpPtr, cpParam)) { return NULL; } /*获取参数的值*/ cpPtr = TrimStr(cpTmp + ulSepLoc + 1); strcpy(cpValue, cpPtr); return cpValue; }
void SHVStringUTF8::TrimRight(const SHVChar* trimString) { static const SHVChar DefaultTrimStr[] = {' ','\t','\r','\n','\0'}; SHVString8C TrimStr(DefaultTrimStr); size_t len; if (trimString) TrimStr = trimString; if (IsNull()) return; len = SHVString8C::StrLen(Buffer); while (len > 0) { if (TrimStr.LocateChar(Buffer[len-1])>=0) { if ((len-1) > 0 && Buffer[len-2] > 0) len--; else // unicode char - not a white space after all break; } else break; } Buffer[len] = '\0'; }
BOOL ASZCreateParamCheck(char * aszParams) { BOOL bRet = FALSE; if(aszParams == NULL || strlen(aszParams)<=0) return bRet; { char tmpaszParams[128] = {0}; char * word[16] = {NULL}; strcpy(tmpaszParams, aszParams); if(strstr(tmpaszParams, ",")) { char *buf = tmpaszParams; int i = 0, j = 0; while((word[i] = strtok(buf, ",")) != NULL) { i++; buf=NULL; } if(i==2) { for(j = 0; j <= i; j++) { TrimStr(word[i]); } if(!_stricmp(word[0], "FALSE") || !_stricmp(word[0], "TRUE")) { char * pPercentStr = word[1]; int tmpPercent = 0; BOOL isDigit = TRUE; char *p = pPercentStr; while(*p != '\0') { if(*p < '0' || *p++ > '9') { isDigit = FALSE; break; } } if(isDigit) { tmpPercent = atoi(pPercentStr); if(tmpPercent>=0 && tmpPercent<=100) { bRet = TRUE; } } } } } } return bRet; }
static BOOL GetIniValue(char * iniPath, char * keyWord, char * valueStr) { BOOL bRet = FALSE; if(NULL == iniPath || NULL == keyWord || NULL == valueStr) return bRet; if(app_os_is_file_exist(iniPath)) { FILE * pVNCIniFile = NULL; pVNCIniFile = fopen(iniPath, "rb"); if(pVNCIniFile) { char lineBuf[512] = {0}; while(!feof(pVNCIniFile)) { memset(lineBuf, 0, sizeof(lineBuf)); if(fgets(lineBuf, sizeof(lineBuf), pVNCIniFile)) { if(strstr(lineBuf, keyWord)) { char * word[16] = {NULL}; char *buf = lineBuf; int i = 0, wordIndex = 0; while((word[i] = strtok(buf, "=")) != NULL) { i++; buf=NULL; } while(word[wordIndex] != NULL) { TrimStr(word[wordIndex]); wordIndex++; } if(wordIndex < 2) continue; if(!strcmp(keyWord, word[0])) { strcpy(valueStr, word[1]); bRet = TRUE; break; } } } } fclose(pVNCIniFile); } } return bRet; }
void MMatchConfig::ReadEnableMaps() { char szEnableMap[512]; GetPrivateProfileString("SERVER", "EnableMap", "", szEnableMap, 512, SERVER_CONFIG_FILENAME); char seps[] = ";"; char *token; int nMapCount = 0; token = strtok( szEnableMap, seps ); while( token != NULL ) { char szInputMapName[256] = ""; TrimStr(token, szInputMapName); int nMapIndex = -1; for (int i = 0; i < MMATCH_MAP_MAX; i++) { if (!stricmp(szInputMapName, MGetMapDescMgr()->GetMapName(i))) { nMapIndex = i; break; } } if (nMapIndex != -1) { nMapCount++; m_EnableMaps.insert(set<int>::value_type(nMapIndex)); } // Get next token token = strtok( NULL, seps ); } if (nMapCount <= 0) { for (int i = 0; i < MMATCH_MAP_MAX; i++) m_EnableMaps.insert(set<int>::value_type(i)); m_bRestrictionMap = false; } else { m_bRestrictionMap = true; } }
void CreateASZ(char * aszParams) { recovery_handler_context_t *pRecoveryHandlerContext = (recovery_handler_context_t *)&RecoveryHandlerContext; char createASZMsg[BUFSIZ] = {0}; char aszParamsStr[BUFSIZ] = {0}; char * word[16] = {NULL}; if(NULL == aszParams) return; strcpy(aszParamsStr, aszParams); if(strstr(aszParamsStr, ",")) { char *buf = aszParamsStr; int i = 0, j = 0; while((word[i] = strtok( buf, ",")) != NULL) { i++; buf=NULL; } for(j = 0; j <= i; j++) { TrimStr(word[i]); } } if(!pRecoveryHandlerContext->isCreateASZRunning) { pRecoveryHandlerContext->isCreateASZRunning = TRUE; if (app_os_thread_create(&pRecoveryHandlerContext->acrCreateASZThreadHandle, CreateASZThreadStart, word) != 0) { RecoveryLog(g_loghandle, Normal, "%s()[%d]###Start create ASZ thread failed!\n",__FUNCTION__, __LINE__ ); sprintf(createASZMsg, "%s,%s", "ASZInfo", "Create ASZ thread failed!"); SendReplyMsg_Rcvy(createASZMsg, asz_threadFail, rcvy_create_asz_rep); pRecoveryHandlerContext->isCreateASZRunning = FALSE; } else { sprintf(createASZMsg, "%s,%s", "ASZInfo", "Creating ASZ..."); SendReplyMsg_Rcvy(createASZMsg, asz_creating, rcvy_create_asz_rep); } } }
/************************************* * Trim functions *************************************/ void SHVStringUTF8::TrimLeft(const SHVChar* trimString) { SHVChar* oldBuf = Buffer; size_t cut = 0; static const SHVChar DefaultTrimStr[] = {' ','\t','\r','\n','\0'}; SHVString8C TrimStr(DefaultTrimStr); if (trimString) TrimStr = trimString; if (IsNull()) return; while (Buffer[cut] != '\0') { if (TrimStr.LocateChar(oldBuf[cut])>=0) cut++; else break; } if (cut > 0) { Buffer = NULL; BUFFER_DESTROY2(*this = oldBuf+cut,oldBuf); // sets the new buffer, and destroys the old (heap protection) } }
void read_and_parse_file(const char* filePath) { int ret = -1; FILE* pFile = NULL; pFile = fopen("Bind.txt", "r"); if (NULL == pFile) { std::cout << "Open Bind.txt failed, " << strerror(errno) << std::endl; } else { int index = 0; char* pch = NULL; char szLine[1024] = "\0"; std::map<int, std::string> mapDetector; while(NULL != fgets(szLine, 1024, pFile)) { std::cout << index << " - '" << szLine << "'" << std::endl; printf("addr0:%02hhX,addr1:%02hhX,addr2:%02hhX,addr3:%c,addr4:%c,addr5:%c,addr6:%c\n", szLine[0], szLine[1], szLine[2],szLine[3], szLine[4],szLine[5], szLine[6]); //printf("addr0:%c,addr1:%c,addr2:%c,addr3:%c,addr4:%c,addr5:%c,addr6:%c\n", szLine[0], szLine[1], szLine[2],szLine[3], szLine[4],szLine[5], szLine[6]); int col = 0; pch = strtok(szLine, ","); //if (pch != NULL) //{ printf("addr0:%02hhX,addr1:%02hhX,addr2:%02hhX,addr3:%c,addr4:%c,addr5:%c,addr6:%c\n", szLine[0], szLine[1], szLine[2],szLine[3], szLine[4],szLine[5], szLine[6]); printf("line addr:%p\n", szLine); std::cout << index << " - '" << szLine << "'" << std::endl; while(pch != NULL) { printf("addr:%p\n", pch); std::cout << col << " - '" << pch << "'" << std::endl; switch (col) { case 0: //console(1) << index << " - " << pch << ", "; break; case 1: break; case 2: break; case 3: { //console(1) << pch << std::endl; std::string strDet(pch); TrimStr(strDet); std::cout << strDet << std::endl; mapDetector.insert(std::pair<int, std::string>(index, strDet)); } break; default: break; } col++; pch = strtok(NULL, ","); } //} pch = NULL; //memset(szLine, 0, 1024); index++; } } }