2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

apostrophe is now allowed

git-svn-id: https://svn.fhem.de/fhem/trunk@5803 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
damian-s 2014-05-09 19:56:39 +00:00
parent 4023ad98d2
commit ed19741cfd

View File

@ -86,7 +86,7 @@ ReadingValIf($$$)
my $element; my $element;
$r=$defs{$name}{READINGS}{$reading}{VAL}; $r=$defs{$name}{READINGS}{$reading}{VAL};
if ($regExp) { if ($regExp) {
$element = ($r =~ /$regExp/) ? $1 : ""; $element = ($r =~ /$regExp/) ? $1 : "";
} else { } else {
$element=$r; $element=$r;
} }
@ -155,6 +155,7 @@ ReplaceAllReadingsIf($$)
my $ret = eval $block; my $ret = eval $block;
return($block." ",$@) if ($@); return($block." ",$@) if ($@);
# return($eval,"no reading value") if (!$ret); # return($eval,"no reading value") if (!$ret);
$ret =~ s/'/\\'/g;
$block=$ret; $block=$ret;
} }
} else { } else {
@ -202,27 +203,31 @@ ParseCommandsIf($)
my $err=""; my $err="";
my $parsedCmd=""; my $parsedCmd="";
my $pos=0; my $pos=0;
$tailBlock =~ s/;/;;/g;
while ($tailBlock ne "") { while ($tailBlock ne "") {
if ($tailBlock=~ /^\s*\{/) { # perl block if ($tailBlock=~ /^\s*\{/) { # perl block
($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\{\}]'); ($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\{\}]');
return ($currentBlock,$err) if ($err); return ($currentBlock,$err) if ($err);
return($currentBlock, 'use "'." instead of '") if ($currentBlock =~ /'/); $parsedCmd.=$currentBlock;
$parsedCmd.="{".$currentBlock."}";
} }
if ($tailBlock =~ /^\s*IF/) { if ($tailBlock =~ /^\s*IF/) {
($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]'); #condition ($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]'); #condition
return ($currentBlock,$err) if ($err); return ($currentBlock,$err) if ($err);
$parsedCmd.=$beginning."(".$currentBlock.")"; $parsedCmd.="fhem('".$beginning."(".$currentBlock.")";
($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]'); #if case ($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]'); #if case
return ($currentBlock,$err) if ($err); return ($currentBlock,$err) if ($err);
$currentBlock =~ s/'/\\'/g;
$currentBlock =~ s/;/;;/g;
$parsedCmd.=$beginning."(".$currentBlock.")"; $parsedCmd.=$beginning."(".$currentBlock.")";
if ($tailBlock =~ /^\s*ELSE/) { if ($tailBlock =~ /^\s*ELSE/) {
($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]'); #else case ($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]'); #else case
return ($currentBlock,$err) if ($err); return ($currentBlock,$err) if ($err);
$currentBlock =~ s/'/\\'/g;
$currentBlock =~ s/;/;;/g;
$parsedCmd.=$beginning."(".$currentBlock.")"; $parsedCmd.=$beginning."(".$currentBlock.")";
} }
} else { #repalce Readings if no IF command $parsedCmd.="')";
} else { #replace Readings if no IF command
if ($tailBlock =~ /^\s*\(/) { # remove bracket if ($tailBlock =~ /^\s*\(/) { # remove bracket
($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]'); ($beginning,$currentBlock,$err,$tailBlock)=GetBlockIf($tailBlock,'[\(\)]');
return ($currentBlock,$err) if ($err); return ($currentBlock,$err) if ($err);
@ -236,13 +241,13 @@ ParseCommandsIf($)
$tailBlock=""; $tailBlock="";
} }
if ($currentBlock ne "") { if ($currentBlock ne "") {
return($currentBlock, 'use "'." instead of '") if ($currentBlock =~ /'/); $currentBlock =~ s/'/\\'/g;
($currentBlock,$err)=ReplaceAllReadingsIf($currentBlock,1); ($currentBlock,$err)=ReplaceAllReadingsIf($currentBlock,1);
return ($currentBlock,$err) if ($err); return ($currentBlock,$err) if ($err);
($currentBlock,$err)=EvalAllIf($currentBlock); ($currentBlock,$err)=EvalAllIf($currentBlock);
$currentBlock =~ s/;/;;;;/g; $currentBlock =~ s/;/;;/g;
return ($currentBlock,$err) if ($err); return ($currentBlock,$err) if ($err);
$parsedCmd.=$currentBlock; $parsedCmd.="fhem('".$currentBlock."')";
$parsedCmd.=";;" if ($tailBlock); $parsedCmd.=";;" if ($tailBlock);
} else { } else {
$parsedCmd.=";;" if ($tailBlock); $parsedCmd.=";;" if ($tailBlock);
@ -303,8 +308,8 @@ CmdIf($)
return ($else_cmd,$err) if ($err); return ($else_cmd,$err) if ($err);
} }
my $perl_cmd="{if(".$cond.")"; my $perl_cmd="{if(".$cond.")";
$perl_cmd .="{fhem('".$if_cmd."')}"; $perl_cmd .="{".$if_cmd."}";
$perl_cmd .= "else{fhem('".$else_cmd."')}" if ($else_cmd); $perl_cmd .= "else{".$else_cmd."}" if ($else_cmd);
$perl_cmd.="}"; $perl_cmd.="}";
return($perl_cmd,""); return($perl_cmd,"");
} }