yjj-20230904
This commit is contained in:
parent
ac50191203
commit
f8ccddc10c
|
@ -3,4 +3,4 @@
|
|||
add_subdirectory(ReturnCode)
|
||||
add_subdirectory(StatusCode)
|
||||
add_subdirectory(Log)
|
||||
add_subdirectory(LogC)
|
||||
add_subdirectory(LogC)
|
||||
|
|
0
utils/FileIo/CMakeList.txt
Normal file
0
utils/FileIo/CMakeList.txt
Normal file
40
utils/FileIo/include/file_io.h
Normal file
40
utils/FileIo/include/file_io.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* @brief
|
||||
* The only one header file for the other modules to use log module.
|
||||
*/
|
||||
#ifndef FILE_IO_H
|
||||
#define FILE_IO_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "file.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);
|
||||
|
||||
//从acData中,查找key的值,保存在value中
|
||||
static char *__get_value(char *acData, char *key, char *value, int nMaxLen)
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
108
utils/FileIo/src/file_io.c
Normal file
108
utils/FileIo/src/file_io.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
#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;
|
||||
}
|
19
utils/IpcConfig/CMakeList.txt
Normal file
19
utils/IpcConfig/CMakeList.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
./include
|
||||
)
|
||||
#do not rely on any other library
|
||||
#link_directories(
|
||||
#)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME IpcConfig)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
|
@ -44,4 +44,4 @@ const StatusCode CreateStatusCode(const long int code)
|
|||
LogError("undefined code.\n");
|
||||
return NewStatusCode(STATUS_CODE_END);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user