#!/usr/bin/perl -w
# Copyright (c)2001-2002 Joe Wreschnig, Moritz Muehlenhoff
# Feta plugin for viewing changelogs.
# Licensed under the GNU GPL.

use Getopt::Std;
use strict;

my %opts; getopts('tyqV', \%opts);

if (!$opts{'q'}) { open(QUIET, ">&STDOUT"); }
else { open(QUIET, ">>/dev/null"); }
if ($opts{'V'}) { open(VERBOSE, ">&STDOUT"); }
else { open(VERBOSE, ">>/dev/null"); }

if (!@ARGV) {
 print STDERR "E: You must give a least one package name to read its changelog.\n";
 exit 1;
}

foreach my $package (@ARGV) {
 my $found = 0;
 my @files = ("changelog.Debian", "changelog", "NEWS");

 foreach my $file (@files) {
  my $filename = "/usr/share/doc/$package/$file";
  if (-r "$filename.gz") {
   system("zcat $filename | sensible-pager");
   $found = 1;
   last;
  } elsif (-r $filename ) {
   system('sensible-pager', $filename);
   $found = 1;
   last;
  }
 }
 if (!$found) {
  print STDERR "W: $package does not appear to be installed, or have a changelog.\n";
 }
}

exit 0;
