make config handel the markers
This commit is contained in:
148
readconfig.pl
148
readconfig.pl
@@ -4,22 +4,7 @@
|
||||
#
|
||||
# Copyright 2001 Wilmer van der Gaast (lintux@lintux.cx)
|
||||
#
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Updated for marker-aware config writing.
|
||||
|
||||
my( @info, @conf, @rawconf, $l );
|
||||
|
||||
@@ -52,6 +37,7 @@ $info[47] = 'Trustee files';
|
||||
$info[50] = 'Conversion tables';
|
||||
$info[60] = 'MAX_CONNECTIONS';
|
||||
$info[61] = 'MAX_NW_VOLS';
|
||||
$info[62] = 'Reserved';
|
||||
$info[63] = 'MAX_DIR_BASE_ENTRIES';
|
||||
$info[68] = 'USE_MMAP';
|
||||
$info[69] = 'HANDLE_ALL_SAP_TYPS';
|
||||
@@ -161,6 +147,42 @@ sub section_of_line( $ )
|
||||
return( '' );
|
||||
}
|
||||
|
||||
sub grouped_section_key( $ )
|
||||
{
|
||||
my $sec = $_[0];
|
||||
|
||||
if( $sec >= 100 && $sec <= 106 ) { return '100-106'; }
|
||||
if( $sec >= 200 && $sec <= 202 ) { return '200-202'; }
|
||||
if( $sec >= 210 && $sec <= 211 ) { return '210-211'; }
|
||||
if( $sec >= 300 && $sec <= 302 ) { return '300-302'; }
|
||||
|
||||
return $sec;
|
||||
}
|
||||
|
||||
sub build_marker_map()
|
||||
{
|
||||
my( %map, $line, $sec, $key );
|
||||
|
||||
foreach $line ( @conf )
|
||||
{
|
||||
$sec = section_of_line( $line );
|
||||
next if $sec eq '';
|
||||
|
||||
$key = grouped_section_key( $sec );
|
||||
push( @{ $map{$key} }, $line );
|
||||
}
|
||||
|
||||
# Keep SYS as first entry in section 1
|
||||
if( defined( $map{'1'} ) )
|
||||
{
|
||||
my @sys = grep( /^1 SYS /, @{ $map{'1'} } );
|
||||
my @rest = grep( !/^1 SYS /, @{ $map{'1'} } );
|
||||
$map{'1'} = [ @sys, @rest ];
|
||||
}
|
||||
|
||||
return %map;
|
||||
}
|
||||
|
||||
sub writeconfig_compact()
|
||||
{
|
||||
my( $i, $l );
|
||||
@@ -183,13 +205,63 @@ sub writeconfig_compact()
|
||||
close( CONF );
|
||||
}
|
||||
|
||||
sub writeconfig_markers()
|
||||
{
|
||||
my( %secmap, %emitted );
|
||||
my( $line, $active_key, $inside_active );
|
||||
|
||||
%secmap = build_marker_map();
|
||||
$inside_active = '';
|
||||
|
||||
open( CONF, '>' . $mars_config ) or die "Could not write $mars_config: $!";
|
||||
|
||||
foreach $line ( @rawconf )
|
||||
{
|
||||
if( $line =~ /^\s*#\s*>>>\s*SMARTHOOK\s+SECTION\s+([0-9]+(?:-[0-9]+)?)\s+ACTIVE\s+BEGIN/i )
|
||||
{
|
||||
$active_key = $1;
|
||||
$inside_active = $active_key;
|
||||
|
||||
print CONF $line;
|
||||
|
||||
if( defined( $secmap{$active_key} ) )
|
||||
{
|
||||
foreach my $entry ( @{ $secmap{$active_key} } )
|
||||
{
|
||||
print CONF $entry . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$emitted{$active_key} = 1;
|
||||
next;
|
||||
}
|
||||
|
||||
if( $line =~ /^\s*#\s*<<<\s*SMARTHOOK\s+SECTION\s+([0-9]+(?:-[0-9]+)?)\s+ACTIVE\s+END/i )
|
||||
{
|
||||
$inside_active = '';
|
||||
print CONF $line;
|
||||
next;
|
||||
}
|
||||
|
||||
if( $inside_active ne '' )
|
||||
{
|
||||
# Skip old content inside ACTIVE blocks completely.
|
||||
next;
|
||||
}
|
||||
|
||||
print CONF $line;
|
||||
}
|
||||
|
||||
close( CONF );
|
||||
}
|
||||
|
||||
sub writeconfig_preserve_layout()
|
||||
{
|
||||
my( %secmap, %written, @sections, $sec, $line, $sysline );
|
||||
my( $heading_sec );
|
||||
|
||||
sortconfig();
|
||||
|
||||
# Keep SYS as the first entry in section 1.
|
||||
$sysline = ( grep( /^1 SYS /, @conf ) )[0];
|
||||
if( defined( $sysline ) )
|
||||
{
|
||||
@@ -210,16 +282,34 @@ sub writeconfig_preserve_layout()
|
||||
|
||||
foreach $line ( @rawconf )
|
||||
{
|
||||
if( $line =~ /^\s*#.*Section\s+([0-9]+)\b/i )
|
||||
{
|
||||
$heading_sec = $1;
|
||||
|
||||
foreach $sec ( sort { $a <=> $b } keys( %secmap ) )
|
||||
{
|
||||
next if $written{$sec};
|
||||
next if $sec > $heading_sec;
|
||||
|
||||
if( defined( $secmap{$sec} ) )
|
||||
{
|
||||
foreach my $entry ( @{ $secmap{$sec} } )
|
||||
{
|
||||
print CONF $entry . "\n";
|
||||
}
|
||||
}
|
||||
$written{$sec} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$sec = section_of_line( $line );
|
||||
|
||||
# Preserve comments and blank lines exactly as they were.
|
||||
if( $sec eq '' )
|
||||
{
|
||||
print CONF $line;
|
||||
next;
|
||||
}
|
||||
|
||||
# Replace each section only once, at its first occurrence.
|
||||
if( ! $written{$sec} )
|
||||
{
|
||||
if( defined( $secmap{$sec} ) )
|
||||
@@ -231,12 +321,8 @@ sub writeconfig_preserve_layout()
|
||||
}
|
||||
$written{$sec} = 1;
|
||||
}
|
||||
|
||||
# Skip the original config line because the updated section
|
||||
# has already been emitted.
|
||||
}
|
||||
|
||||
# Append sections that did not exist in the original file.
|
||||
@sections = sort { $a <=> $b } keys( %secmap );
|
||||
foreach $sec ( @sections )
|
||||
{
|
||||
@@ -253,12 +339,28 @@ sub writeconfig_preserve_layout()
|
||||
close( CONF );
|
||||
}
|
||||
|
||||
sub config_has_smart_markers()
|
||||
{
|
||||
foreach my $line ( @rawconf )
|
||||
{
|
||||
if( $line =~ /SMARTHOOK\s+SECTION/i )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub writeconfig()
|
||||
{
|
||||
if( defined( $smart_compact_nwservconf ) && $smart_compact_nwservconf )
|
||||
{
|
||||
writeconfig_compact();
|
||||
}
|
||||
elsif( config_has_smart_markers() )
|
||||
{
|
||||
writeconfig_markers();
|
||||
}
|
||||
else
|
||||
{
|
||||
writeconfig_preserve_layout();
|
||||
|
||||
Reference in New Issue
Block a user