ini_file_reader support #@for
parent
d34dfee8dc
commit
28930e70b6
1
HISTORY
1
HISTORY
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
Version 1.28 2016-06-14
|
Version 1.28 2016-06-14
|
||||||
* ini_file_reader support #@if
|
* ini_file_reader support #@if
|
||||||
|
* ini_file_reader support #@for
|
||||||
|
|
||||||
Version 1.28 2016-06-08
|
Version 1.28 2016-06-08
|
||||||
* id generator support extra bits
|
* id generator support extra bits
|
||||||
|
|
|
||||||
2
make.sh
2
make.sh
|
|
@ -52,7 +52,7 @@ fi
|
||||||
|
|
||||||
DEBUG_FLAG=0
|
DEBUG_FLAG=0
|
||||||
|
|
||||||
CFLAGS='-Wall -D_FILE_OFFSET_BITS=64'
|
CFLAGS='-Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE'
|
||||||
if [ "$DEBUG_FLAG" = "1" ]; then
|
if [ "$DEBUG_FLAG" = "1" ]; then
|
||||||
CFLAGS="$CFLAGS -g -DDEBUG_FLAG"
|
CFLAGS="$CFLAGS -g -DDEBUG_FLAG"
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -669,6 +669,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
static char *iniAllocContent(IniContext *pContext, const int content_len)
|
static char *iniAllocContent(IniContext *pContext, const int content_len)
|
||||||
{
|
{
|
||||||
char *buff;
|
char *buff;
|
||||||
|
int index;
|
||||||
if (pContext->dynamicContents.count >= pContext->dynamicContents.alloc_count)
|
if (pContext->dynamicContents.count >= pContext->dynamicContents.alloc_count)
|
||||||
{
|
{
|
||||||
int alloc_count;
|
int alloc_count;
|
||||||
|
|
@ -708,7 +709,8 @@ static char *iniAllocContent(IniContext *pContext, const int content_len)
|
||||||
"malloc %d bytes fail", __LINE__, content_len);
|
"malloc %d bytes fail", __LINE__, content_len);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pContext->dynamicContents.contents[pContext->dynamicContents.count++] = buff;
|
index = pContext->dynamicContents.count++;
|
||||||
|
pContext->dynamicContents.contents[index] = buff;
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1025,9 +1027,14 @@ static int iniParseForRange(char *range, const int range_len,
|
||||||
}
|
}
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
|
while (p < pEnd && (*p == ' ' || *p == '\t'))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
}
|
||||||
if (!(memcmp(p, _PREPROCESS_TAG_STR_FOR_FROM,
|
if (!(memcmp(p, _PREPROCESS_TAG_STR_FOR_FROM,
|
||||||
_PREPROCESS_TAG_LEN_FOR_FROM) == 0 &&
|
_PREPROCESS_TAG_LEN_FOR_FROM) == 0 &&
|
||||||
(*p == ' ' || *p == '\t')))
|
(*(p+_PREPROCESS_TAG_LEN_FOR_FROM) == ' ' ||
|
||||||
|
*(p+_PREPROCESS_TAG_LEN_FOR_FROM) == '\t')))
|
||||||
{
|
{
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"invalid for range: %.*s", __LINE__,
|
"invalid for range: %.*s", __LINE__,
|
||||||
|
|
@ -1054,13 +1061,14 @@ static int iniParseForRange(char *range, const int range_len,
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
while (p < pEnd && !(*p == ' ' || *p == '\t'))
|
while (p < pEnd && (*p == ' ' || *p == '\t'))
|
||||||
{
|
{
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (!(memcmp(p, _PREPROCESS_TAG_STR_FOR_TO,
|
if (!(memcmp(p, _PREPROCESS_TAG_STR_FOR_TO,
|
||||||
_PREPROCESS_TAG_LEN_FOR_TO) == 0 &&
|
_PREPROCESS_TAG_LEN_FOR_TO) == 0 &&
|
||||||
(*p == ' ' || *p == '\t')))
|
(*(p+_PREPROCESS_TAG_LEN_FOR_TO) == ' ' ||
|
||||||
|
*(p+_PREPROCESS_TAG_LEN_FOR_TO) == '\t')))
|
||||||
{
|
{
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"unkown for range: %.*s", __LINE__,
|
"unkown for range: %.*s", __LINE__,
|
||||||
|
|
@ -1098,7 +1106,8 @@ static int iniParseForRange(char *range, const int range_len,
|
||||||
}
|
}
|
||||||
if (!(memcmp(p, _PREPROCESS_TAG_STR_FOR_STEP,
|
if (!(memcmp(p, _PREPROCESS_TAG_STR_FOR_STEP,
|
||||||
_PREPROCESS_TAG_LEN_FOR_STEP) == 0 &&
|
_PREPROCESS_TAG_LEN_FOR_STEP) == 0 &&
|
||||||
(*p == ' ' || *p == '\t')))
|
(*(p+_PREPROCESS_TAG_LEN_FOR_STEP) == ' ' ||
|
||||||
|
*(p+_PREPROCESS_TAG_LEN_FOR_STEP) == '\t')))
|
||||||
{
|
{
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"unkown for range: %.*s", __LINE__,
|
"unkown for range: %.*s", __LINE__,
|
||||||
|
|
@ -1214,7 +1223,36 @@ static char *iniProccessFor(char *content, const int content_len,
|
||||||
tagLen = sprintf(tag, "{$%.*s}", idLen, id);
|
tagLen = sprintf(tag, "{$%.*s}", idLen, id);
|
||||||
for (i=start; i<=end; i+=step)
|
for (i=start; i<=end; i+=step)
|
||||||
{
|
{
|
||||||
|
char *p;
|
||||||
|
char *pRemain;
|
||||||
|
int remainLen;
|
||||||
|
|
||||||
valueLen = sprintf(value, "%d", i);
|
valueLen = sprintf(value, "%d", i);
|
||||||
|
|
||||||
|
pRemain = pForBlock;
|
||||||
|
remainLen = forBlockLen;
|
||||||
|
while (remainLen >= tagLen)
|
||||||
|
{
|
||||||
|
p = (char *)memmem(pRemain, remainLen, tag, tagLen);
|
||||||
|
if (p == NULL)
|
||||||
|
{
|
||||||
|
memcpy(pDest, pRemain, remainLen);
|
||||||
|
pDest += remainLen;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
copyLen = p - pRemain;
|
||||||
|
if (copyLen > 0)
|
||||||
|
{
|
||||||
|
memcpy(pDest, pRemain, copyLen);
|
||||||
|
pDest += copyLen;
|
||||||
|
}
|
||||||
|
memcpy(pDest, value, valueLen);
|
||||||
|
pDest += valueLen;
|
||||||
|
|
||||||
|
pRemain = p + tagLen;
|
||||||
|
remainLen -= copyLen + tagLen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
copyLen = (content + content_len) - (pEnd + _PREPROCESS_TAG_LEN_ENDFOR);
|
copyLen = (content + content_len) - (pEnd + _PREPROCESS_TAG_LEN_ENDFOR);
|
||||||
|
|
@ -1261,8 +1299,6 @@ static int iniLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
}
|
}
|
||||||
} while (new_content != pContent);
|
} while (new_content != pContent);
|
||||||
|
|
||||||
logInfo("new_content(%d): %s", new_content_len, new_content);
|
|
||||||
|
|
||||||
return iniDoLoadItemsFromBuffer(new_content, pContext);
|
return iniDoLoadItemsFromBuffer(new_content, pContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1342,7 +1378,7 @@ void iniFreeContext(IniContext *pContext)
|
||||||
hash_walk(&pContext->sections, iniFreeHashData, NULL);
|
hash_walk(&pContext->sections, iniFreeHashData, NULL);
|
||||||
hash_destroy(&pContext->sections);
|
hash_destroy(&pContext->sections);
|
||||||
|
|
||||||
if (pContext->dynamicContents.contents != NULL)
|
if (pContext->dynamicContents.count > 0)
|
||||||
{
|
{
|
||||||
for (i=0; i<pContext->dynamicContents.count; i++)
|
for (i=0; i<pContext->dynamicContents.count; i++)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ typedef struct
|
||||||
char config_path[MAX_PATH_SIZE]; //save the config filepath
|
char config_path[MAX_PATH_SIZE]; //save the config filepath
|
||||||
bool ignore_annotation;
|
bool ignore_annotation;
|
||||||
struct {
|
struct {
|
||||||
int count;
|
char count;
|
||||||
int alloc_count;
|
char alloc_count;
|
||||||
char **contents;
|
char **contents;
|
||||||
} dynamicContents; //dynamic alloced contents which will be freed when destroy
|
} dynamicContents; //dynamic alloced contents which will be freed when destroy
|
||||||
} IniContext;
|
} IniContext;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue