#!/usr/bin/env perl
# Copyright (c) 2008,2009,2010,2011 David Sugar, Tycho Softworks
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

if (-d "/var/lib/pacman") {
    if("$ARGV[0]" eq "") {
        system("pacman -Qq");
        exit 0;
    }
    foreach(@ARGV) {
        $path = "$_";
        if(index($path, "/") > -1) {
            system("pacman -Qo $path");
        }
        else {
            system("pacman -Ql $path");
        }
    }
    exit 0;
}

if (-e "/etc/debian_version") {
    if("$ARGV[0]" eq "") {
        system("dpkg --get-selections | grep -v '[a-z]install\$' | cut -f1");
        exit 0;
    }
    foreach(@ARGV) {
        $path = "$_";
        if(index($path, "/") > -1) {
            system("dpkg-query -S $path");
        }
        else {
            system("dpkg -L $path");
        }
    }
    exit 0
}

if (-e "/etc/redhat-release") {
    if("$ARGV[0]" eq "") {
        system("rpm -qa");
        exit 0;
    }
    foreach(@ARGV) {
        $path = "$_";
        if(index($path, "/") > -1) {
            system("rpm -qf $path");
        }
        else {
            system("rpm -ql $path");
        }
    }
    exit 0;
}

die("*** cape-list: unknown platform\n");

