[Ferm] [PATCH] Added $LINE Automatic variable.
Omen Wild
omen at mandarb.com
Tue Mar 15 00:40:59 CET 2011
Added an Automatic variable named $LINE that is the line of the
current file. Added a test case and documenation with a note on how
to use it for logging.
---
doc/ferm.pod | 12 ++++++++++++
src/ferm | 4 ++++
test/misc/autovar.ferm | 1 +
test/misc/autovar.result | 1 +
4 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/doc/ferm.pod b/doc/ferm.pod
index 955923c..ccd1d20 100644
--- a/doc/ferm.pod
+++ b/doc/ferm.pod
@@ -1481,6 +1481,18 @@ The current netfilter table.
The current netfilter chain.
+=item B<$LINE>
+
+The line of the current script. It can be used like this:
+
+ @def &log($msg) = {
+ LOG log-prefix "rule=$msg:$LINE ";
+ }
+ .
+ .
+ .
+ &log("log message");
+
=back
=head2 Functions
diff --git a/src/ferm b/src/ferm
index 8cf83a8..3fc54ba 100755
--- a/src/ferm
+++ b/src/ferm
@@ -901,6 +901,10 @@ sub require_next_token {
sub variable_value($) {
my $name = shift;
+ if ($name eq "LINE") {
+ return $script->{line};
+ }
+
foreach (@stack) {
return $_->{vars}{$name}
if exists $_->{vars}{$name};
diff --git a/test/misc/autovar.ferm b/test/misc/autovar.ferm
index 33a53b7..56e26a2 100644
--- a/test/misc/autovar.ferm
+++ b/test/misc/autovar.ferm
@@ -2,4 +2,5 @@ table filter chain INPUT {
LOG log-prefix "in $TABLE ";
LOG log-prefix "in $CHAIN ";
LOG log-prefix "in $TABLE/$CHAIN ";
+ LOG log-prefix "in $TABLE/$CHAIN line #$LINE";
}
diff --git a/test/misc/autovar.result b/test/misc/autovar.result
index c8bbada..f0210a5 100644
--- a/test/misc/autovar.result
+++ b/test/misc/autovar.result
@@ -1,3 +1,4 @@
iptables -t filter -A INPUT -j LOG --log-prefix 'in filter '
iptables -t filter -A INPUT -j LOG --log-prefix 'in INPUT '
iptables -t filter -A INPUT -j LOG --log-prefix 'in filter/INPUT '
+iptables -t filter -A INPUT -j LOG --log-prefix 'in filter/INPUT line #5'
--
1.7.4.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4538 bytes
Desc: not available
URL: <http://foo-projects.org/pipermail/ferm/attachments/20110314/21299f92/attachment-0001.bin>
More information about the Ferm
mailing list