-set -e
-
-VERSION='$Rev$'
-USAGE="Usage: $0 [-p papersize] [-r revoked-style] keyid-or-name"
-
-
-if [ -z "$*" ]; then
- echo $USAGE
- exit 1
-fi
-
-KEYIDS=
-REVOKESTYLE=hide
-
-while [ -n "$1" ]; do
- case "$1" in
- -p)
- PAPERSIZE=$2
- export PAPERSIZE
- shift 2
- ;;
- -p*)
- PAPERSIZE=`echo $1 | sed -e 's/^-p//'`
- export PAPERSIZE
- shift 1
- ;;
- -r)
- REVOKESTYLE=$2
- shift 2
- ;;
- -r*)
- REVOKESTYLE=`echo $1 | sed -e 's/^-r//'`
- shift 1
- ;;
- -*)
- echo $USAGE
- exit 1
- ;;
- *)
- KEYIDS=$1
- shift 1
- ;;
- esac
-done
-
-case "$REVOKESTYLE" in
-grey|hide|note|show|strike)
- ;;
-*)
- echo >&2 "Unknown style \"$REVOKESTYLE\". Please use one of"
- echo >&2 " grey - Print text in grey"
- echo >&2 " hide - Don't show revoked uids"
- echo >&2 " note - Add \"(revoked)\""
- echo >&2 " show - List revoked uids normally"
- echo >&2 " strike - Strike through lines"
- exit 1
- ;;
-esac
-
-TMPFILE=`mktemp -t gpg-key2ps.XXXXXX`
-
-if ! gpg --fingerprint --with-colons $KEYIDS 2>/dev/null >$TMPFILE; then
- echo >&2 "Key not found. Try 'gpg --list-keys'"
- rm $TMPFILE
- exit 1
-fi
-
-NUMLINES=$((`wc -l <$TMPFILE` + `grep '^pub:' $TMPFILE | wc -l` - 1))
-
-if test -x /usr/bin/paperconf; then
- w=`paperconf -w`
- h=`paperconf -h`
-else
+use strict;
+use Getopt::Long;
+
+my $version = '$Rev$';
+$version =~ s/\$Rev:\s*(\d+)\s*\$/$1/;
+my $revokestyle = "hide";
+my $creationdate = scalar(localtime);
+
+sub version($) {
+ my $fd = shift;
+ print $fd "gpg-key2ps $version - (c) 2001-2006 Simon Richter, Thijs Kinkhorst, Christoph Berg\n";
+}
+
+sub usage($$) {
+ my ($fd, $exitcode) = @_;
+ version ($fd);
+ print $fd <<EOF;
+Usage: $0 [-p papersize] [-r revoked-style] keyid-or-name ...
+Options:
+ -p --paper-size
+ -r --revoked-style
+ hide - Don't show revoked uids (default)
+ grey - Print text in grey
+ note - Add "[revoked]"
+ show - List revoked uids normally
+ strike - Strike through lines
+ -h --help
+ -v --version
+EOF
+ exit $exitcode;
+}
+
+# fetch command line parameters
+my $opts;
+Getopt::Long::config('bundling');
+if (!GetOptions (
+ '-h' => \$opts->{help},
+ '--help' => \$opts->{help},
+ '-v' => \$opts->{version},
+ '--version' => \$opts->{version},
+ '-p=s' => \$opts->{papersize},
+ '--paper-size=s' => \$opts->{papersize},
+ '-r=s' => \$opts->{revokestyle},
+ '--revoked-style=s' => \$opts->{revokestyle},
+)) {
+ usage(\*STDERR, 1);
+}
+
+if ($opts->{help}) {
+ usage (\*STDOUT, 0);
+}
+
+if ($opts->{version}) {
+ version (\*STDOUT);
+ exit 0;
+}
+
+if ( $opts->{revokestyle} ) { $revokestyle = $opts->{revokestyle}; }
+if ( $opts->{papersize} ) { $ENV{'PAPERSIZE'} = $opts->{papersize}; }
+
+if ( $revokestyle !~ /^(grey|hide|note|show|strike)$/ ) {
+ print STDERR "Unknown revoked-style \"$revokestyle\".\n";
+ usage (\*STDERR, 1);
+}
+
+usage(\*STDERR, 1) unless scalar @ARGV >= 1;
+
+# determine the paper size through the paperconf tool
+my $w; my $h;
+if ( `which paperconf` && $? == 0 ) {
+ $w=`paperconf -w`;
+ $h=`paperconf -h`;
+ chomp($w);
+ chomp($h);
+} else {