fix console.pl max scroll depth
[spider.git] / cmd / apropos.pl
index 1226a0a729df48fc63ebddeec50b0eb9c7d4d28c..1d6ac6bf5ab73b80715fc41098f81f1e9edea55c 100644 (file)
@@ -1,4 +1,3 @@
-# 
 # the help subsystem
 #
 # apropos - this does a grep on the command file and returns the commands
@@ -6,7 +5,7 @@
 #
 # Copyright (c) 1998 - Dirk Koopman G1TLH
 #
-# $Id$
+#
 #
 
 my ($self, $line) = @_;
@@ -15,40 +14,82 @@ my @out;
 my $lang = $self->lang;
 $lang = 'en' if !$lang;
 
-my $h = new IO::File;
+#print "$line\n";
+my $in;
+$line = 'help' unless $line;
+$line =~ s/\ball\b/.*/;
+$line =~ s/\W//g;   # remove dubious characters
+print "$line\n";
+
+my ($priv, $cmd, $param, $desc);
+my %cmd;
 
-if (!open($h, "$main::localcmd/Commands_$lang.hlp")) {
-       if (!open($h, "$main::cmd/Commands_$lang.hlp")) {
+my $defh = new IO::File;
+unless ($defh->open("$main::localcmd/Commands_en.hlp")) {
+       unless($defh->open("$main::cmd/Commands_en.hlp")) {
                return (1, $self->msg('helpe1'));
        }
 }
-my $in;
-
-$line = 'help' unless $line;
-$line =~ s/\W//og;   # remove dubious characters
 
-my $include;
-my ($priv, $cmd, $desc);
+my $h;
+if ($lang ne 'en') {
+       $h = new IO::File;
+       unless ($h->open("$main::localcmd/Commands_$lang.hlp")) {
+               unless($h->open("$main::cmd/Commands_$lang.hlp")) {
+                       undef $h;
+               }
+       }
+}
 
-foreach $in (<$h>) {
+# do english help
+foreach $in (<$defh>) {
        next if $in =~ /^\#/;
        chomp $in;
+       $in =~ s/\r$//;
        if ($in =~ /^===/) {
-               push @out, "$cmd $desc" if $include;
-               $include = 0;
-               $in =~ s/=== //;
-               ($priv, $cmd, $desc) = split /\^/, $in;
+#              print "$in\n";
+               ($priv, $cmd, $param, $desc) = $in =~ m{^===\s+(\d)\^(\S+)(\s+[^\^]+)?\^(.*)};
+               $param ||= '';
+               $desc ||= '';
                next if $priv > $self->priv;             # ignore subcommands that are of no concern
-               next unless $cmd =~ /$line/i || $desc =~ /$line/i;
+               next unless $in =~ /$line/i;
                next if $cmd =~ /-$/o;
-               $include = 1;
+               push @{$cmd{$cmd}->{en}}, "$cmd$param $desc";
                next;
        }
-       $include =~ 1 if $cmd =~ /$line/i;
 }
-push @out, "$cmd $desc" if $include;
+$defh->close;
 
-close($h);
+# override with any not english help
+if ($h) {
+       my $include;
+       foreach $in (<$h>) {
+               next if $in =~ /^\#/;
+               chomp $in;
+               $in =~ s/\r$//;
+               if ($in =~ /^===/) {
+#                      print "$in\n";
+                       ($priv, $cmd, $param, $desc) = $in =~ m{^===\s+(\d)\^(\S+)(\s+[^\^]+)?\^(.*)};
+                       $param ||= '';
+                   $desc ||= '';
+                       next if $priv > $self->priv;             # ignore subcommands that are of no concern
+                       next unless $in =~ /$line/i;
+                       next if $cmd =~ /-$/o;
+                       push @{$cmd{$cmd}->{$lang}}, "$cmd$param $desc";
+                       next;
+               }
+       }
+       $h->close;
+}
+
+foreach my $k (sort keys %cmd) {
+       my $v;
+       if ($v = $cmd{$k}->{$lang}) {
+               push @out, @$v; 
+       } elsif ($v = $cmd{$k}->{en}) {
+               push @out, @$v;
+       }
+}
 
 push @out, $self->msg('helpe2', $line) if @out == 0;