diff --git a/HISTORY b/HISTORY index c96f635..af272d3 100644 --- a/HISTORY +++ b/HISTORY @@ -3,6 +3,7 @@ Version 1.40 2018-08-20 * add function conn_pool_parse_server_info and conn_pool_load_server_info * support directive: #@add_annotation, for example: #@add_annotation CONFIG_GET /usr/lib/libshmcache.so /etc/libshmcache.conf + * add function fc_split_string and fc_match_delim Version 1.39 2018-07-31 * add #@function REPLACE_VARS diff --git a/src/ini_file_reader.c b/src/ini_file_reader.c index 820d64e..6fc16e4 100644 --- a/src/ini_file_reader.c +++ b/src/ini_file_reader.c @@ -840,7 +840,7 @@ static int iniAddAnnotation(char *params) int result; trim(params); - count = splitEx(params, ' ', cols, MAX_PARAMS); + count = fc_split_string(params, " \t", cols, MAX_PARAMS); if (count < 2) { logError("file: "__FILE__", line: %d, " @@ -987,6 +987,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext) isAnnotation = 0; } + STR_TRIM(pLine); if (*pLine == '#' && \ strncasecmp(pLine+1, "include", 7) == 0 && \ (*(pLine+8) == ' ' || *(pLine+8) == '\t')) @@ -1091,8 +1092,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext) continue; } - STR_TRIM(pLine); - if (*pLine == '#' || *pLine == '\0') + if (*pLine == '\0') { continue; } diff --git a/src/shared_func.c b/src/shared_func.c index 6fbcb75..4aa3ae1 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -747,6 +747,59 @@ int splitEx(char *src, const char seperator, char **pCols, const int nMaxCols) return count; } +bool fc_match_delim(const char *str, const char *delim) +{ + const char *sp; + const char *send; + const char *dp; + const char *dend; + + send = str + strlen(str); + dend = delim + strlen(delim); + for (sp=str; sp= nMaxCols) + { + break; + } + + if (fc_match_delim(token, delim)) + { + continue; + } + + pCols[count++] = token; + } + + return count; +} + int my_strtok(char *src, const char *delim, char **pCols, const int nMaxCols) { char *p; diff --git a/src/shared_func.h b/src/shared_func.h index 346f19f..81423d2 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -366,6 +366,25 @@ void freeSplit(char **p); */ int splitEx(char *src, const char seperator, char **pCols, const int nMaxCols); + +/** split string by delimiter characters + * parameters: + * src: the source string, will be modified by this function + * delim: the delimiter characters + * pCols: store split strings + * nMaxCols: max columns (max split count) + * return: string array / column count +*/ +int fc_split_string(char *src, const char *delim, char **pCols, const int nMaxCols); + +/** if the input string contains all delimiter characters + * parameters: + * str: the input string + * delim: the delimiter characters + * return: true for contains all delimiter characters, otherwise false +*/ +bool fc_match_delim(const char *str, const char *delim); + /** split string * parameters: * src: the source string, will be modified by this function diff --git a/src/tests/test.ini b/src/tests/test.ini index 9215d26..b43a45f 100644 --- a/src/tests/test.ini +++ b/src/tests/test.ini @@ -1,13 +1,19 @@ + +#@set author_name = yuqing +#@set OS_NAME = $(uname -a | awk '{print $1;}') + # to support #@function CONFIG_GET # the version of libshmcache >= 1.0.7 -#@add_annotation CONFIG_GET /usr/local/lib/libshmcache.so /usr/local/etc/libshmcache.conf + +#@if %{OS_NAME} in [Darwin] + #@add_annotation CONFIG_GET /usr/local/lib/libshmcache.so /usr/local/etc/libshmcache.conf +#@else + #@add_annotation CONFIG_GET /usr/lib/libshmcache.so /etc/libshmcache.conf +#@endif #@function CONFIG_GET app.version = app1.key1 -#@set author_name = yuqing -#@set os_name = $(uname -a | awk '{print $1;}') - #@function SHELL_EXEC host = hostname @@ -17,7 +23,7 @@ bind_ip = inner[0] #@function EXPRESS_CALC thread_count = 5 * 4 + 6 -#@if %{os_name} in [Linux, Darwin] +#@if %{OS_NAME} in [Linux, Darwin] [AccessLogSpaceCharConvert] # format: src = dest # src can be a printable char or a backslash char pair such as \t