diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-04-27 19:03:11 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-04-27 19:03:11 +0400 |
commit | b9baa0d48da843d73926fff54b36846a778d9474 (patch) | |
tree | 7904fe31f4d6d9aa9cba1776c7ea3153933b0301 /utils | |
parent | c1723b27e05334a43d1443a125023ba556f54117 (diff) | |
download | rspamd-b9baa0d48da843d73926fff54b36846a778d9474.tar.gz rspamd-b9baa0d48da843d73926fff54b36846a778d9474.zip |
* Add expression parser utility
* Temporaly switch off expression optimizer as it should be reworked
Diffstat (limited to 'utils')
-rw-r--r-- | utils/expression_parser.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/utils/expression_parser.c b/utils/expression_parser.c new file mode 100644 index 000000000..fa0237f3a --- /dev/null +++ b/utils/expression_parser.c @@ -0,0 +1,50 @@ +#include "../src/config.h" +#include "../src/main.h" +#include "../src/cfg_file.h" +#include "../src/expressions.h" + +int +main (int argc, char **argv) +{ + memory_pool_t *pool; + struct expression *cur; + char *line, *outstr; + int r, s; + char buf[BUFSIZ]; + + pool = memory_pool_new (memory_pool_get_size ()); + + line = fgets (buf, sizeof (buf), stdin); + while (line) { + s = strlen (line); + if (buf[s - 1] == '\n') { + buf[s - 1] = '\0'; + } + if (buf[s - 2] == '\r') { + buf[s - 2] = '\0'; + } + + r = 0; + cur = parse_expression (pool, line); + s = strlen (line) * 4; + outstr = memory_pool_alloc (pool, s); + while (cur) { + if (cur->type == EXPR_REGEXP) { + r += snprintf (outstr + r, s - r, "OP:%s ", (char *)cur->content.operand); + } else if (cur->type == EXPR_STR) { + r += snprintf (outstr + r, s - r, "S:%s ", (char *)cur->content.operand); + + } else if (cur->type == EXPR_FUNCTION) { + r += snprintf (outstr + r, s - r, "F:%s ", ((struct expression_function *)cur->content.operand)->name); + } + else { + r += snprintf (outstr + r, s - r, "O:%c ", cur->content.operation); + } + cur = cur->next; + } + printf ("Parsed expression: '%s' -> '%s'\n", line, outstr); + line = fgets (buf, sizeof (buf), stdin); + } + + memory_pool_delete (pool); +} |