#!/bin/env perl -w
#
# $Id: qdepend 830 2006-09-19 18:23:08Z comand $
#
# Copyright 2006 Cory Omand <comand@blastwave.org>
# All rights reserved.  Use is subject to license terms.
#
# Redistribution and/or use, with or without modification, is
# permitted.  This software is without warranty of any kind.  The
# author(s) shall not be liable in the event that use of the
# software causes damage.
#
# qdepend - Quick depend formatter for use with installed packages.
#

use strict;

@ARGV or die "Usage: $0 [P|I|R] <pkg> ... <pkgN>\n";

my $DEPTYPE = "P";
   $DEPTYPE = shift @ARGV if $ARGV[0] =~ /P|I|R/;

foreach my $pkg (@ARGV) {
    my ($pinfo) = `pkginfo -x $pkg 2>&1`;
    if (($? >> 8) != 0) {
        print STDERR $pinfo;
        next;
    }
    $pinfo =~ s/\s{2,}/ /g;
    chomp($pinfo);
    print "$DEPTYPE $pinfo\n";
}

