99 Classes
1010, SysUtils
1111, CustApp
12+ , Generate.Console
1213, Generate.Common
1314;
1415
1516const
1617 cVersion = { $I version.inc} ;
1718
18- cShortOptHelp: Char = ' h' ;
19- cLongOptHelp = ' help' ;
20- cShortOptVersion: Char = ' v' ;
21- cLongOptVersion = ' version' ;
22- cShortOptInput: Char = ' i' ;
23- cLongOptInput = ' input-file' ;
24- cShortOptOutput: Char = ' o' ;
25- cLongOptOutput = ' output-file' ;
26- cShortOptNumner: Char = ' n' ;
27- cLongOptNumber = ' line-count' ;
28-
29- var
30- inputFilename: String = ' ' ;
31- outputFilename: String = ' ' ;
32- lineCount: Int64 = 0 ;
33-
3419type
3520
3621 { TOneBRCGenerator }
@@ -43,7 +28,6 @@ TOneBRCGenerator = class(TCustomApplication)
4328 public
4429 constructor Create(TheOwner: TComponent); override;
4530 destructor Destroy; override;
46- procedure WriteHelp ; virtual ;
4731 published
4832 end ;
4933
@@ -73,7 +57,7 @@ procedure TOneBRCGenerator.DoRun;
7357 if ErrorMsg<>' ' then
7458 begin
7559 // ShowException(Exception.Create(ErrorMsg));
76- WriteLn(' ERROR: ' , ErrorMsg);
60+ WriteLn(Format(rsErrorMessage, [ ErrorMsg ]) );
7761 Terminate;
7862 Exit;
7963 end ;
@@ -88,7 +72,7 @@ procedure TOneBRCGenerator.DoRun;
8872
8973 if HasOption(cShortOptVersion, cLongOptVersion) then
9074 begin
91- WriteLn(' generator v ' , cVersion);
75+ WriteLn(Format(rsGeneratorVersion, [ cVersion ]) );
9276 Terminate;
9377 Exit;
9478 end ;
@@ -102,7 +86,7 @@ procedure TOneBRCGenerator.DoRun;
10286 end
10387 else
10488 begin
105- WriteLn(' ERROR: Missing input file flag ' );
89+ WriteLn(Format(rsErrorMessage, [ rsMissingInputFlag ]) );
10690 Terminate;
10791 Exit;
10892 end ;
@@ -116,7 +100,7 @@ procedure TOneBRCGenerator.DoRun;
116100 end
117101 else
118102 begin
119- WriteLn(' ERROR: Missing output file flag ' );
103+ WriteLn(Format(rsErrorMessage, [ rsMissingOutputFlag ]) );
120104 Terminate;
121105 Exit;
122106 end ;
@@ -130,30 +114,30 @@ procedure TOneBRCGenerator.DoRun;
130114 tmpLineCount:= StringReplace(tmpLineCount, ' _' , ' ' , [rfReplaceAll]);
131115 if not TryStrToInt64(tmpLineCount, lineCount) then
132116 begin
133- WriteLn(' ERROR: Invalid integer " ' , tmpLineCount, ' " ' );
117+ WriteLn(Format(rsInvalidInteger, [ tmpLineCount ]) );
134118 Terminate;
135119 Exit;
136120 end ;
137121 if not (lineCount > 0 ) then
138122 begin
139- WriteLn(' ERROR: Number of lines should be a positive number, greater than 0. ' );
123+ WriteLn(Format(rsErrorMessage, [ rsInvalidLineNumber ]) );
140124 Terminate;
141125 Exit;
142126 end ;
143127 end
144128 else
145129 begin
146- WriteLn(' ERROR: Missing line count flag ' );
130+ WriteLn(Format(rsErrorMessage, [ rsMissingLineCountFlag ]) );
147131 Terminate;
148132 Exit;
149133 end ;
150134
151135 inputFilename:= ExpandFileName(inputFilename);
152136 outputFilename:= ExpandFileName(outputFilename);
153137
154- WriteLn(' Input File : ' , inputFilename);
155- WriteLn(' Output File: ' , outputFilename);
156- WriteLn(' Line Count : ' , Format(' %.0n ' , [ Double(lineCount) ]));
138+ WriteLn(Format(rsInputFile, [ inputFilename ]) );
139+ WriteLn(Format(rsOutputFile, [ outputFilename ]) );
140+ WriteLn(Format(rsLineCount , [ Double(lineCount) ]));
157141 WriteLn;
158142
159143 FGenerator:= TGenerator.Create(inputFilename, outputFilename, lineCount);
@@ -163,7 +147,7 @@ procedure TOneBRCGenerator.DoRun;
163147 except
164148 on E: Exception do
165149 begin
166- WriteLn(' ERROR: ' , E.Message);
150+ WriteLn(Format(rsErrorMessage, [ E.Message ]) );
167151 end ;
168152 end ;
169153 finally
@@ -185,27 +169,11 @@ destructor TOneBRCGenerator.Destroy;
185169 inherited Destroy;
186170end ;
187171
188- procedure TOneBRCGenerator.WriteHelp ;
189- begin
190- { add your help code here }
191- WriteLn(' Generates the measurement file with the specified number of lines' );
192- WriteLn;
193- WriteLn(' USAGE' );
194- WriteLn(' generator <flags>' );
195- WriteLn;
196- WriteLn(' FLAGS' );
197- WriteLn(' -h|--help Writes this help message and exits' );
198- WriteLn(' -v|--version Writes the version and exits' );
199- WriteLn(' -i|--input-file <filename> The file containing the Weather Stations' );
200- WriteLn(' -o|--output-file <filename> The file that will contain the generated lines' );
201- WriteLn(' -n|--line-count <number> The amount of lines to be generated' );
202- end ;
203-
204172var
205173 Application: TOneBRCGenerator;
206174begin
207175 Application:=TOneBRCGenerator.Create(nil );
208- Application.Title:=' One Billion Row Challenge Generator ' ;
176+ Application.Title:= rsAppTitle ;
209177 Application.Run;
210178 Application.Free;
211179end .
0 commit comments