summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-03-07 12:04:14 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-03-07 12:04:14 +0000
commit78c6d42fb0e287b40f625ac35469e87345b7cab1 (patch)
treecc8be40c4f9eb6aefb36053e70e935dd28ff2291
parentae86cf1eed2dbd7e8529b31e1117082b01999c1e (diff)
introduce versionspecs as a derivative object from version.
Allows an operator such as <=. also overrides the compare operator for the pnum part, because specifically, in pkgspecs, if the pnum is not specified, it stands for "any pnum will do"... yes, that's hairy...
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageName.pm50
1 files changed, 48 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageName.pm b/usr.sbin/pkg_add/OpenBSD/PackageName.pm
index d4ec0668d42..c42bd216169 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageName.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageName.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageName.pm,v 1.32 2008/10/20 10:25:16 espie Exp $
+# $OpenBSD: PackageName.pm,v 1.33 2009/03/07 12:04:13 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -231,6 +231,12 @@ sub to_string
return $string;
}
+sub pnum_compare
+{
+ my ($a, $b) = @_;
+ return $a->{pnum} <=> $b->{pnum}
+}
+
sub compare
{
my ($a, $b) = @_;
@@ -240,7 +246,7 @@ sub compare
}
# Simple case: only p number differs
if ($a->{string} eq $b->{string}) {
- return $a->{pnum} <=> $b->{pnum}
+ return $a->pnum_compare($b);
}
# Try a diff in dewey numbers first
for (my $i = 0; ; $i++) {
@@ -295,6 +301,46 @@ sub dewey_compare
return $a cmp $b;
}
+package OpenBSD::PackageName::versionspec;
+our @ISA = qw(OpenBSD::PackageName::version);
+
+sub from_string
+{
+ my ($class, $s) = @_;
+ my ($op, $version) = ('=', $s);
+ if ($s =~ m/^(\>\=|\>|\<\=|\<|\=)(.*)$/) {
+ ($op, $version) = ($1, $2);
+ }
+ my $self = $class->SUPER::from_string($version);
+ $self->{op} = $op;
+ return $self;
+}
+
+sub pnum_compare
+{
+ my ($spec, $b) = @_;
+ if ($spec->{pnum} == -1) {
+ return 0;
+ } else {
+ return $spec->SUPER::pnum_compare($b);
+ }
+}
+
+sub match
+{
+ my ($self, $b) = @_;
+
+ my $op = $self->{op};
+
+ my $compare = - $self->compare($b);
+ return 0 if $op eq '<' && $compare >= 0;
+ return 0 if $op eq '<=' && $compare > 0;
+ return 0 if $op eq '>' && $compare <= 0;
+ return 0 if $op eq '>=' && $compare < 0;
+ return 0 if $op eq '=' && $compare != 0;
+ return 1;
+}
+
package OpenBSD::PackageName::Stem;
sub to_string
{