diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index f2ed91d4c..12dc85318 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -1638,11 +1638,12 @@ FW_style($$) } else { $fileName =~ s,.*/,,g; # Little bit of security my $filePath = FW_fileNameToPath($fileName); - if(!open(FH, $filePath)) { - FW_pO "
$filePath: $!
"; + my($err, @data) = FileRead($filePath); + if($err) { + FW_pO "
$err
"; return; } - $data = join("", ); + $data = join("\n", @data); close(FH); } @@ -1671,14 +1672,13 @@ FW_style($$) my $filePath = FW_fileNameToPath($fileName); if($cfgDB ne 'configDB') { # save file to filesystem - if(!open(FH, ">$filePath")) { + + $FW_data =~ s/\r//g; + my $err = FileWrite($filePath, split("\n", $FW_data)); + if($err) { FW_pO "
$filePath: $!
"; return; } - $FW_data =~ s/\r//g if($^O !~ m/Win/); - binmode (FH); - print FH $FW_data; - close(FH); my $ret = FW_fC("rereadcfg") if($filePath eq $attr{global}{configfile}); $ret = FW_fC("reload $fileName") if($fileName =~ m,\.pm$,); $ret = ($ret ? "

ERROR:

$ret" : "Saved the file $fileName"); diff --git a/fhem/FHEM/91_eventTypes.pm b/fhem/FHEM/91_eventTypes.pm index 120993d10..1e158da33 100755 --- a/fhem/FHEM/91_eventTypes.pm +++ b/fhem/FHEM/91_eventTypes.pm @@ -37,7 +37,6 @@ eventTypes_Define($$) my ($err, @content) = FileRead($f); foreach my $l (@content) { - chomp($l); next if($l =~ m/ CULHM (SND|RCV) /); next if($l =~ m/ UNKNOWNCODE /); next if($l =~ m/^\d+ global /); @@ -114,7 +113,7 @@ eventTypes_Shutdown($$) my $ldata = $modules{eventTypes}{ldata}; foreach my $t (sort keys %{$ldata}) { foreach my $e (sort keys %{$ldata->{$t}}) { - push @content, "$ldata->{$t}{$e} $t $e\n"; + push @content, "$ldata->{$t}{$e} $t $e"; } } FileWrite($fName, @content); diff --git a/fhem/FHEM/95_holiday.pm b/fhem/FHEM/95_holiday.pm index fabf935ab..37d01a33d 100755 --- a/fhem/FHEM/95_holiday.pm +++ b/fhem/FHEM/95_holiday.pm @@ -69,7 +69,6 @@ holiday_refresh($$) foreach my $l (@holidayfile) { next if($l =~ m/^\s*#/); next if($l =~ m/^\s*$/); - chomp($l); my $found; if($l =~ m/^1/) { # Exact date: 1 MM-DD Holiday diff --git a/fhem/FHEM/98_SVG.pm b/fhem/FHEM/98_SVG.pm index 6c74529d3..836ba8358 100755 --- a/fhem/FHEM/98_SVG.pm +++ b/fhem/FHEM/98_SVG.pm @@ -443,22 +443,22 @@ SVG_WriteGplot($) return if(!$fName); my @rows; - push @rows, "# Created by FHEM/98_SVG.pm, ".TimeNow()."\n"; - push @rows, "set terminal png transparent size crop\n"; - push @rows, "set output '.png'\n"; - push @rows, "set xdata time\n"; - push @rows, "set timefmt \"%Y-%m-%d_%H:%M:%S\"\n"; - push @rows, "set xlabel \" \"\n"; - push @rows, "set title '$FW_webArgs{title}'\n"; - push @rows, "set ytics ".$FW_webArgs{ytics}."\n"; - push @rows, "set y2tics ".$FW_webArgs{y2tics}."\n"; + push @rows, "# Created by FHEM/98_SVG.pm, ".TimeNow(); + push @rows, "set terminal png transparent size crop"; + push @rows, "set output '.png'"; + push @rows, "set xdata time"; + push @rows, "set timefmt \"%Y-%m-%d_%H:%M:%S\""; + push @rows, "set xlabel \" \""; + push @rows, "set title '$FW_webArgs{title}'"; + push @rows, "set ytics ".$FW_webArgs{ytics}.""; + push @rows, "set y2tics ".$FW_webArgs{y2tics}.""; push @rows, "set grid".($FW_webArgs{gridy} ? " ytics" :""). - ($FW_webArgs{gridy2} ? " y2tics":"")."\n"; - push @rows, "set ylabel \"$FW_webArgs{ylabel}\"\n"; - push @rows, "set y2label \"$FW_webArgs{y2label}\"\n"; - push @rows, "set yrange $FW_webArgs{yrange}\n" if($FW_webArgs{yrange}); - push @rows, "set y2range $FW_webArgs{y2range}\n" if($FW_webArgs{y2range}); - push @rows, "\n"; + ($FW_webArgs{gridy2} ? " y2tics":"").""; + push @rows, "set ylabel \"$FW_webArgs{ylabel}\""; + push @rows, "set y2label \"$FW_webArgs{y2label}\""; + push @rows, "set yrange $FW_webArgs{yrange}" if($FW_webArgs{yrange}); + push @rows, "set y2range $FW_webArgs{y2range}" if($FW_webArgs{y2range}); + push @rows, ""; my $ld = $FW_webArgs{logdevicetype}; my @plot; @@ -471,7 +471,7 @@ SVG_WriteGplot($) join(":", map { $v[$_] =~ s/:/\\x3a/g if($_<$#v); $v[$_] } 0..$#v) : $v[0]; - push @rows, "#$ld $r\n"; + push @rows, "#$ld $r"; push @plot, "\"\" using 1:2 axes ". ($FW_webArgs{"axes_$i"} eq "right" ? "x1y2" : "x1y1"). ($FW_webArgs{"title_$i"} eq "notitle" ? " notitle" : @@ -480,9 +480,15 @@ SVG_WriteGplot($) " lw " .$FW_webArgs{"width_$i"} . " with " .$FW_webArgs{"type_$i"}; } - push @rows, "\n"; - push @rows, "plot ".join(",\\\n ", @plot)."\n"; - + push @rows, ""; + for(my $i=0; $i < @plot; $i++) { + my $r = $plot[$i]; + $r = "plot $r" if($i == 0); + $r = " $r" if($i > 0); + $r = "$r,\\" if($i+1 < @plot); + push @rows, $r; + } + my $err = FileWrite($fName, @rows); FW_pO "SVG_WriteGplot: $err" if($err); @@ -509,7 +515,6 @@ SVG_readgplotfile($$) foreach my $l (@svgplotfile) { $l = "$l\n" unless $l =~ m/\n$/; - $l =~ s/\r//g; my $plotfn = undef; if($l =~ m/^#$ldType (.*)$/) { $plotfn = $1; diff --git a/fhem/fhem.pl b/fhem/fhem.pl index f1aaa3586..826e2aca5 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -3799,6 +3799,7 @@ FileRead($) if(open(FH, $fname)) { @ret = ; close(FH); + chomp(@ret); } else { $err = "Can't open $fname: $!"; } @@ -3818,8 +3819,9 @@ FileWrite($@) } else { if(open(FH, ">$fname")) { + binmode (FH); foreach my $l (@rows) { - print FH $l; + print FH $l,"\n"; } close(FH); return undef;