From 840f2414bda5856daa481611b24be29759d7a56f Mon Sep 17 00:00:00 2001 From: teastep Date: Mon, 11 Jun 2007 23:17:02 +0000 Subject: [PATCH] Finish externalization of compiler git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@6520 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- Shorewall-common/changelog.txt | 2 + Shorewall-common/releasenotes.txt | 75 +++++++++++++++++++++++++++- Shorewall-perl/Shorewall/Common.pm | 20 ++++++-- Shorewall-perl/Shorewall/Compiler.pm | 19 ++++++- Shorewall-perl/Shorewall/Config.pm | 11 +++- Shorewall-perl/compiler.pl | 34 +++++++------ 6 files changed, 139 insertions(+), 22 deletions(-) diff --git a/Shorewall-common/changelog.txt b/Shorewall-common/changelog.txt index c8348d315..0cf3b702a 100644 --- a/Shorewall-common/changelog.txt +++ b/Shorewall-common/changelog.txt @@ -3,6 +3,8 @@ Changes in 4.0.0 Beta 5 1) Fix undefined function call when both an input interface and an output interface are present. +2) Externalize compiler and Compile.pm. + Changes in 4.0.0 Beta 4 1) Fix the 'Modules' output of 'dump' diff --git a/Shorewall-common/releasenotes.txt b/Shorewall-common/releasenotes.txt index 54d239433..bc70c63ab 100644 --- a/Shorewall-common/releasenotes.txt +++ b/Shorewall-common/releasenotes.txt @@ -27,7 +27,79 @@ Problems corrected in 4.0.0 Beta 5. Other changes in Shorewall 4.0.0 Beta 5. -None. +1) The Perl compiler is now externalized. Both the program + 'compiler.pl' and the Perl Module interface + are now documented. + + The compiler program is /usr/share/shorewall-perl/compiler.pl: + + compiler.pl [ ] [ ] + + If a is given, then the configuration will be compiled + output placed in the named file. If is not given, then + the configuration will simply be syntax checked. + + Options are: + + -v + --verbosity= + + The is a number between 0 and 2 and corresponds to + the VERBOSITY setting in shorewall.conf. This setting controls + the verbosity of the compiler itself. + + -e + --export + + If given, the configuration will be compiled for export to + another system. + + -d + --directory= + + If this option is omitted, the configuration in /etc/shorewall + is compiled/checked. Otherwise, the configuration in the named + directory will be compiled/checked. + + -t + --timestamp + + If given, each progress message issued by the compiler and by + the compiled program will be timestamped. + + Example (compiles the configuration in the current directory + generating a script named 'firewall' and using VERBOSITY + 2). + + /usr/share/shorewall-perl/compiler.pl -v 2 -d . firewall + + To use the Shorewall::Compiler module: + + use lib '/usr/share/shorewall-perl'; + use Shorewall::Compiler; + + Two functions are exported: + + configure( $export, $directory, $verbose, $timestamp ) + + The arguments corresponding to the similarly-named + run-line options. If passed as '', the value will be + ignored. + + configure will raise an exception with die if $directory + is passed and does not name an existing directory. + + Example: configure( '', '.', 2, '' ); + + compiler( $objectfile ) + + The compiler function accepts 1 argument. If it corresponds to + the run-line argument. If the argument is + false, then a check is performed; otherwise, the + configuration is compiled into the named file. + + Compilation errors cause the compiler to raise an exception via + die. Migration Considerations: @@ -560,6 +632,7 @@ Migration Considerations: - Perl Cwd Module - Perl File::Basename Module - Perl File::Temp Module +- Perl Getopt::Long Module ---------------------------------------------------------------------------- U S I N G T H E N E W C O M P I L E R ---------------------------------------------------------------------------- diff --git a/Shorewall-perl/Shorewall/Common.pm b/Shorewall-perl/Shorewall/Common.pm index 1152fc43d..981ec34e6 100644 --- a/Shorewall-perl/Shorewall/Common.pm +++ b/Shorewall-perl/Shorewall/Common.pm @@ -42,6 +42,8 @@ our @EXPORT = qw( emit_unindented save_progress_message save_progress_message_short + set_timestamp + set_verbose progress_message progress_message2 progress_message3 @@ -78,9 +80,7 @@ our $tempfile; # Temporary File Name # sub fatal_error { - print STDERR " ERROR: @_\n"; - - exit 1; + die " ERROR: @_\n"; } # @@ -154,6 +154,20 @@ sub save_progress_message_short( $ ) { emit "progress_message $_[0]" if $object; } +# +# Set $timestamp +# +sub set_timestamp( $ ) { + $timestamp = shift; +} + +# +# Set $verbose +# +sub set_verbose( $ ) { + $verbose = shift; +} + # # Print the current TOD to STDOUT. # diff --git a/Shorewall-perl/Shorewall/Compiler.pm b/Shorewall-perl/Shorewall/Compiler.pm index ae59b38e1..4d66924c4 100644 --- a/Shorewall-perl/Shorewall/Compiler.pm +++ b/Shorewall-perl/Shorewall/Compiler.pm @@ -43,12 +43,29 @@ use Shorewall::Proc; use Shorewall::Proxyarp; our @ISA = qw(Exporter); -our @EXPORT = qw( compiler ); +our @EXPORT = qw( compiler configure ); our @EXPORT_OK = qw( $export ); our @VERSION = 1.00; our $export = 0; +# +# Configure the compiler +# +sub configure( $$$$ ) { + my ( $export_param, $shorewall_dir, $verbose, $timestamp) = @_; + + $export = $export_param if $export_param; + + if ( $shorewall_dir ne '' ) { + fatal_error "$shorewall_dir is not an existing directory" unless -d $shorewall_dir; + set_shorewall_dir( $shorewall_dir ); + } + + set_verbose( $verbose ) unless $verbose eq ''; + set_timestamp( $timestamp ) unless $timestamp eq ''; +} + # # First stage of script generation. # diff --git a/Shorewall-perl/Shorewall/Config.pm b/Shorewall-perl/Shorewall/Config.pm index a344c5f49..486c2abce 100644 --- a/Shorewall-perl/Shorewall/Config.pm +++ b/Shorewall-perl/Shorewall/Config.pm @@ -36,6 +36,7 @@ our @ISA = qw(Exporter); our @EXPORT = qw( warning_message fatal_error + set_shorewall_dir find_file split_line split_line1 @@ -281,9 +282,15 @@ sub warning_message sub fatal_error { my $lineinfo = $currentfile ? " : $currentfilename ( line $currentlinenumber )" : ''; - print STDERR " ERROR: @_$lineinfo\n"; + die " ERROR: @_$lineinfo\n"; + +} - exit 1; +# +# Set $shorewall_dir +# +sub set_shorewall_dir( $ ) { + $shorewall_dir = shift; } # diff --git a/Shorewall-perl/compiler.pl b/Shorewall-perl/compiler.pl index d333b2142..e0dc38ac3 100755 --- a/Shorewall-perl/compiler.pl +++ b/Shorewall-perl/compiler.pl @@ -25,7 +25,6 @@ # use strict; use lib '/usr/share/shorewall-perl'; -use Shorewall::Config qw( fatal_error ); use Shorewall::Compiler; use Getopt::Long; @@ -38,21 +37,26 @@ sub usage() { # Getopt::Long::Configure ('bundling'); -my $result = GetOptions('export' => \$Shorewall::Compiler::export, - 'e' => \$Shorewall::Compiler::export, - 'directory=s' => \$Shorewall::Config::shorewall_dir, - 'd=s' => \$Shorewall::Config::shorewall_dir, - 'verbose=i' => \$Shorewall::Common::verbose, - 'v=i' => \$Shorewall::Common::verbose, - 'timestamp' => \$Shorewall::Common::timestamp, - 't' => \$Shorewall::Common::timestamp ); +my ( $export , $shorewall_dir, $verbose, $timestamp ) = qw( 0 '' '' '' ); -usage unless $result; +my $result = GetOptions('export' => \$export, + 'e' => \$export, + 'directory=s' => \$shorewall_dir, + 'd=s' => \$shorewall_dir, + 'verbose=i' => \$verbose, + 'v=i' => \$verbose, + 'timestamp' => \$timestamp, + 't' => \$timestamp ); -if ( $Shorewall::Config::shorewall_dir ne '' ) { - fatal_error "$Shorewall::Config::shorewall_dir is not an existing directory" unless -d $Shorewall::Config::shorewall_dir; +usage unless $result && @ARGV < 2; + +eval { + configure( $export, $shorewall_dir, $verbose, $timestamp ); + compiler $ARGV[0]; +}; + +if ( $@ ) { + print STDERR $@; + exit 1; } -usage unless @ARGV < 2; - -compiler $ARGV[0];