diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-04-28 06:50:22 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-04-28 06:50:22 +0000 |
commit | c81d4960d450e1bb563668a3ebacc0638dcfc7d0 (patch) | |
tree | fb234e629221ca7cca5a90da692a5cebf508d341 | |
parent | b96df966c6f52f1a207ab2ef2383af6299cb6686 (diff) |
slightly more intricate selectors code.
Approved by at least sturm@ and fries@
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingList.pm | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm index 82e9c4a944b..1fd3740d751 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm @@ -1,4 +1,4 @@ -# $OpenBSD: PackingList.pm,v 1.6 2004/02/23 21:47:48 espie Exp $ +# $OpenBSD: PackingList.pm,v 1.7 2004/04/28 06:50:21 espie Exp $ # # Copyright (c) 2003 Marc Espie. # @@ -48,31 +48,73 @@ sub read } else { $plist = new $a; } + $code = \&defaultCode if !defined $code; + &$code($fh, + sub { + local $_ = shift; + next if m/^\s*$/; + chomp; + OpenBSD::PackingElement::Factory($_, $plist); + }); + return $plist; +} + +sub defaultCode +{ + my ($fh, $cont) = @_; + local $_; while (<$fh>) { - next if m/^\s*$/; - next if defined $code and !&$code; - chomp; - OpenBSD::PackingElement::Factory($_, $plist); + &$cont($_); } - return $plist; } -# XXX Please don't define other selectors yourself, as this is a hack -# XXX that is bound to change in the future. +sub DirrmOnly +{ + my ($fh, $cont) = @_; + local $_; + while (<$fh>) { + next unless m/^\@cwd/ || m/^\@dirrm/ || m/^\@name/; + &$cont($_); + } +} -sub OpenBSD::PackingList::DirrmOnly +sub FilesOnly { - m/^\@cwd/ || m/^\@dirrm/ || m/^\@name/; + my ($fh, $cont) = @_; + local $_; + while (<$fh>) { + next unless m/^\@cwd/ || m/^\@name/ || !m/^\@/; + &$cont($_); + } } -sub OpenBSD::PackingList::FilesOnly +sub ConflictOnly { - m/^\@cwd/ || m/^\@name/ || !m/^\@/; + my ($fh, $cont) = @_; + local $_; + while (<$fh>) { + next unless m/^\@pkgcfl/ || m/^\@option/ || m/^\@name/; + &$cont($_); + } } -sub OpenBSD::PackingList::ConflictOnly +sub SharedStuffOnly { - m/^\@pkgcfl/ || m/^\@option/ || m/^\@name/; + my ($fh, $cont) = @_; + local $_; +MAINLOOP: + while (<$fh>) { + if (m/^\@shared/) { + &$cont($_); + while(<$fh>) { + redo MAINLOOP unless m/^\@md5/ || m/^\@size/; + &$cont($_); + } + } else { + next unless m/^\@cwd/ || m/^\@dirrm/ || m/^\@name/; + } + &$cont($_); + } } sub write |