added apropos command
[spider.git] / cmd / apropos.pl
1
2 # the help subsystem
3 #
4 # apropos - this does a grep on the command file and returns the commands
5 # that contain the string searched for
6 #
7 # Copyright (c) 1998 - Dirk Koopman G1TLH
8 #
9 # $Id$
10 #
11
12 my ($self, $line) = @_;
13 my @out;
14
15 my $lang = $self->lang;
16 $lang = 'en' if !$lang;
17
18 my $h = new FileHandle;
19
20 if (!open($h, "$main::localcmd/Commands_$lang.hlp")) {
21         if (!open($h, "$main::cmd/Commands_$lang.hlp")) {
22                 return (1, $self->msg('helpe1'));
23         }
24 }
25 my $in;
26
27 $line =~ s/\W//og;   # remove dubious characters
28
29 my $include;
30 my ($priv, $cmd, $desc);
31
32 foreach $in (<$h>) {
33         next if $in =~ /^\#/;
34         chomp $in;
35         if ($in =~ /^===/) {
36                 push @out, "$cmd $desc" if $include;
37                 $include = 0;
38                 $in =~ s/=== //;
39                 ($priv, $cmd, $desc) = split /\^/, $in;
40                 next if $priv > $self->priv;             # ignore subcommands that are of no concern
41                 next unless $cmd =~ /$line/i || $desc =~ /$line/i;
42                 next if $cmd =~ /-$/o;
43                 $include = 1;
44                 next;
45         }
46         $include =~ 1 if $cmd =~ /$line/i;
47 }
48 push @out, "$cmd $desc" if $include;
49
50 close($h);
51
52 push @out, $self->msg('helpe2', $line) if @out == 0;
53
54 return (1, @out);