#! /usr/bin/perl
use warnings;
use strict;
my @currentMappings = ();
my @newMappings = ();
print "Protections:\n";
while (<>)
{
# trim leading and trailing whitespace
chomp;
s/^\s+//;
s/\s+$//;
# skip blank lines and comments
next if ($_ eq "");
next if (/^#/);
# lines that start with -// or // are mappings. Allow optional quote in the mapping name as well.
if (/^-?"?\/\//)
{
# add quotes if there is whitespace in the mapping but no quotes
s/^(-?)(.*)/$1"$2"/ if (/\s+/ && !/"/);
push(@newMappings, $_);
}
else
{
# handle the mappings changing
if (@newMappings)
{
@currentMappings = @newMappings;
@newMappings = ();
}
# parse the user line
my ($permission, $userOrGroup, $name, $ip) = split;
$ip = "*" if (!defined $ip);
# output a protection line for each mapping
foreach my $mapping (@currentMappings)
{
print "\t", $permission, " ", $userOrGroup, " ", $name, " ", $ip, " ", $mapping, "\n";
}
}
}