From 2d6067151187eef26532750518dd84a59ffbeca9 Mon Sep 17 00:00:00 2001 From: yuqing Date: Wed, 1 Mar 2017 17:41:32 +0800 Subject: [PATCH] test_ini_parser.c changed --- src/tests/test.ini | 3 +++ src/tests/test_ini_parser.c | 38 ++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/tests/test.ini b/src/tests/test.ini index 16c0c4f..56182fa 100644 --- a/src/tests/test.ini +++ b/src/tests/test.ini @@ -8,6 +8,9 @@ os_name = hostname #@function LOCAL_IP_GET bind_ip = inner +#@function EXPRESS_CALC +thread_count = 5 * 4 + 6 + #@if %{os_name} in [Linux, Darwin] [AccessLogSpaceCharConvert] # format: src = dest diff --git a/src/tests/test_ini_parser.c b/src/tests/test_ini_parser.c index 07786b2..04f1e45 100644 --- a/src/tests/test_ini_parser.c +++ b/src/tests/test_ini_parser.c @@ -8,21 +8,54 @@ #include #include #include "logger.h" +#include "shared_func.h" #include "ini_file_reader.h" +static int iniAnnotationFuncExpressCalc(char *param, char **pOutValue, int max_values) +{ + int count; + int result; + char cmd[512]; + static char output[256]; + + count = 0; + sprintf(cmd, "echo \'%s\' | bc -l", param); + if ((result=getExecResult(cmd, output, sizeof(output))) != 0) + { + logWarning("file: "__FILE__", line: %d, " + "exec %s fail, errno: %d, error info: %s", + __LINE__, cmd, result, STRERROR(result)); + return count; + } + if (*output == '\0') + { + logWarning("file: "__FILE__", line: %d, " + "empty reply when exec: %s", __LINE__, param); + } + pOutValue[count++] = fc_trim(output); + return count; +} + int main(int argc, char *argv[]) { int result; IniContext context; - const char *szFilename = "/home/yuqing/watchd-config/order.conf"; + const char *szFilename = "test.ini"; + AnnotationMap annotations[1]; if (argc > 1) { szFilename = argv[1]; } log_init(); + + annotations[0].func_name = "EXPRESS_CALC"; + annotations[0].func_init = NULL; + annotations[0].func_destroy = NULL; + annotations[0].func_get = iniAnnotationFuncExpressCalc; + if ((result=iniLoadFromFileEx(szFilename, &context, - INI_ANNOTATION_WITH_BUILTIN, NULL, 0)) != 0) + INI_ANNOTATION_WITH_BUILTIN, annotations, 1)) != 0) { return result; } @@ -32,4 +65,3 @@ int main(int argc, char *argv[]) iniFreeContext(&context); return 0; } -