diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /pigeonhole/src/lib-sieve/tst-truefalse.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/src/lib-sieve/tst-truefalse.c')
-rw-r--r-- | pigeonhole/src/lib-sieve/tst-truefalse.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/pigeonhole/src/lib-sieve/tst-truefalse.c b/pigeonhole/src/lib-sieve/tst-truefalse.c new file mode 100644 index 0000000..6373ce3 --- /dev/null +++ b/pigeonhole/src/lib-sieve/tst-truefalse.c @@ -0,0 +1,104 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "sieve-ast.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-binary.h" + +#include "sieve-commands.h" +#include "sieve-code.h" +#include "sieve-interpreter.h" + +/* + * True/False test command + */ + +static bool tst_false_validate_const + (struct sieve_validator *valdtr, struct sieve_command *tst, + int *const_current, int const_next); +static bool tst_false_generate + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, + struct sieve_jumplist *jumps, bool jump_true); + +const struct sieve_command_def tst_false = { + .identifier = "false", + .type = SCT_TEST, + .positional_args = 0, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .validate_const = tst_false_validate_const, + .control_generate = tst_false_generate +}; + +static bool tst_true_validate_const + (struct sieve_validator *valdtr, struct sieve_command *tst, + int *const_current, int const_next); +static bool tst_true_generate + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, + struct sieve_jumplist *jumps, bool jump_true); + +const struct sieve_command_def tst_true = { + .identifier = "true", + .type = SCT_TEST, + .positional_args = 0, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .validate_const = tst_true_validate_const, + .control_generate = tst_true_generate +}; + +/* + * Code validation + */ + +static bool tst_false_validate_const +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_command *tst ATTR_UNUSED, int *const_current, + int const_next ATTR_UNUSED) +{ + *const_current = 0; + return TRUE; +} + +static bool tst_true_validate_const +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_command *tst ATTR_UNUSED, int *const_current, + int const_next ATTR_UNUSED) +{ + *const_current = 1; + return TRUE; +} + +/* + * Code generation + */ + +static bool tst_false_generate +(const struct sieve_codegen_env *cgenv, + struct sieve_command *cmd ATTR_UNUSED, + struct sieve_jumplist *jumps, bool jump_true) +{ + if ( !jump_true ) { + sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation); + sieve_jumplist_add(jumps, sieve_binary_emit_offset(cgenv->sblock, 0)); + } + + return TRUE; +} + +static bool tst_true_generate +(const struct sieve_codegen_env *cgenv, + struct sieve_command *cmd ATTR_UNUSED, + struct sieve_jumplist *jumps, bool jump_true) +{ + if ( jump_true ) { + sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation); + sieve_jumplist_add(jumps, sieve_binary_emit_offset(cgenv->sblock, 0)); + } + + return TRUE; +} + |