Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Deal with backreferences

  • Loading branch information...
commit 6df133f3fcd480cd91bc85723e4f35c1f07eff5b 1 parent 985edd1
@jcameron jcameron authored
Showing with 34 additions and 5 deletions.
  1. +34 −5 dovecot/dovecot-lib.pl
View
39 dovecot/dovecot-lib.pl
@@ -28,11 +28,11 @@ sub get_config
return \@get_config_cache;
}
-# read_config_file(filename)
+# read_config_file(filename, [&include-parent-rv])
# Convert a file into a list od directives
sub read_config_file
{
-local ($file) = @_;
+local ($file, $incrv) = @_;
local $filedir = $file;
$filedir =~ s/\/[^\/]+$//;
local $lnum = 0;
@@ -92,6 +92,32 @@ sub read_config_file
push(@{$section->{'members'}}, $dir);
$section->{'eline'} = $lnum;
}
+
+ # Fix up references to other variables
+ my @w = split(/\s+/, $dir->{'value'});
+ my $changed;
+ foreach my $w (@w) {
+ if ($w =~ /^\$(\S+)/) {
+ my $var = $1;
+ my ($prev) = grep { $_->{'name'} eq $var } @rv;
+ if (!$prev && $incrv) {
+ ($prev) = grep { $_->{'name'} eq $var }
+ @$incrv;
+ }
+ if ($prev) {
+ $w = $prev->{'value'};
+ $changed = 1;
+ }
+ else {
+ $w = undef;
+ $changed = 1;
+ }
+ }
+ }
+ if ($changed) {
+ @w = grep { defined($_) } @w;
+ $dir->{'value'} = join(" ", @w);
+ }
push(@rv, $dir);
}
elsif (/^\s*!(include|include_try)\s+(\S+)/) {
@@ -101,7 +127,7 @@ sub read_config_file
$glob = $filedir."/".$glob;
}
foreach my $i (glob($glob)) {
- push(@rv, &read_config_file($i));
+ push(@rv, &read_config_file($i, \@rv));
}
}
$lnum++;
@@ -123,7 +149,7 @@ sub find
@rv = grep { $_->{'sectionname'} eq $sname &&
$_->{'sectionvalue'} eq $svalue } @rv;
}
-return wantarray ? @rv : $rv[0];
+return wantarray ? @rv : $rv[$#rv];
}
# find_value(name, &config, [disabled-mode], [sectionname], [sectionvalue])
@@ -134,8 +160,11 @@ sub find_value
if (wantarray) {
return map { $_->{'value'} } @rv;
}
+elsif (!@rv) {
+ return undef;
+ }
else {
- return $rv[0]->{'value'};
+ return $rv[$#rv]->{'value'};
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.