Reimplement object_enable/disable

Signed-off-by: Tom Eastep <teastep@shorewall.net>

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@9824 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2009-04-07 03:22:30 +00:00
parent b6053d8577
commit 0744df13d6
2 changed files with 37 additions and 0 deletions

View File

@ -640,6 +640,7 @@ sub compiler {
setup_notrack;
unless ( $command eq 'check' ) {
enable_object;
#
# Place Header in the object
#
@ -682,6 +683,7 @@ sub compiler {
unless ( $command eq 'check' ) {
pop_indent;
emit '}';
disable_object;
}
#
@ -689,6 +691,8 @@ sub compiler {
# (Writes the setup_routing_and_traffic_shaping() function to the compiled script)
#
unless ( $command eq 'check' ) {
enable_object;
emit( "\n#",
'# Setup routing and traffic shaping',
'#',
@ -709,6 +713,7 @@ sub compiler {
unless ( $command eq 'check' ) {
pop_indent;
emit "}\n";
disable_object;
}
#
@ -781,6 +786,7 @@ sub compiler {
progress_message3 "Shorewall6 configuration verified";
}
} else {
enable_object;
#
# I N I T I A L I Z E
# (Writes the initialize() function to the compiled script)
@ -810,6 +816,8 @@ sub compiler {
copy $globals{SHAREDIRPL} . 'prog.footer6';
}
}
disable_object;
#
# Close, rename and secure the object
#

View File

@ -56,6 +56,8 @@ our @EXPORT_OK = qw( $shorewall_dir initialize read_a_line1 set_config_path shor
our %EXPORT_TAGS = ( internal => [ qw( create_temp_object
finalize_object
enable_object
disable_object
numeric_value
numeric_value1
in_hex
@ -145,6 +147,10 @@ our $timestamp;
#
our $object;
#
# When 'true', writes to the object are enabled. Used to catch code emission between functions
#
our $object_enabled;
#
# True, if last line emitted is blank
#
our $lastlineblank;
@ -296,6 +302,7 @@ sub initialize( $ ) {
$log_verbose = -1; # Verbosity of log.
$timestamp = ''; # If true, we are to timestamp each progress message
$object = 0; # Object (script) file Handle Reference
$object_enabled = 0; # Object (script) file Handle Reference
$lastlineblank = 0; # Avoid extra blank lines in the output
$indent1 = ''; # Current indentation tabs
$indent2 = ''; # Current indentation spaces
@ -757,6 +764,8 @@ sub in_hex8( $ ) {
# Replaces leading spaces with tabs as appropriate and suppresses consecutive blank lines.
#
sub emit {
assert( $object_enabled );
if ( $object ) {
#
# 'compile' as opposed to 'check'
@ -781,6 +790,8 @@ sub emit {
# Write passed message to the object with newline but no indentation.
#
sub emit_unindented( $ ) {
assert( $object_enabled );
print $object "$_[0]\n" if $object;
}
@ -972,6 +983,8 @@ sub pop_indent() {
# Functions for copying files into the object
#
sub copy( $ ) {
assert( $object_enabled );
if ( $object ) {
my $file = $_[0];
@ -1002,6 +1015,8 @@ sub copy( $ ) {
# This one handles line continuation and 'here documents'
sub copy1( $ ) {
assert( $object_enabled );
if ( $object ) {
my $file = $_[0];
@ -1112,6 +1127,20 @@ sub finalize_aux_config() {
progress_message3 "Shorewall configuration compiled to $file";
}
#
# Enable writes to the object file
#
sub enable_object() {
$object_enabled = 1;
}
#
# Diusable writes to the object file
#
sub disable_object() {
$object_enabled = 0;
}
#
# Set $config{CONFIG_PATH}
#