summaryrefslogtreecommitdiff
path: root/usr.bin/pkg-config
diff options
context:
space:
mode:
authorJasper Lievisse Adriaanse <jasper@cvs.openbsd.org>2011-06-06 11:18:56 +0000
committerJasper Lievisse Adriaanse <jasper@cvs.openbsd.org>2011-06-06 11:18:56 +0000
commit340db53cfe20943881b326acb7e746e744414eef (patch)
treefd9dee05df74b76fc5d01967f636491a2af96820 /usr.bin/pkg-config
parentc567b6c3288533f4a794e44949018e46df1c80cd (diff)
move simple numeric comparison to a single routine, instead of duplicating it
Diffstat (limited to 'usr.bin/pkg-config')
-rw-r--r--usr.bin/pkg-config/pkg-config25
1 files changed, 17 insertions, 8 deletions
diff --git a/usr.bin/pkg-config/pkg-config b/usr.bin/pkg-config/pkg-config
index ad1285c311e..a3ef3296814 100644
--- a/usr.bin/pkg-config/pkg-config
+++ b/usr.bin/pkg-config/pkg-config
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $OpenBSD: pkg-config,v 1.47 2011/06/06 11:16:59 jasper Exp $
+# $OpenBSD: pkg-config,v 1.48 2011/06/06 11:18:55 jasper Exp $
# $CSK: pkgconfig.pl,v 1.39 2006/11/27 16:26:20 ckuethe Exp $
# Copyright (c) 2006 Chris Kuethe <ckuethe@openbsd.org>
@@ -588,8 +588,8 @@ sub compare
while (@a && @b) { #so long as both lists have something
if (!(@suffix_a || @suffix_b)) {
# simple comparison when no suffixes are in the game.
- return 1 if $a[0] > $b[0];
- return -1 if $a[0] < $b[0];
+ my $rc = compare_numeric($a[0], $b[0], 0);
+ return $rc if defined($rc);
} else {
# extended comparison.
if (((scalar(@a) == 1) || (scalar(@b) == 1)) &&
@@ -607,9 +607,7 @@ sub compare
# suffixes are equal, compare on numeric
if (&$first_char($suffix_a[0]) eq
&$first_char($suffix_b[0])) {
- return 0 if ($suffix_a[1] == $suffix_b[1]);
- return 1 if ($suffix_a[1] > $suffix_b[1]);
- return -1 if ($suffix_a[1] < $suffix_b[1]);
+ return compare_numeric($suffix_a[1], $suffix_b[1], 1);
}
# rc beats beta beats alpha
@@ -637,8 +635,8 @@ sub compare
}
} else {
- return 1 if $a[0] > $b[0];
- return -1 if $a[0] < $b[0];
+ my $rc = compare_numeric($a[0], $b[0], 0);
+ return $rc if defined($rc);
}
}
@@ -649,6 +647,17 @@ sub compare
return 0;
}
+# simple numeric comparison, with optional equality test.
+sub compare_numeric
+{
+ my ($x, $y, $eq) = @_;
+
+ return 1 if $x > $y;
+ return -1 if $x < $y;
+ return 0 if (($x == $y) and ($eq == 1));
+ return undef;
+}
+
# got a package meeting the requested specific version?
sub versionmatch
{