1. Fixed DXBearing::is_qra so that it correctly detects full QRA locators
[spider.git] / cmd / help.pl
1
2 # the help subsystem
3 #
4 # It is a very simple system in that you type in 'help <cmd>' and it
5 # looks for a file called command.hlp in either the local_cmd directory
6 # or the cmd directory (in that order). 
7 #
8 # Copyright (c) 1998 - Dirk Koopman G1TLH
9 #
10 # $Id$
11 #
12
13 my ($self, $line) = @_;
14 my @out;
15
16 # this is naff but it will work for now
17 $line = "help" if !$line;
18 my $lang = $self->lang;
19 $lang = 'en' if !$lang;
20
21 # each help file contains lines that looks like:-
22 #
23 # === 0^EN^*^Description
24 # text
25 # text
26 #
27 # === 0^EN^help^Description
28 # text
29 # text
30 # text 
31 #
32 # The fields are:- privilege level, Language, full command name, short description
33 #
34
35 my $h = new FileHandle;
36
37 if (!open($h, "$main::localcmd/Commands_$lang.hlp")) {
38         if (!open($h, "$main::cmd/Commands_$lang.hlp")) {
39                 return (1, $self->msg('helpe1'));
40         }
41 }
42 my $in;
43
44 $line =~ s/![\w\/]//og;
45 $line =~ s/\//\.\*\//og;
46
47 my $include;
48 foreach $in (<$h>) {
49         next if $in =~ /^\#/;
50         chomp $in;
51         if ($in =~ /^===/) {
52                 $include = 0;
53                 $in =~ s/=== //;
54                 my ($priv, $cmd, $desc) = split /\^/, $in;
55                 next if $priv > $self->priv;             # ignore subcommands that are of no concern
56                 next unless $cmd =~ /$line/i;
57                 push @out, "$cmd $desc" unless $cmd =~ /-$/o;
58                 $include = 1;
59                 next;
60         }
61         push @out, "   $in" if $include;
62 }
63
64 close($h);
65
66 push @out, $self->msg('helpe2', $line) if @out == 0;
67
68 return (1, @out);
69