# $Id: 98_help.pm 8032 2015-02-18 18:36:37Z betateilchen $ # package main; use strict; use warnings; sub CommandHelp; sub help_Initialize($$) { my %hash = ( Fn => "CommandHelp", Hlp => "[],get help (this screen or module dependent docu)" ); $cmds{help} = \%hash; } sub CommandHelp { my ($cl, $arg) = @_; my ($mod,$lang) = split(" ",$arg); $lang //= AttrVal('global','language','en'); $lang = (lc($lang) eq 'de') ? '_DE' : ''; if($mod) { my $internals = "attributes command commands devspec global perl"; $mod = lc($mod); my $modPath = AttrVal('global','modpath','.'); my $output = ""; if($internals !~ m/$mod/) { my %mods; my @modDir = ("$modPath/FHEM"); foreach my $modDir (@modDir) { opendir(DH, $modDir) || die "Cant open $modDir: $!\n"; while(my $l = readdir DH) { next if($l !~ m/^\d\d_.*\.pm$/); my $of = $l; $l =~ s/.pm$//; $l =~ s/^[0-9][0-9]_//; $mods{lc($l)} = "$modDir/$of"; } } return "Module $mod not found" unless defined($mods{$mod}); my $skip = 1; my ($err,@text) = FileRead({FileName => $mods{$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; } } } else { $output = ''; my $i; my $f = "$modPath/docs/commandref$lang.html"; my $skip = 1; my ($err,@text) = FileRead({FileName => $f, ForceType => 'file'}); return $err if $err; foreach my $l (@text) { if($l =~ m/^{TYPE} eq 'telnet' ) { $output =~ s/
/\n/g; $output =~ s//\n/g; $output =~ s/<\/a>//g; $output =~ s///g; $output =~ s/