#!/usr/bin/perl -w
# $Id: p0rn-dblist,v 1.8 2004/05/26 09:00:25 mitch Exp $
#
# list tables from p0rn.db
#
# 2004 (C) by Christian Garbs <mitch@cgarbs.de>
# Licensed under GNU GPL.  See COPYING for details.

use strict;
use P0rn::DB;

=head1 NAME

p0rn-dblist - list links in the p0rn database

=head1 SYNOPSIS

B<p0rn-dblist> S< [ B<-v> ] I<table>>

=head1 OVERVIEW

p0rn-dblist lists links in the p0rn database.  There should be no need
to call this program directly.

=head1 DESCRIPTION

You must set the table name upon startup.  Existing database tables
are B<thumbz> for thumbnails, B<picz> for pictures and B<downz> for
download urls.  Links are then read from the database and written to
STDOUT.

=head2 Switches

=over 5

=item B<-v>

This enables the alternative data format.

=back

=head1 DATA FORMAT

Format is one plain URL per line with no leading or trailing
whitespace.

Alternative format is a positive integer followed by a tab and a plain
URL per line.

=head1 FILES

All data is stored in a database.  By default, it is located in
B<./p0rn.db> (yes, that's the directory from which you're starting
p0rn-dblist).  Is you want to change this, set the environment
variable B<P0RNDBLOCATION> (the second letter is a zero) to another
path and filename.

=head1 SEE ALSO

L<p0rn-proxy(1)>, L<p0rn-download(1)>, L<p0rn-dbdump(1)>, L<p0rn-dbrestore(1)>

=head1 MODULES NEEDED

 use DBM::Deep;

This module can be obtained from L<http://www.cpan.org>.

=head1 BUGS

Please report bugs by mail to <F<p0rn-bugs@cgarbs.de>>.

=head1 AUTHOR

p0rn-dblist was written by Christian Garbs <F<mitch@cgarbs.de>>.

=head1 AVAILABILITY

Look for updates at L<http://www.cgarbs.de/p0rn-comfort.en.html>.

=head1 COPYRIGHT

p0rn-dblist is licensed under the GNU GPL.

=cut

my $verbose = shift;
if (defined $verbose) {
    if ($verbose ne "-v") {
	unshift @ARGV, $verbose;
	$verbose = 0;
    }
}

my $hash = opendb(shift);

if ($verbose) {
    foreach my $key (sort keys %{$hash}) {
        my $value = $hash->{$key};
        $value = 0 unless defined $value;
        $value = 2 if $value > 2;
        $value = 0 if $value < 0;
        print "$value\t$key\n";
    }
} else {
    print "$_\n" foreach (sort keys %{$hash});
}

