2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

98_help.pm: avoid recursion error

git-svn-id: https://svn.fhem.de/fhem/trunk@8050 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2015-02-21 12:01:17 +00:00
parent 800e1d98ef
commit 9d133cf6ba

View File

@ -4,7 +4,10 @@ package main;
use strict; use strict;
use warnings; use warnings;
my $ret;
sub CommandHelp; sub CommandHelp;
sub cref_search;
sub help_Initialize($$) { sub help_Initialize($$) {
my %hash = ( Fn => "CommandHelp", my %hash = ( Fn => "CommandHelp",
@ -25,7 +28,7 @@ sub CommandHelp {
my $internals = "attributes command commands devspec global perl"; my $internals = "attributes command commands devspec global perl";
$mod = lc($mod); $mod = lc($mod);
my $modPath = AttrVal('global','modpath','.'); my $modPath = AttrVal('global','modpath','.');
my $output = ""; my $output = '';
if($internals !~ m/$mod /) { if($internals !~ m/$mod /) {
my %mods; my %mods;
@ -44,19 +47,15 @@ sub CommandHelp {
return "Module $mod not found" unless defined($mods{$mod}); return "Module $mod not found" unless defined($mods{$mod});
my $skip = 1; $output = cref_search($mods{$mod},$lang);
my ($err,@text) = FileRead({FileName => $mods{$mod}, ForceType => 'file'}); Debug $output;
return $err if $err; unless($output) {
foreach my $l (@text) { $output = cref_search($mods{$mod},"");
if($l =~ m/^=begin html$lang$/) { $output = "Keine deutsche Hilfe gefunden!<br/>$output" if $output;
$skip = 0;
} elsif($l =~ m/^=end html$lang$/) {
$skip = 1;
} elsif(!$skip) {
$output .= $l;
}
} }
$output = "No help found for module: $mod" unless $output;
} else { } else {
$output = ''; $output = '';
@ -78,8 +77,6 @@ sub CommandHelp {
} }
$output = "Keine deutsche Hilfe gefunden!\n\n".
CommandHelp(undef, "$mod en") unless $output;
if( $cl && $cl->{TYPE} eq 'telnet' ) { if( $cl && $cl->{TYPE} eq 'telnet' ) {
$output =~ s/<br>/\n/g; $output =~ s/<br>/\n/g;
@ -96,9 +93,8 @@ sub CommandHelp {
$output =~ s/&gt;/>/g; $output =~ s/&gt;/>/g;
$output =~ s/<[bui]>/\ /g; $output =~ s/<[bui]>/\ /g;
$output =~ s/<\/[bui]>/\ /g; $output =~ s/<\/[bui]>/\ /g;
$output =~ s/\ \ +/\ /g; $output =~ tr/ / /s;
$output =~ s/\t+/ /g; $output =~ s/\n\n/\n/s;
$output =~ s/\n\n/\n/g;
$output =~ s/&auml;/ä/g; $output =~ s/&auml;/ä/g;
$output =~ s/&Auml;/Ä/g; $output =~ s/&Auml;/Ä/g;
$output =~ s/&ouml;/ö/g; $output =~ s/&ouml;/ö/g;
@ -107,7 +103,7 @@ sub CommandHelp {
$output =~ s/&Uuml;/Ü/g; $output =~ s/&Uuml;/Ü/g;
$output =~ s/&szlig;/ß/g; $output =~ s/&szlig;/ß/g;
return $output; $ret = $output;
} }
return "<html>$output</html>"; return "<html>$output</html>";
@ -132,6 +128,24 @@ sub CommandHelp {
} }
} }
sub cref_search {
my ($mod,$lang) = @_;
my $output = "";
my $skip = 1;
my ($err,@text) = FileRead({FileName => $mod, ForceType => 'file'});
return $err if $err;
foreach my $l (@text) {
if($l =~ m/^=begin html$lang$/) {
$skip = 0;
} elsif($l =~ m/^=end html$lang$/) {
$skip = 1;
} elsif(!$skip) {
$output .= $l;
}
}
return $output;
}
1; 1;
=pod =pod