ignore annotation in some cases

pull/5/head
liuwei 2015-09-11 19:40:15 +08:00
parent 5f52349bd6
commit 07ffa9e6bd
4 changed files with 10 additions and 103 deletions

View File

@ -134,104 +134,11 @@ static void iniSortItems(IniContext *pContext)
int iniLoadFromFile(const char *szFilename, IniContext *pContext)
{
int result;
int len;
char *pLast;
char full_filename[MAX_PATH_SIZE];
if ((result=iniInitContext(pContext)) != 0)
{
return result;
}
if (strncasecmp(szFilename, "http://", 7) == 0)
{
*pContext->config_path = '\0';
snprintf(full_filename, sizeof(full_filename),"%s",szFilename);
}
else
{
if (*szFilename == '/')
{
pLast = strrchr(szFilename, '/');
len = pLast - szFilename;
if (len >= sizeof(pContext->config_path))
{
logError("file: "__FILE__", line: %d, "\
"the path of the config file: %s is " \
"too long!", __LINE__, szFilename);
return ENOSPC;
}
memcpy(pContext->config_path, szFilename, len);
*(pContext->config_path + len) = '\0';
snprintf(full_filename, sizeof(full_filename), \
"%s", szFilename);
}
else
{
memset(pContext->config_path, 0, \
sizeof(pContext->config_path));
if (getcwd(pContext->config_path, sizeof( \
pContext->config_path)) == NULL)
{
logError("file: "__FILE__", line: %d, " \
"getcwd fail, errno: %d, " \
"error info: %s", \
__LINE__, errno, STRERROR(errno));
return errno != 0 ? errno : EPERM;
}
len = strlen(pContext->config_path);
if (len > 0 && pContext->config_path[len - 1] == '/')
{
len--;
*(pContext->config_path + len) = '\0';
}
snprintf(full_filename, sizeof(full_filename), \
"%s/%s", pContext->config_path, szFilename);
pLast = strrchr(szFilename, '/');
if (pLast != NULL)
{
int tail_len;
tail_len = pLast - szFilename;
if (len + 1 + tail_len >= sizeof( \
pContext->config_path))
{
logError("file: "__FILE__", line: %d, "\
"the path of the config " \
"file: %s is too long!", \
__LINE__, szFilename);
return ENOSPC;
}
*(pContext->config_path + len++) = '/';
memcpy(pContext->config_path + len, \
szFilename, tail_len);
len += tail_len;
*(pContext->config_path + len) = '\0';
}
}
}
result = iniDoLoadFromFile(full_filename, pContext);
if (result == 0)
{
iniSortItems(pContext);
}
else
{
iniFreeContext(pContext);
}
return result;
return iniLoadFromFileEx(szFilename, pContext, false);
}
int iniLoadFromFileEx(const char *szFilename, IniContext *pContext,
char annotation)
bool ignore_annotation)
{
int result;
int len;
@ -243,7 +150,7 @@ int iniLoadFromFileEx(const char *szFilename, IniContext *pContext,
return result;
}
pContext->annotation = annotation;
pContext->ignore_annotation = ignore_annotation;
if (strncasecmp(szFilename, "http://", 7) == 0)
{
@ -511,7 +418,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
strncasecmp(pLine+1, "@function", 9) == 0 && \
(*(pLine+10) == ' ' || *(pLine+10) == '\t')))
{
if (pContext->annotation != IGNORE_ANNOTATION) {
if (!pContext->ignore_annotation) {
nNameLen = strlen(pLine + 11);
if (nNameLen > FAST_INI_ITEM_NAME_LEN)
{
@ -531,8 +438,8 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
"the function name of annotation line is empty", \
__LINE__);
}
continue;
}
continue;
}
trim(pLine);

View File

@ -47,7 +47,7 @@ typedef struct
HashArray sections; //key is session name, and value is IniSection
IniSection *current_section; //for load from ini file
char config_path[MAX_PATH_SIZE]; //save the config filepath
char annotation;
bool ignore_annotation;
} IniContext;
#ifdef __cplusplus
@ -69,11 +69,11 @@ int iniLoadFromFile(const char *szFilename, IniContext *pContext);
* parameters:
* szFilename: the filename, can be an URL
* pContext: the ini context
* annotation: whether ignore annotation
* ignore_annotation: whether ignore annotation
* return: error no, 0 for success, != 0 fail
*/
int iniLoadFromFileEx(const char *szFilename, IniContext *pContext,
char annotation);
bool ignore_annotation);
/** load ini items from string buffer
* parameters:

View File

@ -212,7 +212,7 @@ int get_base_path_from_conf_file(const char *filename, char *base_path,
memset(&iniContext, 0, sizeof(IniContext));
if ((result=iniLoadFromFileEx(filename, &iniContext, IGNORE_ANNOTATION)) != 0)
if ((result=iniLoadFromFileEx(filename, &iniContext, true)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"load conf file \"%s\" fail, ret code: %d", \

View File

@ -1322,7 +1322,7 @@ int load_log_level_ex(const char *conf_filename)
int result;
IniContext iniContext;
if ((result=iniLoadFromFileEx(conf_filename, &iniContext, IGNORE_ANNOTATION)) != 0)
if ((result=iniLoadFromFileEx(conf_filename, &iniContext, true)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"load conf file \"%s\" fail, ret code: %d", \