#!/sw/bin/perl
##
##  GotoURL -- go to a particular URL
##  Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved. 
##

$url = $ARGV[0];

$tmpfile = "/tmp/tmp.gotourl.cf";

@RC = ();
open(RC, "<$ENV{'HOME'}/.gotourlrc");
while (<RC>) {
    next if (m|^\s*#.*|);
    next if (m|^\s*$|);
    if (m|^(\S+)\s+(.+)$|) {
        push(@RC, { PAT => $1, CMD => $2 });
    }
}
close(RC);

unlink($tmpfile);
open(FP, ">$tmpfile");
print FP "\n";
print FP "URL: $url\n";
print FP "\n";
print FP "Available clients for this URL type:\n";
print FP "\n";
foreach $rc (@RC) {
    if ($url =~ m|$rc->{PAT}|) {
        $cmd = $rc->{CMD};
        $cmd =~ s|%U|$url|g;
        $txt = $rc->{CMD};
        $txt =~ s|%U|...|g;
        print FP sprintf("%s %%%%S:%s%%%%\n", $txt, $cmd);
    }
}
print FP <<'EOT';
_____________________________________________________

Help: <up>,<down> .......... browse client list
      <return>,<right> ..... select client
      q,<left> ............. quit
EOT
close(FP);
$client = `iselect -n 'GotoURL 1.0' -t 'Select Client...' -p6 <$tmpfile`;
unlink($tmpfile);
if ($client ne '') {
    system("$client");
}

##EOF##
