#include "file_io.h" void _write_config_file(char *cfgname) { } void __read_config_file(char *cfgName) { } /** *@brief 从给定字符串中提取key和value对。 *处理字符串data,从中取出第一个key和value并存入key和value *@param data 要解析的字符串 *@param key 保存提取到的KEY串 *@param value 保存提取到的value串 *@param maxlen key和value能容忍的最大字符串长度 *@return 处理完字符串后,指针指向的位置 * */ char *sysfunc_get_key_value(char *data, char *key, char *value, int maxlen) { int i = 0; char *temp = data; while(*temp && *temp == ';') temp++; while(*temp && *temp != ';' && *temp != '=' && i < maxlen) { key[i++] = *temp++; } key[i] = '\0'; if (*temp == ';' || *temp == '\0') value[0] = '\0'; else if(*temp == '=') { i = 0; temp++; while(*temp && *temp != ';' && i < maxlen) { value[i++] = *temp++; } value[i] = 0; } return temp; } //返回参数长度 U32 ParseParam(char *pParam, int nMaxLen, char *pBuffer) { int nLen = 0; while(pBuffer && *pBuffer && *pBuffer != ';') { *pParam++ = *pBuffer++; nLen++; } return nLen; } //从acData中,查找key的值,保存在value中 static char *__get_value(char *acData, char *key, char *value, int nMaxLen) { char *pItem, *pValue; U32 nRead; char acBuff[256]={0}; U32 nOffset = 0; int nCh = 0; char *out_ptr = NULL; while ((nRead = ParseParam(acBuff, 64, acData+nOffset)) > 0) { acBuff[nRead] = 0; //把分号去掉 nOffset += (nRead+1); if (strncmp(acBuff, "[CH1]", 5) == 0) { nCh = 0; } else if (strncmp(acBuff, "[CH2]", 5) == 0) { nCh = 1; } else if (strncmp(acBuff, "[CH3]", 5) == 0) { nCh = 2; } else if (strncmp(acBuff, "[ALL]", 5) == 0) { nCh = 0; } else { pItem = strtok_r(acBuff, "=", &out_ptr); pValue = strtok_r(NULL, "\r", &out_ptr); //Printf("pItem: %s, pValue: %s\n", pItem, pValue); if (pValue == NULL) pValue = ""; if (pItem != NULL && strcmp(pItem, key) == 0) { strncpy(value, pValue, nMaxLen); return value; } } } return NULL; }