-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbeeb
executable file
·71 lines (58 loc) · 1.45 KB
/
beeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w
use strict;
use FindBin;
# Simple wrapper so you can do "beeb dcat" or similar. In this
# way you just need to symlink this "beeb" program into your PATH
# (eg $HOME/bin) and that's it.
my $INSTALL_DIR="";
# Set this one variable if the program can't work out the symlink
# target properly!
# $INSTALL_DIR="/where/you/installed/the/program";
my $prog=$0; $prog=~s!^.*/!!;
if (!$INSTALL_DIR)
{
$INSTALL_DIR=$FindBin::RealBin;
my $prog2=$INSTALL_DIR . "/$prog";
die "Can not find myself in $INSTALL_DIR\n" unless -x $prog2;
if ( -l $prog2 )
{
$INSTALL_DIR=readlink $prog2;
$INSTALL_DIR=~s!/[^/]*$!!;
}
$prog2=$INSTALL_DIR . "/$prog";
die "Can not find myself in $INSTALL_DIR\n" unless -x $prog2;
}
my %all_cmds;
map { s!^.*/!!; s/\.pl$//; $all_cmds{$_}=1; } <$INSTALL_DIR/*.pl>;
if (!@ARGV)
{
print "Syntax: $prog command [args]\n";
print " Possible commands:\n";
foreach (sort keys %all_cmds)
{
print " $_\n";
}
exit;
}
my $opt=$ARGV[0];
$opt=~s/\.pl$//;
shift @ARGV;
# Pretend *. - maps to "info"
$opt="info" if $opt eq ".";
# If the option ends in a "." then find what commands match
if ($opt =~ /\.$/)
{
my $match;
foreach (sort keys %all_cmds)
{
if ($_ =~ /^$opt/)
{
die "Ambiguous: $opt matches multiple commands\n" if $match;
$match=$_;
}
}
$opt=$match if $match;
}
die "Bad command: $opt\n" unless $all_cmds{$opt};
my $cmd="$INSTALL_DIR/$opt.pl";
exec($cmd,@ARGV);