X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fhelp.pl;h=cc9eee3a1cf3d32e58d3b090212c373b0614d619;hb=eac4538f1f78b3d014539dc548fc6322e8337429;hp=c74fad166ba4a073f70cf2d025be99040b99fcf4;hpb=4c92a7711c41cc7ba1c60d5a49a94db239032ac1;p=spider.git diff --git a/cmd/help.pl b/cmd/help.pl index c74fad16..cc9eee3a 100644 --- a/cmd/help.pl +++ b/cmd/help.pl @@ -7,63 +7,115 @@ # # Copyright (c) 1998 - Dirk Koopman G1TLH # -# $Id$ +# # my ($self, $line) = @_; my @out; # this is naff but it will work for now -$line = "help" if !$line; my $lang = $self->lang; $lang = 'en' if !$lang; # each help file contains lines that looks like:- # -# === 0^EN^*^Description +# === 0^*^Description # text # text # -# === 0^EN^help^Description +# === 0^help^Description # text # text # text # -# The fields are:- privilege level, Language, full command name, short description +# The fields are:- privilege level, full command name, short description # -my $h = new FileHandle; +#$DB::single = 1; + -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 $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; + } + } +} + my $in; -$line =~ s/![\w\/]//og; -$line =~ s/\//\.\*\//og; +#$line =~ s/[^\w\/]//g; +#$line =~ s/\//\.\*\//g; + +$line =~ s{[^\w/]}{}g; +$line =~ s{/}{.*/}g; +$line =~ s/^\s+//g; +$line =~ s/[\s\r]+$//g; +$line = "help" if $line =~ /^\s*$/; + +# sort out aliases +my $alias = CmdAlias::get_hlp($line); +$line = $alias if $alias; -my $include; -foreach $in (<$h>) { +# non english help (if available) +if ($h) { + my $state = 0; + foreach $in (<$h>) { + next if $in =~ /^\#/; + chomp $in; + $in =~ s/\r$//; + if ($in =~ /^===/) { + last if $state == 2; # come out on next command + $in =~ s/=== //; + my ($priv, $cmd, $desc) = split /\^/, $in; + next if $priv > $self->priv; # ignore subcommands that are of no concern + next unless $cmd =~ /^$line/i; + push @out, "$cmd $desc" unless $cmd =~ /-$/o; + $state = 1; + next; + } + if ($state > 0) { + push @out, " $in"; + $state = 2; + } + } + $h->close; + + # return if some help was given, otherwise continue to english help + return (1, @out) if @out && $state == 2; +} + +# standard 'english' help +my $state = 0; +foreach $in (<$defh>) { next if $in =~ /^\#/; chomp $in; if ($in =~ /^===/) { - $include = 0; + last if $state == 2; # come out on next command $in =~ s/=== //; my ($priv, $cmd, $desc) = split /\^/, $in; next if $priv > $self->priv; # ignore subcommands that are of no concern - next unless $cmd =~ /$line/i; + next unless $cmd =~ /^$line/i; push @out, "$cmd $desc" unless $cmd =~ /-$/o; - $include = 1; + $state = 1; next; } - push @out, " $in" if $include; + if ($state > 0) { + push @out, " $in"; + $state = 2; + } } - -close($h); +$defh->close; push @out, $self->msg('helpe2', $line) if @out == 0; - return (1, @out);