allow fallback to english for help
[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 my $lang = $self->lang;
18 $lang = 'en' if !$lang;
19
20 # each help file contains lines that looks like:-
21 #
22 # === 0^EN^*^Description
23 # text
24 # text
25 #
26 # === 0^EN^help^Description
27 # text
28 # text
29 # text 
30 #
31 # The fields are:- privilege level, Language, full command name, short description
32 #
33
34 my $h = new IO::File;
35
36 if (!open($h, "$main::localcmd/Commands_$lang.hlp")) {
37         $lang = 'en';
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\/]//g;
45 $line =~ s/\//\.\*\//g;
46 $line =~ s/^\s+//g;
47 $line =~ s/\s+$//g;
48 $line = "help" if $line =~ /^\s*$/;
49
50 # sort out aliases
51 my $alias = CmdAlias::get_hlp($line);
52 $line = $alias if $alias;
53
54 my $state = 0;
55 foreach $in (<$h>) {
56         next if $in =~ /^\#/;
57         chomp $in;
58         if ($in =~ /^===/) {
59             last if $state == 2;           # come out on next command
60                 $in =~ s/=== //;
61                 my ($priv, $cmd, $desc) = split /\^/, $in;
62                 next if $priv > $self->priv;             # ignore subcommands that are of no concern
63                 next unless $cmd =~ /^$line/i;
64                 push @out, "$cmd $desc" unless $cmd =~ /-$/o;
65                 $state = 1;
66                 next;
67         }
68         if ($state > 0) {
69             push @out, " $in";
70                 $state = 2;
71         }
72 }
73
74 close($h);
75
76 push @out, $self->msg('helpe2', $line) if @out == 0;
77
78 return (1, @out);
79