added show sun
[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 IO::File;
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 = 'help' unless $line;
28 $line =~ s/\W//og;   # remove dubious characters
29
30 my $include;
31 my ($priv, $cmd, $desc);
32
33 foreach $in (<$h>) {
34         next if $in =~ /^\#/;
35         chomp $in;
36         if ($in =~ /^===/) {
37                 push @out, "$cmd $desc" if $include;
38                 $include = 0;
39                 $in =~ s/=== //;
40                 ($priv, $cmd, $desc) = split /\^/, $in;
41                 next if $priv > $self->priv;             # ignore subcommands that are of no concern
42                 next unless $cmd =~ /$line/i || $desc =~ /$line/i;
43                 next if $cmd =~ /-$/o;
44                 $include = 1;
45                 next;
46         }
47         $include =~ 1 if $cmd =~ /$line/i;
48 }
49 push @out, "$cmd $desc" if $include;
50
51 close($h);
52
53 push @out, $self->msg('helpe2', $line) if @out == 0;
54
55 return (1, @out);