added apropos command
[spider.git] / cmd / apropos.pl
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..111e9b25292bb4a2ec83946aff25badc7f0e9780 100644 (file)
@@ -0,0 +1,54 @@
+# 
+# the help subsystem
+#
+# apropos - this does a grep on the command file and returns the commands
+# that contain the string searched for
+#
+# Copyright (c) 1998 - Dirk Koopman G1TLH
+#
+# $Id$
+#
+
+my ($self, $line) = @_;
+my @out;
+
+my $lang = $self->lang;
+$lang = 'en' if !$lang;
+
+my $h = new FileHandle;
+
+if (!open($h, "$main::localcmd/Commands_$lang.hlp")) {
+       if (!open($h, "$main::cmd/Commands_$lang.hlp")) {
+               return (1, $self->msg('helpe1'));
+       }
+}
+my $in;
+
+$line =~ s/\W//og;   # remove dubious characters
+
+my $include;
+my ($priv, $cmd, $desc);
+
+foreach $in (<$h>) {
+       next if $in =~ /^\#/;
+       chomp $in;
+       if ($in =~ /^===/) {
+               push @out, "$cmd $desc" if $include;
+               $include = 0;
+               $in =~ s/=== //;
+               ($priv, $cmd, $desc) = split /\^/, $in;
+               next if $priv > $self->priv;             # ignore subcommands that are of no concern
+               next unless $cmd =~ /$line/i || $desc =~ /$line/i;
+               next if $cmd =~ /-$/o;
+               $include = 1;
+               next;
+       }
+       $include =~ 1 if $cmd =~ /$line/i;
+}
+push @out, "$cmd $desc" if $include;
+
+close($h);
+
+push @out, $self->msg('helpe2', $line) if @out == 0;
+
+return (1, @out);