Linux-KernelSort-0.01/0000755000672700001440000000000010526174401014514 5ustar ogasawarausersLinux-KernelSort-0.01/t/0000755000672700001440000000000010526174401014757 5ustar ogasawarausersLinux-KernelSort-0.01/t/Linux-KernelSort.t0000644000672700001440000000773210525223140020334 0ustar ogasawarausers# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl Linux-KernelSort.t' use Test::More tests => 20; BEGIN { use_ok('Linux::KernelSort') }; ######################### use Linux::KernelSort; my $kernel = new Linux::KernelSort; $kernel->{debug} = 0; my $version1 = "2.6.19"; my $version2 = "2.6.19-rc2-git7"; my $bad_version = "bad-2.6.19-version"; ok ($kernel->version_check($version1) eq 0, "Valid: $version1"); ok ($kernel->version_check($version2) eq 0, "Valid: $version2"); ok ($kernel->version_check($bad_version) eq 1, "Invalid: $version2"); ok ($kernel->rank("2.6.19") eq '2619.0.0.0.0.0', "Rank 2.6.19"); ok ($kernel->rank("2.6.19-mm1") eq '2619.0.0.0.0.1', "Rank 2.6.19-mm1"); ok ($kernel->rank("2.6.19-rc1") eq '2618.1.0.0.0.0', "Rank 2.6.19-rc1"); ok ($kernel->rank("2.6.19-rc1-git7") eq '2618.1.7.0.0.0', "Rank 2.6.19-rc1-git7"); ok ($kernel->rank("2.6.19-rc1-mm2") eq '2618.1.0.0.0.2', "Rank 2.6.19-rc1-mm2"); ok ($kernel->rank("2.6.19-rc1-scsi-misc2") eq '2618.1.0.2.0.0', "Rank 2.6.19-rc1-scsi-misc2"); ok ($kernel->rank("2.6.19-rc1-scsi-rc-fixes5") eq '2618.1.0.0.5.0', "Rank 2.6.19-rc1-scsi-rc-fixes5"); ok ( !defined ($kernel->rank($bad_version)), "Invalid Kernel"); ok ($kernel->compare($version1, $version2) == 1, "$version1 > $version2"); ok ($kernel->compare($version2, $version1) == -1, "$version2 < $version1"); ok ($kernel->compare($version1, $version1) == 0, "$version1 == $version2"); ok ($kernel->compare($bad_version, $version1) == -1, "$bad_version < $version1"); ok ($kernel->compare($version1, $bad_version) == 1, "$version1 > $bad_version"); ok ($kernel->compare($bad_version, $bad_version) == 0, "$bad_version == $bad_version"); my @kernel_list = ( '2.6.19', '2.6.15', '2.6.18', '2.6.18-mm2', '2.6.19-mm2', '2.6.18-rc2', '2.6.18-rc2-mm2', '2.6.18-rc2-git2', '2.6.18-rc2-git1', '2.6.18-rc2-git35', '2.6.18-rc10', '2.6.18-mm1', '2.6.18-rc2-mm1' ); my @kernel_sorted = ( '2.6.15', '2.6.18-rc2', '2.6.18-rc2-mm1', '2.6.18-rc2-mm2', '2.6.18-rc2-git1', '2.6.18-rc2-git2', '2.6.18-rc2-git35', '2.6.18-rc10', '2.6.18', '2.6.18-mm1', '2.6.18-mm2', '2.6.19', '2.6.19-mm2' ); my @sorted_list = $kernel->sort(@kernel_list); my $size1 = @sorted_list; my $size2 = @kernel_sorted; if ($size1 != $size2) { fail("Kernel Sort (containing only valid kernel names)"); } my $i; for ($i = 0; $i < $size1; $i++) { if ($kernel_sorted[$i] ne $sorted_list[$i]) { fail ("Kernel Sort (containing only valid kernel names)"); last; } } if ($i == $size1) { pass ("Kernel Sort (containing only valid kernel names)"); } my @bad_kernel_list = ( '2.6.19', '2.6.18-mm2', '2.6.0', 'bad-2.6.0', '2.6.0-foo', '2.bad.version' ); my @bad_kernel_sorted = ( 'bad-2.6.0', '2.6.0-foo', '2.bad.version', '2.6.0', '2.6.18-mm2', '2.6.19' ); @sorted_list = $kernel->sort (@bad_kernel_list); $size1 = @sorted_list; $size2 = @bad_kernel_sorted; if ($size1 != $size2) { fail("Kernel Sort (containing invalid kernel names)"); } for ($i = 0; $i < $size1; $i++) { if ($bad_kernel_sorted[$i] ne $sorted_list[$i]) { fail ("Kernel Sort (containing invalid kernel names)"); last; } } if ($i == $size1) { pass ("Kernel Sort (containing invalid kernel names)"); } Linux-KernelSort-0.01/lib/0000755000672700001440000000000010526174401015262 5ustar ogasawarausersLinux-KernelSort-0.01/lib/Linux/0000755000672700001440000000000010526174401016361 5ustar ogasawarausersLinux-KernelSort-0.01/lib/Linux/KernelSort.pm0000644000672700001440000001353010525223140021003 0ustar ogasawarausers=head1 NAME Linux::KernelSort - Perl extension for sorting and comparing Linux kernel versions. The expected kernel version naming convention is the same naming convetion demonstrated by http://www.kernel.org. NOTE: Currently, only the 2.6.x series of kernels (including -rc's, -git's, and -mm's) are properly evaluated. =head1 SYNOPSIS use Linux::KernelSort; my $kernel = new Linux::KernelSort; int $ret; my $version1 = "2.6.19"; my $version2 = "2.6.19-rc2-git7"; $ret = $kernel->compare($version1, $version2); if ($ret == 0) { print "$version1 and $version2 are the same version"; } elsif ($ret > 0) { print "$version1 is newer than $version2"; } else { print "$version1 is older than $version2"; } my @kernel_list = [ '2.6.15', '2.6.18', '2.6.18-rc2', '2.6.18-rc2-git2', '2.6.18-mm1', '2.6.18-rc2-mm1' ]; my @sorted_list = $kernel->sort($kernel_list); print "@sorted_list"; =head1 DESCRIPTION Linux::KernelSort is intended to sort a list of kernel versions into ascending order. It also provides the capability to compare two kernel versions and determine if one version is newer, older, or the same as the other version. =head1 FUNCTIONS =cut package Linux::KernelSort; use strict; use warnings; our $VERSION = '0.01'; sub new { my $class = shift; my $self = {}; $self->{debug} = 1; bless ($self, $class); return $self; } =head2 version_check() Purpose: Verify the version is valid and follows the proper naming convention demonstrated by http://www.kernel.org Input: A string containing the kernel version Return: 0 if version is valid 1 if version is invalid =cut sub version_check { my $self = shift; my $version = shift || return undef; if ( $version !~ m/^\d+\.\d+\.\d+(-rc\d+)?(-git\d+)?(-scsi-misc\d+)?(-scsi-rc-fixes\d+)?(-mm\d+)?$/ ) { if ( $self->{debug} ) { print "Invalid Kernel Version: $version\n"; } return 1; } return 0; } =head2 rank() Purpose: Generate a ranking for a given kernel version Input: A string containing the kernel version which follows the proper naming convention demonstrated by http://www.kernel.org Return: Kernel ranking =cut sub rank { my $self = shift; my $version = shift || return undef; if ( $self->version_check($version) ) { return undef; } $version =~ s/\.//g; $version =~ m/^(\d+).*/; my $rank = $1; if ( $version =~ m/-rc(\d+)/ ) { my $rc = $1; $rank = $rank - 1; $rank = $rank . ".$rc"; } else { $rank = $rank . ".0"; } if ( $version =~ m/-git(\d+)/ ) { my $git = $1; $rank = $rank . ".$git" } else { $rank = $rank . ".0"; } if ( $version =~ m/-scsi-misc(\d+)/ ) { my $scsi_misc = $1; $rank = $rank . ".$scsi_misc" } else { $rank = $rank . ".0"; } if ( $version =~ m/-scsi-rc-fixes(\d+)/ ) { my $rc_fixes = $1; $rank = $rank . ".$rc_fixes" } else { $rank = $rank . ".0"; } if ( $version =~ m/-mm(\d+)/ ) { my $mm = $1; $rank = $rank . ".$mm"; } else { $rank = $rank . ".0" } return $rank; } =head2 compare() Purpose: Compare two kernel versions Input: Strings ($kernel1, $kernel2) each containing a kernel version which follows the proper naming conventaion demonstrated by http://www.kernel.org Return -1 if $kernel1 < $kernel2 (ie $kernel1 is older than $kernel2) 0 if $kernel1 == $kernel2 (ie $kernel1 is the same version as $kernel2) 1 if $kernel1 > $kernel2 (ie $kernel1 is newer than $kernel2) =cut sub compare { my $self = shift; my $kernel1 = shift || return undef; my $kernel2 = shift || return undef; my $rank1 = $self->rank($kernel1); my $rank2 = $self->rank($kernel2); if ( !$rank1 || !$rank2 ) { if ( $self->{debug} ) { print "Unable to properly compare kernel versions: $kernel1, $kernel2\n"; } if ( !$rank1 && !$rank2 ) { return 0; } elsif ( !$rank1 ) { return -1; } else { return 1; } } while (length($rank1) && length($rank2)) { $rank1 =~ m/^(\d+)\.?(.*)/; my $value1 = $1; $rank1 = $2; $rank2 =~ m/^(\d+)\.?(.*)/; my $value2 = $1; $rank2 = $2; if ($value1 == $value2) { next; } elsif ($value1 < $value2) { return -1; } else { return 1; } } return 0; } =head2 sort() Purpose: Sort a list of kernel versions in ascending order. Uses shell sort algorithm. Input: Array of strings containing kernel versions which follows the proper naming convention demonstrated by http://www.kernel.org Return: Sorted array =cut sub sort { my $self = shift; my (@kernels) = @_; my $size = @kernels; for (my $gap = int($size/2); $gap > 0; $gap = int($gap/2)) { for (my $i = $gap; $i < $size; $i++) { for (my $j = $i-$gap; ($j >= 0) && ($self->compare($kernels[$j], $kernels[$j+$gap]) > 0); $j -= $gap) { my $temp = $kernels[$j]; $kernels[$j] = $kernels[$j+$gap]; $kernels[$j+$gap] = $temp; } } } return @kernels; } =head1 AUTHOR Leann Ogasawara ogasawara@osdl.org =head1 COPYRIGHT AND LICENSE Linux-KernelSort is Copyright (c) 2006, by Leann Ogasawara. All rights reserved. You may distribute this code under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. =cut 1; __END__ Linux-KernelSort-0.01/scripts/0000755000672700001440000000000010526174401016203 5ustar ogasawarausersLinux-KernelSort-0.01/scripts/kernelsort.pl0000755000672700001440000000717610525223140020740 0ustar ogasawarausers#!/usr/bin/perl -w use Linux::KernelSort; my $kernel = new Linux::KernelSort; $kernel->{debug} = 0; my $version1 = "2.6.19"; my $version2 = "2.6.19-rc2-git7"; if ($kernel->version_check($version1)) { print "Invalid version: $version1\n"; } else { print "Valid version: $version1\n"; } if ($kernel->version_check("$version2")) { print "Invalid version: $version2\n"; } else { print "Valid version: $version2\n"; } if ($kernel->compare($version1, $version2) == 1) { print "GOOD: $version1 > $version2\n"; } else { print "BAD: tried $version1 > $version2\n"; } print "------------------\n"; if ($kernel->compare($version2, $version1) == -1) { print "GOOD: $version2 < $version1\n"; } else { print "BAD: tried $version2 < $version1\n"; } print "------------------\n"; if ($kernel->compare($version1, $version1) == 0) { print "GOOD: $version1 == $version1\n"; } else { print "BAD: tried $version1 == $version1\n"; } print "------------------\n"; if ($kernel->compare($version2, $version2) == 0) { print "GOOD: $version2 == $version2\n"; } else { print "BAD: tried $version2 == $version2\n"; } print "------------------\n"; if ($kernel->compare("2.6.18-rc2-git2", "2.6.18-rc2-mm1") > 0) { print "GOOD: 2.6.18-rc2-git2 > 2.6.18-rc2-mm1\n"; } else { print "BAD: tried 2.6.18-rc2-git2 > 2.6.18-rc2-mm1\n"; } print "------------------\n"; if ($kernel->compare("2.6.18-rc2-mm1", "2.6.18-rc2") > 0) { print "GOOD: 2.6.18-rc2-mm1 > 2.6.18-rc2\n"; } else { print "BAD: tried 2.6.18-rc2-mm1 > 2.6.18-rc2\n"; } print "------------------\n"; if ($kernel->compare("2.6.18-mm1", "2.6.18-git1") < 0) { print "GOOD: 2.6.18-mm1 < 2.6.18-git1\n"; } else { print "BAD: tried 2.6.18-mm1 < 2.6.18-git1\n"; } print "------------------\n"; if ($kernel->compare("2.6.18-mm2", "2.6.18-mm1") > 0) { print "GOOD: 2.6.18-mm2 > 2.6.18-mm1\n"; } else { print "BAD: tried 2.6.18-mm2 > 2.6.18-mm1\n"; } print "------------------\n"; if ($kernel->compare("test-2.6.18", "2.6.18") < 0){ print "GOOD: test-2.6.18 < 2.6.18\n"; } else { print "BAD: test-2.6.18 < 2.6.18\n"; } print "------------------\n"; if ($kernel->compare("test-2.6.18", "foo-2.6.18-bar") == 0){ print "GOOD: test-2.6.18 == foo-2.6.18-bar\n"; } else { print "BAD: test-2.6.18 != foo-2.6.18-bar\n"; } print "------------------\n"; if ($kernel->compare("2.6.18", "2.6.18-foobar") > 0){ print "GOOD: 2.6.18 > 2.6.18-foobar\n"; } else { print "BAD: tried 2.6.18 > 2.6.18-foobar\n"; } print "------------------\n"; if ($kernel->compare("2.6.18", "2.6.18-scsi-misc4") < 0){ print "GOOD: 2.6.18 < 2.6.18-scsi-misc4\n"; } else { print "BAD: tried 2.6.18 > 2.6.18-scsi-misc4\n"; } print "------------------\n"; if ($kernel->compare("2.6.18-rc1", "2.6.19-rc1-scsi-misc2") < 0) { print "GOOD: 2.6.18-rc1 < 2.6.18-rc1-scsi-misc2\n"; } else { print "BAD: tried 2.6.18-rc2 > 2.6.18-rc1-scsi-misc2\n"; } print "------------------\n"; my @kernel_list = ( '2.6.19', '2.6.15', '2.6.18', '2.6.18-mm2', '2.6.19-mm2', '2.6.18-rc2', '2.6.18-rc2-mm2', '2.6.18-rc2-git2', '2.6.18-rc2-git1', '2.6.18-rc2-git35', '2.6.18-rc2-scsi-misc5', '2.6.18-rc2-scsi-rc-fixes3', '2.6.18-rc10', '2.6.18-mm1', '2.6.18-rc2-mm1', 'bad-2.6.18', '2.6.18-foo', '2.6.bad'); my @sorted_list = $kernel->sort(@kernel_list); print "@sorted_list"; Linux-KernelSort-0.01/MANIFEST0000644000672700001440000000012110523744420015640 0ustar ogasawarausersChanges Makefile.PL MANIFEST README t/Linux-KernelSort.t lib/Linux/KernelSort.pm Linux-KernelSort-0.01/Makefile.PL0000644000672700001440000000106210523744420016466 0ustar ogasawarausersuse ExtUtils::MakeMaker; use strict; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. my %opts = ( 'NAME' => 'Linux::KernelSort', 'VERSION_FROM' => 'lib/Linux/KernelSort.pm', # finds $VERSION 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 'ABSTRACT_FROM' => 'lib/Linux/KernelSort.pm', # retrieve abstract from module 'AUTHOR' => 'Leann Ogasawara ', ); WriteMakefile( %opts ); Linux-KernelSort-0.01/Changes0000644000672700001440000000025310523744420016010 0ustar ogasawarausersRevision history for Perl extension Linux::KernelSort. 0.01 Fri Nov 3 10:04:40 2006 - original version; created by h2xs 1.23 with options -AXc -n Linux::KernelSort Linux-KernelSort-0.01/README0000644000672700001440000000171410524675200015400 0ustar ogasawarausersLinux::KernelSort version 0.01 ============================== Linux::KernelSort is intended to sort a list of kernel versions into ascending order. It also provides the capability to compare two kernel versions and determine if one version is newer, older, or the same as the other version. NOTE: Currently only the 2.6.x kernel series (including -rc's, -git's, and -mm's) are properly evaluated. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install For more information on how to use KernelSort, see the pod documentation via the command perldoc Linux-KernelSort or , after installation, view the man pages with man Linux-KernelSort COPYRIGHT AND LICENCE Linux-KernelSort is Copyright (c) 2006, by Leann Ogasawara. All rights reserved. You may distribute this code under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.