Add support for the += operator, which appends to a multiple-value variable.

This commit is contained in:
Dag-Erling Smørgrav 2005-11-14 13:32:30 +00:00
parent c9b130583b
commit 9f88b80ace
2 changed files with 19 additions and 6 deletions

View File

@ -84,8 +84,9 @@ used to specify default values shared by multiple configurations.
The configuration consists of a list of single- or multiple-value
variable assignments:
.Bl -tag
.It Va variable = Ar value
.It Va variable = Ar value1 , Ar value2, ...
.It Va single_variable = Ar value
.It Va multi_variable = Ar value1 , Ar value2, ...
.It Va multi_variable += Ar value3 , ...
.El
.Pp
Whitespace around the equal sign and around the commas separating

View File

@ -143,8 +143,8 @@ sub readconf($) {
$line .= $_;
if (length($line) && $line !~ s/\\$/ /) {
die("$fn: syntax error on line $n\n")
unless ($line =~ m/^(\w+)\s*=\s*(.*)$/);
my ($key, $val) = (uc($1), $2);
unless ($line =~ m/^(\w+)\s*([+]?=)\s*(.*)$/);
my ($key, $op, $val) = (uc($1), $2, $3);
$val = ''
unless defined($val);
die("$fn: unknown keyword on line $n\n")
@ -154,10 +154,22 @@ sub readconf($) {
foreach (@a) {
s/^\'([^\']*)\'$/$1/;
}
$CONFIG{$key} = \@a;
if ($op eq '=') {
$CONFIG{$key} = \@a;
} elsif ($op eq '+=') {
push(@{$CONFIG{$key}}, @a);
} else {
die("can't happen\n");
}
} else {
$val =~ s/^\'([^\']*)\'$/$1/;
$CONFIG{$key} = $val;
if ($op eq '=') {
$CONFIG{$key} = $val;
} elsif ($op eq '+=') {
die("$fn: invalid operator on line $n\n");
} else {
die("can't happen\n");
}
}
$line = "";
}