Skip to content

Commit 9de95d5

Browse files
authored
Merge pull request #61 from EagleAglow/main
Fix "-" issue
2 parents f651a24 + 2c571ad commit 9de95d5

4 files changed

Lines changed: 31 additions & 103 deletions

File tree

entries/bfire/src/ConsoleUnit.pas

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,17 @@ function ParseConsoleParams: Boolean;
7171
// initialize values
7272
valid := 0;
7373
ParamOK := false;
74+
ParseConsoleParams := false; // default
75+
inputFilename := '';
76+
outputFilename := '';
7477
// initialize the params list
7578
if not Assigned(FParams) then
7679
FParams := TStringList.Create(dupIgnore, false, false);
7780

7881
J := 0;
7982
for I := 1 to ParamCount do
8083
begin
81-
if pos('-', ParamStr(I)) > 0 then
84+
if pos('-', ParamStr(I)) = 1 then
8285
begin
8386
FParams.Add(Copy(ParamStr(I), 2, ParamStr(I).Length));
8487
inc(J);
@@ -161,7 +164,7 @@ function ParseConsoleParams: Boolean;
161164
if J = -1 then // send to console
162165
begin
163166
// WriteLn(Format(rsErrorMessage, [rsMissingOutputFlag]));
164-
outputFilename := 'CONSOLE';
167+
outputFilename := '';
165168
inc(valid);
166169
end
167170
else
@@ -171,7 +174,7 @@ function ParseConsoleParams: Boolean;
171174
end;
172175

173176
// check if everything was provided
174-
Result := valid = 2;
177+
ParseConsoleParams := valid = 2;
175178
end;
176179

177180
end.

entries/bfire/src/ProcessUnit.pas

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ TStationData = class of TStationDataClass;
2222
var
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

2929
implementation
3030

@@ -92,7 +92,7 @@ function MeanFixup(total: Integer; count: Integer): String;
9292
MeanFixup := RoundTowardPositiveInfinity(Mean);
9393
end;
9494

95-
procedure DumpFile(outFile: String);
95+
procedure DumpFile(outFile: String; UseStdOut: Boolean);
9696
var
9797
outputFileStream: TFileStream;
9898
StationCount: Integer;
@@ -105,7 +105,10 @@ procedure DumpFile(outFile: String);
105105

106106
begin
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

163166
end;
164167

165-
procedure ProcessFile(inFile: String; outFile: String);
168+
procedure ProcessFile(inFile: String; outFile: String; UseStdOut: Boolean);
166169

167170
var
168171
inputStream: TFileStream;
@@ -179,7 +182,7 @@ procedure ProcessFile(inFile: String; outFile: String);
179182

180183
begin
181184
InitCities;
182-
if outFile <> 'CONSOLE' then
185+
if Not(UseStdOut) then
183186
begin
184187
WriteLn('Building Weather Station List...');
185188
end;

entries/bfire/src/bfire.dpr

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,28 @@ uses
1111

1212
var
1313
keypress: String; // dummy for readln
14+
UseStdOut: Boolean; // True unless output file is defined
1415

1516
begin
17+
UseStdOut := True;
1618
try
1719
if ParseConsoleParams then
1820
begin
1921
inputFilename := ExpandFileName(inputFilename);
20-
if outputFilename <> 'CONSOLE' then
22+
if outputFilename <> '' then
2123
begin
24+
UseStdOut := False;
2225
outputFilename := ExpandFileName(outputFilename);
2326
WriteLn(Format(rsInputFile, [inputFilename]));
2427
WriteLn(Format(rsOutputFile, [outputFilename]));
2528
WriteLn;
2629
start := Now();
2730
end;
2831

29-
ProcessFile(inputFilename, outputFilename);
30-
DumpFile(outputFilename);
32+
ProcessFile(inputFilename, outputFilename, UseStdOut);
33+
DumpFile(outputFilename, UseStdOut);
3134

32-
if outputFilename <> 'CONSOLE' then
35+
if Not (UseStdOut) then
3336
begin
3437
WriteLn(Format('Total Elapsed: %s', [FormatDateTime('n" min, "s" sec"',
3538
Now - start)]));
@@ -42,7 +45,7 @@ begin
4245

4346
on E: Exception do
4447
begin
45-
if outputFilename <> 'CONSOLE' then
48+
if Not (UseStdOut) then
4649
begin
4750
WriteLn(E.ClassName, ': ', E.Message);
4851
WriteLn('Press ENTER to exit');

0 commit comments

Comments
 (0)