started the addition of help files
[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 <cmd>.hlp in either the local_cmd directory
6 # or the cmd directory (in that order). 
7 #
8 # if you just type in 'help' by itself you get what is in 'help.hlp'.
9 #
10 # Copyright (c) 1998 - Dirk Koopman G1TLH
11 #
12 # $Id$
13 #
14
15 my ($self, $line) = @_;
16 my @out;
17 my ($path, $fcmd) = ($main::cmd, "help");;
18 my @out;
19 my @inpaths = ($main::localcmd, $main::cmd);
20 my @helpfiles;
21
22 # this is naff but it will work for now
23 $line = "help" if !$line;
24 $fcmd = lc $line;
25
26 # each help file starts with a line that looks like:-
27 #
28 # === 0^EN^HELP^Description
29 # text
30 # text
31 # text 
32 #
33 # The fields are:- privilege level, Language, full command name, short description
34 #
35
36 if (!open(H, "$path/$fcmd.hlp")) {
37   return (1, "no help on $line available");
38 }
39 my $in;
40 my $include = 0;
41 my @in = <H>;
42 close(H);
43
44 foreach $in (@in) {
45   next if $in =~ /^\s*\#/;
46   chomp $in;
47   if ($in =~ /^===/) {
48     $include = 0;
49     $in =~ s/=== //;
50         my ($priv, $lang, $cmd, $desc) = split /\^/, $in;
51         next if $priv > $self->priv;             # ignore subcommands that are of no concern
52         next if $self->lang && $self->lang ne $lang;
53         push @out, "$cmd - $desc";
54         $include = 1;
55         next;
56   }
57   push @out, $in if $include;
58 }
59
60 push @out, "No help available for $line" if @out == 0;
61
62 return (1, @out);
63