Sat, 12 Nov 2022 11:52:47 +0100
allow '-' in tokens, add support for negative integers
--- a/src/server/config/serverconfig.c Sat Nov 12 11:01:11 2022 +0100 +++ b/src/server/config/serverconfig.c Sat Nov 12 11:52:47 2022 +0100 @@ -97,7 +97,7 @@ } static int scfg_char_is_delim(char c) { - static const char *scfg_tokenizer_delim = "()+-/*%"; + static const char *scfg_tokenizer_delim = "()/*%"; for(int i=0;i<sizeof(scfg_tokenizer_delim)-1;i++) { if(c == scfg_tokenizer_delim[i]) { return 1;
--- a/src/server/test/main.c Sat Nov 12 11:01:11 2022 +0100 +++ b/src/server/test/main.c Sat Nov 12 11:52:47 2022 +0100 @@ -79,15 +79,16 @@ ucx_test_register(suite, test_util_uri_escape_kanji); // object tests - //ucx_test_register(suite, test_expr_parse_expr_value); - //ucx_test_register(suite, test_expr_parse_expr_value_str); - //ucx_test_register(suite, test_expr_parse_expr_value_bool); - //ucx_test_register(suite, test_expr_parse_expr_value_var); - //ucx_test_register(suite, test_expr_parse_expr_not_value); - //ucx_test_register(suite, test_expr_parse_expr_sign_value); - //ucx_test_register(suite, test_expr_parse_expr_compare2values); - //ucx_test_register(suite, test_expr_parse_expr_compare2value_expr); - //ucx_test_register(suite, test_expr_parse_expr_compare2expr_value); + ucx_test_register(suite, test_expr_parse_expr_value); + ucx_test_register(suite, test_expr_parse_expr_neg_value); + ucx_test_register(suite, test_expr_parse_expr_value_str); + ucx_test_register(suite, test_expr_parse_expr_value_bool); + ucx_test_register(suite, test_expr_parse_expr_value_var); + ucx_test_register(suite, test_expr_parse_expr_not_value); + ucx_test_register(suite, test_expr_parse_expr_sign_value); + ucx_test_register(suite, test_expr_parse_expr_compare2values); + ucx_test_register(suite, test_expr_parse_expr_compare2value_expr); + ucx_test_register(suite, test_expr_parse_expr_compare2expr_value); ucx_test_register(suite, test_expr_parse_expr_bracket); // vfs tests
--- a/src/server/test/object.c Sat Nov 12 11:01:11 2022 +0100 +++ b/src/server/test/object.c Sat Nov 12 11:52:47 2022 +0100 @@ -57,6 +57,28 @@ pool_destroy(pool); } +UCX_TEST(test_expr_parse_expr_neg_value) { + pool_handle_t *pool = pool_create(); + + CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring)); + cxstring token = cx_str("-123"); + cxListAdd(tokens, &token); + + UCX_TEST_BEGIN; + + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + UCX_TEST_ASSERT(pos == 1, "wrong token pos"); + UCX_TEST_ASSERT(expr, "expression is null"); + UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT, "wrong type"); + UCX_TEST_ASSERT(expr->value.i == -123, "wrong value"); + + UCX_TEST_END; + + pool_destroy(pool); +} + UCX_TEST(test_expr_parse_expr_value_str) { pool_handle_t *pool = pool_create();
--- a/src/server/test/object.h Sat Nov 12 11:01:11 2022 +0100 +++ b/src/server/test/object.h Sat Nov 12 11:52:47 2022 +0100 @@ -38,6 +38,7 @@ #endif UCX_TEST(test_expr_parse_expr_value); +UCX_TEST(test_expr_parse_expr_neg_value); UCX_TEST(test_expr_parse_expr_value_str); UCX_TEST(test_expr_parse_expr_value_bool); UCX_TEST(test_expr_parse_expr_value_var);
--- a/src/server/util/object.c Sat Nov 12 11:01:11 2022 +0100 +++ b/src/server/util/object.c Sat Nov 12 11:52:47 2022 +0100 @@ -112,8 +112,11 @@ /* ------------------------------ Expression ------------------------------ */ Expression* condition_create(pool_handle_t *pool, CxList *tokens) { - - + size_t pos = 0; + NSAPIExpression *expression = expr_parse_logical_expr(pool, tokens, &pos); + if(!expression || pos != tokens->size) { + return NULL; + } return NULL; } @@ -185,7 +188,19 @@ } static int token_is_int(cxstring token) { - for(size_t i=0;i<token.length;i++) { + if(token.length == 0) { + return 0; + } + + size_t start = 0; + if(token.ptr[0] == '-' || token.ptr[0] == '+') { + if(token.length < 2) { + return 0; + } + start++; + } + + for(size_t i=start;i<token.length;i++) { if(!isdigit(token.ptr[i])) { return 0; }