mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
FileWrite/FileRead: input/output is \n free from now on (Forum #23872)
git-svn-id: https://svn.fhem.de/fhem/trunk@5956 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
2cb406f409
commit
3e95b90e6e
@ -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 "<div id=\"content\">$filePath: $!</div>";
|
||||
my($err, @data) = FileRead($filePath);
|
||||
if($err) {
|
||||
FW_pO "<div id=\"content\">$err</div>";
|
||||
return;
|
||||
}
|
||||
$data = join("", <FH>);
|
||||
$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 "<div id=\"content\">$filePath: $!</div>";
|
||||
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 ? "<h3>ERROR:</h3><b>$ret</b>" : "Saved the file $fileName");
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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 <SIZE> crop\n";
|
||||
push @rows, "set output '<OUT>.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 <SIZE> crop";
|
||||
push @rows, "set output '<OUT>.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, "\"<IN>\" using 1:2 axes ".
|
||||
($FW_webArgs{"axes_$i"} eq "right" ? "x1y2" : "x1y1").
|
||||
($FW_webArgs{"title_$i"} eq "notitle" ? " notitle" :
|
||||
@ -480,8 +480,14 @@ 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;
|
||||
|
@ -3799,6 +3799,7 @@ FileRead($)
|
||||
if(open(FH, $fname)) {
|
||||
@ret = <FH>;
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user