#! /usr/bin/perl -w

$kver = shift() || _help();

for $f (<fragments-*>) {
    if($f =~ m/fragments-([0-9]+\.[0-9]+\.[0-9]+)/) {
	if($1 le $kver) {
	    if(!defined($best) || ($1 gt $bver)) {
		$best = $f;
		$bver = $1;
	    }
	}
    }
}

if(!defined($best)) {
    exit 0;
}

open(FRAGS, "$best");
while(<FRAGS>) {
    chomp;
    s/\#.*//;
    next if(m/^\s*$/);
    print `cat $_`;
}
close(FRAGS);

sub _help {
    print "Usage: select_fragments <kernel version>\n";
    exit 1;
}
