aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS17
-rw-r--r--doc/anubis.texi33
-rw-r--r--src/rc-gram.y30
-rw-r--r--src/rc-lex.l1
-rw-r--r--src/regex.c4
5 files changed, 68 insertions, 17 deletions
diff --git a/NEWS b/NEWS
index daf004b..5194635 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
GNU Anubis NEWS -- history of user-visible changes. 2011-01-13
-Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 The Anubis Team.
+Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
+2011 The Anubis Team.
See the end of file for copying conditions.
Please send your bug reports to <bug-anubis@gnu.org>.
@@ -14,6 +15,20 @@ Please send your bug reports to <bug-anubis@gnu.org>.
Command line options take precedence over configuration file
statements.
+* elif statement
+
+A familiar `elif' statement is supported, e.g.:
+
+if condition-1
+ action-list-1
+elif condition-2
+ action-list-2
+elif condition-3
+ action-list-3
+else
+ action-list-4
+fi
+
* New CONTROL statement esmtp-auth-delayed.
When set to `yes', this statement instructs Anubis to postpone ESMTP
diff --git a/doc/anubis.texi b/doc/anubis.texi
index 5f5b8c5..2d99c64 100644
--- a/doc/anubis.texi
+++ b/doc/anubis.texi
@@ -1870,7 +1870,7 @@ syntax is:
@smallexample
if @var{condition}
- @var{action-list-1}
+ @var{action-list-1}
else
@var{action-list-2}
fi
@@ -1902,6 +1902,37 @@ The effect of this statement is: depending on the value of
identification string, or add an @code{X-Passed} header if no known
@code{List-Id} was found.
+To simplify writing such nested conditional statements, the
+@samp{elif} keyword is provided:
+
+@smallexample
+if @var{condition-1}
+ @var{action-list-1}
+elif @var{condition-2}
+ @var{action-list-2}
+else
+ @var{action-list-3}
+fi
+@end smallexample
+
+This statement is equivalent to:
+
+@smallexample
+if @var{condition}
+ @var{action-list-1}
+else
+ if @var{condition-2}
+ @var{action-list-2}
+ else
+ @var{action-list-3}
+ fi
+fi
+@end smallexample
+
+Any number of @samp{elif} branches may appear in a conditional
+statement, the only requirement being that they appear before
+the @samp{else} statement, if it is used.
+
@menu
* Concatenations::
@end menu
diff --git a/src/rc-gram.y b/src/rc-gram.y
index 5eeb062..e9ff410 100644
--- a/src/rc-gram.y
+++ b/src/rc-gram.y
@@ -129,7 +129,7 @@ static struct rc_secdef *rc_secdef;
};
%token EOL T_BEGIN T_END AND OR NE
-%token IF FI ELSE RULE DONE
+%token IF FI ELSE ELIF RULE DONE
%token CALL STOP ADD REMOVE MODIFY
%token <string> IDENT STRING REGEX D_BEGIN
%token <num> T_MSGPART
@@ -141,7 +141,7 @@ static struct rc_secdef *rc_secdef;
%type <string> keyword string modifier arg string_key opt_sep
%type <section> section seclist
%type <stmtlist> stmtlist
-%type <stmt> stmt asgn_stmt cond_stmt rule_stmt inst_stmt modf_stmt
+%type <stmt> stmt asgn_stmt cond_stmt else_cond rule_stmt inst_stmt modf_stmt
%type <num> modlist opt_modlist
%type <node> rule_start cond expr
%type <msgpart> msgpart s_msgpart r_msgpart key opt_key
@@ -303,21 +303,31 @@ arglist : arg
arg : string
;
-cond_stmt: if cond stmtlist fi
+cond_stmt: if cond stmtlist else_cond FI
{
$$ = rc_stmt_create (rc_stmt_cond, &@1.beg);
$$->v.cond.node = $2;
$$->v.cond.iftrue = $3.head;
- $$->v.cond.iffalse = NULL;
+ $$->v.cond.iffalse = $4;
}
- | if cond stmtlist else stmtlist fi
+ ;
+
+else_cond: /* empty */
{
+ $$ = NULL;
+ }
+ | ELIF cond stmtlist else_cond
+ {
$$ = rc_stmt_create (rc_stmt_cond, &@1.beg);
$$->v.cond.node = $2;
$$->v.cond.iftrue = $3.head;
- $$->v.cond.iffalse = $5.head;
+ $$->v.cond.iffalse = $4;
}
- ;
+ | ELSE stmtlist
+ {
+ $$ = $2.head;
+ }
+ ;
cond : expr
| '(' cond ')'
@@ -499,12 +509,6 @@ if : IF
}
;
-fi : FI
- ;
-
-else : ELSE
- ;
-
rule_stmt: rule_start EOL stmtlist DONE
{
$$ = rc_stmt_create (rc_stmt_rule, &@1.beg);
diff --git a/src/rc-lex.l b/src/rc-lex.l
index 5c24c90..630bb83 100644
--- a/src/rc-lex.l
+++ b/src/rc-lex.l
@@ -128,6 +128,7 @@ END |
[iI][fF] return IF;
[fF][iI] return FI;
[eE][lL][sS][eE] return ELSE;
+[eE][lL][iI][fF] return ELIF;
[rR][uU][lL][eE] return RULE;
[tT][rR][iI][gG][gG][eE][rR] return RULE;
[dD][oO][nN][eE] return DONE;
diff --git a/src/regex.c b/src/regex.c
index b382fe0..5b9ba15 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -2,7 +2,7 @@
regex.c
This file is part of GNU Anubis.
- Copyright (C) 2001, 2002, 2003, 2005, 2007 The Anubis Team.
+ Copyright (C) 2001, 2002, 2003, 2005, 2007, 2011 The Anubis Team.
GNU Anubis is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -415,7 +415,7 @@ perl_compile (RC_REGEX *regex, char *line, int opt)
static void
perl_free (RC_REGEX *regex)
{
- pcre_free (regex->v.pre);
+ pcre_free (regex->v.pre);
}
static int

Return to:

Send suggestions and report system problems to the System administrator.