#!/usr/local/bin/perl

# Version 1
#
#  Use this in whatever way you like, it's not worth copyrighting :-)

$psfile="keyblank.ps";
$|=1;

@ENV{'PATH'}='/usr/bin:/usr/ucb:/usr/local/bin';

$username=$ARGV[0] || `whoami`;
$username =~ /(\w+)/;
$username = $1;

open(NAMES, "keyinfo $username|")
  || die "can't run keyinfo: $!, stopped";
$key = <NAMES>;
$key =~ /^\d+\s+(\w+)/
  || die "User $username not found.  Make sure you have run keyinit, stopped";
$key = $1;
close(NAMES);
open(KEYS, "key -n 99 99 $key|")
  || die "can't open $keyfile: $!, stopped";
open(PS, "<$psfile") || die "can't open $psfile: $!, stopped";

while(<KEYS>)
{
  /^(\d+):\s(.+)$/ && do { $key{$1}=$2; next; }; 
};

close(KEYS);

while(<PS>)
{
  s/USERNAME/$key/;
  s/^\((\d+):\)/($1: $key{$1})/;
  print;
}
