@@ -22,9 +22,9 @@ TStationData = class of TStationDataClass;
2222var
2323 Stations: TStringList;
2424 start: TDateTime; // for timing
25-
26- procedure ProcessFile (inFile: String; outFile: String);
27- procedure DumpFile (outFile: String);
25+
26+ procedure ProcessFile (inFile: String; outFile: String; UseStdOut: Boolean );
27+ procedure DumpFile (outFile: String; UseStdOut: Boolean );
2828
2929implementation
3030
@@ -92,7 +92,7 @@ function MeanFixup(total: Integer; count: Integer): String;
9292 MeanFixup := RoundTowardPositiveInfinity(Mean);
9393end ;
9494
95- procedure DumpFile (outFile: String);
95+ procedure DumpFile (outFile: String; UseStdOut: Boolean );
9696var
9797 outputFileStream: TFileStream;
9898 StationCount: Integer;
@@ -105,7 +105,10 @@ procedure DumpFile(outFile: String);
105105
106106begin
107107 try
108- outputFileStream := TFileStream.Create(outFile, fmCreate);
108+ if Not (UseStdOut) then
109+ begin
110+ outputFileStream := TFileStream.Create(outFile, fmCreate);
111+ end ;
109112 // not used for console
110113 StationCount := Stations.count;
111114
@@ -128,7 +131,7 @@ procedure DumpFile(outFile: String);
128131 bufferStr := bufferStr + Stations[index] + ' =' + IntegerFixup(EntryMin) +
129132 ' /' + MeanFixup(EntrySum, EntryCount) + ' /' + IntegerFixup(EntryMax);
130133
131- if outFile = ' CONSOLE ' then // send to STDOUT, where it gets mangled
134+ if UseStdOut then // send to STDOUT, where it gets mangled
132135 begin
133136 write(bufferStr);
134137 end
@@ -140,19 +143,19 @@ procedure DumpFile(outFile: String);
140143 end ;
141144
142145 bufferStr := ' }' + Chr(10 ); // linefeed appears at end of baseline file
143- if outFile = ' CONSOLE ' then // send to STDOUT, where it gets mangled
146+ if UseStdOut then // send to STDOUT, where it gets mangled
144147 begin
145148 write(bufferStr);
146149 end
147150 else
148151 begin
149152 outputFileStream.WriteBuffer(TEncoding.UTF8.GetBytes(bufferStr),
150153 TEncoding.UTF8.GetByteCount(bufferStr));
154+ outputFileStream.Free;
151155 end ;
152- outputFileStream.Free;
153156
154157 finally
155- if outFile <> ' CONSOLE ' then
158+ if Not (UseStdOut) then
156159 begin
157160 WriteLn;
158161 WriteLn;
@@ -162,7 +165,7 @@ procedure DumpFile(outFile: String);
162165
163166end ;
164167
165- procedure ProcessFile (inFile: String; outFile: String);
168+ procedure ProcessFile (inFile: String; outFile: String; UseStdOut: Boolean );
166169
167170var
168171 inputStream: TFileStream;
@@ -179,7 +182,7 @@ procedure ProcessFile(inFile: String; outFile: String);
179182
180183begin
181184 InitCities;
182- if outFile <> ' CONSOLE ' then
185+ if Not (UseStdOut) then
183186 begin
184187 WriteLn(' Building Weather Station List...' );
185188 end ;
0 commit comments