diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2006-11-30 13:18:23 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2006-11-30 13:18:23 +0000 |
commit | 93b792c56e3b2709b0d9d95501908c41992d5c00 (patch) | |
tree | 02a538cdcc16979431a99d4215a4f86f1b9a39b7 /usr.sbin/pkg_add | |
parent | 550a4ae300170741fc1185103d61f4845877aa64 (diff) |
apply some normalization to some properties while reading or writing,
for instance, parse Requirements correctly, and simplify Libs before
writing.
We normalize Libs before writing because it's more efficient.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgConfig.pm | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgConfig.pm b/usr.sbin/pkg_add/OpenBSD/PkgConfig.pm index 8d2ca8f1214..8cc5b0d4a98 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgConfig.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgConfig.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PkgConfig.pm,v 1.5 2006/11/30 01:04:35 espie Exp $ +# $OpenBSD: PkgConfig.pm,v 1.6 2006/11/30 13:18:22 espie Exp $ # # Copyright (c) 2006 Marc Espie <espie@openbsd.org> # @@ -20,6 +20,16 @@ use warnings; # this is a 'special' package, interface to the *.pc file format of pkg-config. package OpenBSD::PkgConfig; +# specific properties may have specific needs. + +my $parse = { + Requires => sub { [split /[,\s]\s*/, shift ] } +}; + +my $write = { + Libs => sub { " ".__PACKAGE__->compress(shift) } +}; + sub new { my $class = shift; @@ -49,11 +59,17 @@ sub add_property die "Duplicate property $name"; } push(@{$self->{proplist}}, $name); + my $v; if (defined $value) { - $self->{properties}->{$name} = [split /\s+/, $value] ; + if (defined $parse->{$name}) { + $v = $parse->{$name}($value); + } else { + $v = [split /\s+/, $value] ; + } } else { - $self->{properties}->{$name} = []; + $v = []; } + $self->{properties}->{$name} = $v; } sub read_fh @@ -77,6 +93,10 @@ sub read_fh die "Incorrect cfg file $name"; } } + if (defined $cfg->{properties}->{Libs}) { + $cfg->{properties}->{Libs} = + $cfg->compress_list($cfg->{properties}->{Libs}); + } return $cfg; } @@ -97,9 +117,14 @@ sub write_fh } print $fh "\n\n"; foreach my $property (@{$self->{proplist}}) { - print $fh "$property:", - (map { " $_" } @{$self->{properties}->{$property}}), - "\n"; + my $p = $self->{properties}->{$property}; + print $fh "$property:"; + if (defined $write->{$property}) { + print $fh $write->{$property}($p); + } else { + print $fh (map { " $_" } @$p); + } + print $fh "\n"; } } |