From 93b792c56e3b2709b0d9d95501908c41992d5c00 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Thu, 30 Nov 2006 13:18:23 +0000 Subject: 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. --- usr.sbin/pkg_add/OpenBSD/PkgConfig.pm | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'usr.sbin/pkg_add/OpenBSD') 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 # @@ -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"; } } -- cgit v1.2.3