#! /usr/bin/perl

# Copyright (C) 2006 Arne Wichmann
#
# This little thing is distributed under the GNU General Public License,
# version 2. If you need the license, ask your distributor for it.

# This gets as input a list of packages and version numbers.
# It outputs packagename/distribution for every package whose version
# number in the package cache is bigger than the one given.

# use strict;
use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Version;
use AptPkg::Cache;

$_config->init;
$_config->{quiet} = 2;

$_system = $_config->system;
$vs = $_system->versioning;

my $cache = AptPkg::Cache->new;

for (<>) {

  chop;
  ($pack,$ver,$comment)=split(' ',$_,3);

  $p=$cache->{$pack};
  print "$pack not here\n" and next unless $p and $p->{VersionList};

  for (@{$p->{VersionList}}) {
    next if $vs->compare($_->{VerStr},$ver)<0;
    print "$pack/".$_->{FileList}->[0]->{File}->{Archive};
    print " ($comment)" if $comment;
    print "\n";
    $ok=1;
    last;
  }
}

exit 1-$ok;
