# $Id$ # package main; use strict; use warnings; use Data::Dumper; my $ret; sub CommandHelp; sub cref_internals; sub cref_search; sub cref_search_cmd; sub cref_fill_list; sub cref_findInfo; sub help_Initialize($$) { my %hash = ( Fn => "CommandHelp", Hlp => "[],get help (this screen or module dependent docu)", InternalCmds => cref_internals() ); $cmds{help} = \%hash; cref_fill_list(); } sub CommandHelp { my ($cl, $arg) = @_; my ($mod,$lang) = split(" ",$arg); $lang //= AttrVal('global','language','en'); $lang = (lc($lang) eq 'de') ? '_DE' : ''; if($mod) { $mod = "help" if($mod eq "?"); $mod = $defs{$mod}->{TYPE} if( defined($defs{$mod}) && $defs{$mod}->{TYPE} ); $mod = lc($mod); my $modPath = AttrVal('global','modpath','.'); my $output = ''; my $outputInfo = cref_findInfo($modPath,$mod); if($cmds{help}{InternalCmds} !~ m/$mod\,/) { my %mods; my @modDir = ("$modPath/FHEM"); $mod = $cmds{$mod}{ModuleName} if defined($cmds{$mod}) && defined($cmds{$mod}{ModuleName}); foreach my $modDir (@modDir) { eval { 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}); # read commandref docu from file $output = cref_search($mods{$mod},$lang); unless($output) { $output = cref_search($mods{$mod},""); $output = "

Keine deutsche Hilfe gefunden!
$output" if $output; } $output = "No help found for module: $mod" unless $output; $output = $outputInfo.$output; } else { $output = "
Internal command: $mod"; my $i; my $f = "$modPath/docs/commandref_frame$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' ) { # telnet output $output =~ s//\n/ig; $output =~ s/\s*
  • \s*/\n- /ig; $output =~ s/<\/?ul>/\n/ig; $output =~ s/<\/?[^>]+>//g; $output =~ s/<//g; $output =~ tr/ / /s; $output =~ s/\n\n\ /\n/g; $output =~ s/ / /g; $output =~ s/ä/ä/g; $output =~ s/Ä/Ä/g; $output =~ s/ö/ö/g; $output =~ s/Ö/Ö/g; $output =~ s/ü/ü/g; $output =~ s/Ü/Ü/g; $output =~ s/ß/ß/g; $output =~ s/\n\s*\n\s*\n/\n\n\n/g; $output =~ s/^\s+//; $output =~ s/\s+$//; } else { # html output my $url_prefix; if(AttrVal('global','exclude_from_update','') =~ m/commandref/) { $url_prefix = "http://fhem.de/commandref$lang.html"; } else { $url_prefix = "$FW_ME/docs/commandref$lang.html"; } # replace tags with a # working real link to commandref $output =~ s,$output"; } return $output; } else { # mod # cref_search_cmd(undef); my $str = "Possible commands:\n\n" . "Command Parameter\n" . " Description\n" . "----------------------------------------------------------------------\n"; for my $cmd (sort keys %cmds) { next if($cmd =~ m/header:command/); next if(!$cmds{$cmd}{Hlp}); next if($cl && $cmds{$cmd}{ClientFilter} && $cl->{TYPE} !~ m/$cmds{$cmd}{ClientFilter}/); my @a = split(",", $cmds{$cmd}{Hlp}, 2); # $a[0] =~ s//>/g; $a[1] //= ""; $a[1] = " $a[1]"; # $a[1] =~ s//>/g; $str .= sprintf("%-15s%-50s\n%s\n", $cmd, $a[0], $a[1]); } return $str; } } sub cref_internals { my $mod = "./docs/commandref_frame.html"; my $output = ""; my ($err,@text) = FileRead({FileName => $mod, ForceType => 'file'}); return $err if $err; foreach my $l (@text) { if($l =~ m/(^