X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fapropos.pl;h=ac1d0f609a9ea792e429b5351f8bbe66170803ca;hb=b463dee2efa3edb72fab9bf1c64364ea38408bec;hp=26a60e7ccca6bdaf573e4ab9550fe2ef4853314e;hpb=a06ff95db570322cf86b713d4a6b410ea007b8e0;p=spider.git diff --git a/cmd/apropos.pl b/cmd/apropos.pl index 26a60e7c..ac1d0f60 100644 --- a/cmd/apropos.pl +++ b/cmd/apropos.pl @@ -15,25 +15,38 @@ my @out; my $lang = $self->lang; $lang = 'en' if !$lang; -my $h = new IO::File; +my $in; +$line = 'help' unless $line; +$line =~ s/\W//g; # remove dubious characters + +my ($priv, $cmd, $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 =~ s/\W//og; # remove dubious characters +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; + } + } +} +# do english help my $include; -my ($priv, $cmd, $desc); - -foreach $in (<$h>) { +foreach $in (<$defh>) { next if $in =~ /^\#/; chomp $in; + $in =~ s/\r$//; if ($in =~ /^===/) { - push @out, "$cmd $desc" if $include; + $cmd{$cmd} = "$cmd $desc" if $include; $include = 0; $in =~ s/=== //; ($priv, $cmd, $desc) = split /\^/, $in; @@ -43,11 +56,36 @@ foreach $in (<$h>) { $include = 1; next; } - $include =~ 1 if $cmd =~ /$line/i; + $include = 1 if $cmd =~ /$line/i; +} +$cmd{$cmd} = "$cmd $desc" if $include; +$defh->close; + +# override with any not english help +if ($h) { + my $include; + foreach $in (<$h>) { + next if $in =~ /^\#/; + chomp $in; + $in =~ s/\r$//; + if ($in =~ /^===/) { + $cmd{$cmd} = "$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; + } + $cmd{$cmd} = "$cmd $desc" if $include; + $h->close; } -push @out, "$cmd $desc" if $include; -close($h); +push @out, map {$cmd{$_}} sort keys %cmd; push @out, $self->msg('helpe2', $line) if @out == 0;