9
9
Classes
10
10
, SysUtils
11
11
, CustApp
12
+ , Generate.Console
12
13
, Generate.Common
13
14
;
14
15
15
16
const
16
17
cVersion = { $I version.inc} ;
17
18
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
-
34
19
type
35
20
36
21
{ TOneBRCGenerator }
@@ -43,7 +28,6 @@ TOneBRCGenerator = class(TCustomApplication)
43
28
public
44
29
constructor Create(TheOwner: TComponent); override;
45
30
destructor Destroy; override;
46
- procedure WriteHelp ; virtual ;
47
31
published
48
32
end ;
49
33
@@ -73,7 +57,7 @@ procedure TOneBRCGenerator.DoRun;
73
57
if ErrorMsg<>' ' then
74
58
begin
75
59
// ShowException(Exception.Create(ErrorMsg));
76
- WriteLn(' ERROR: ' , ErrorMsg);
60
+ WriteLn(Format(rsErrorMessage, [ ErrorMsg ]) );
77
61
Terminate;
78
62
Exit;
79
63
end ;
@@ -88,7 +72,7 @@ procedure TOneBRCGenerator.DoRun;
88
72
89
73
if HasOption(cShortOptVersion, cLongOptVersion) then
90
74
begin
91
- WriteLn(' generator v ' , cVersion);
75
+ WriteLn(Format(rsGeneratorVersion, [ cVersion ]) );
92
76
Terminate;
93
77
Exit;
94
78
end ;
@@ -102,7 +86,7 @@ procedure TOneBRCGenerator.DoRun;
102
86
end
103
87
else
104
88
begin
105
- WriteLn(' ERROR: Missing input file flag ' );
89
+ WriteLn(Format(rsErrorMessage, [ rsMissingInputFlag ]) );
106
90
Terminate;
107
91
Exit;
108
92
end ;
@@ -116,7 +100,7 @@ procedure TOneBRCGenerator.DoRun;
116
100
end
117
101
else
118
102
begin
119
- WriteLn(' ERROR: Missing output file flag ' );
103
+ WriteLn(Format(rsErrorMessage, [ rsMissingOutputFlag ]) );
120
104
Terminate;
121
105
Exit;
122
106
end ;
@@ -130,30 +114,30 @@ procedure TOneBRCGenerator.DoRun;
130
114
tmpLineCount:= StringReplace(tmpLineCount, ' _' , ' ' , [rfReplaceAll]);
131
115
if not TryStrToInt64(tmpLineCount, lineCount) then
132
116
begin
133
- WriteLn(' ERROR: Invalid integer " ' , tmpLineCount, ' " ' );
117
+ WriteLn(Format(rsInvalidInteger, [ tmpLineCount ]) );
134
118
Terminate;
135
119
Exit;
136
120
end ;
137
121
if not (lineCount > 0 ) then
138
122
begin
139
- WriteLn(' ERROR: Number of lines should be a positive number, greater than 0. ' );
123
+ WriteLn(Format(rsErrorMessage, [ rsInvalidLineNumber ]) );
140
124
Terminate;
141
125
Exit;
142
126
end ;
143
127
end
144
128
else
145
129
begin
146
- WriteLn(' ERROR: Missing line count flag ' );
130
+ WriteLn(Format(rsErrorMessage, [ rsMissingLineCountFlag ]) );
147
131
Terminate;
148
132
Exit;
149
133
end ;
150
134
151
135
inputFilename:= ExpandFileName(inputFilename);
152
136
outputFilename:= ExpandFileName(outputFilename);
153
137
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) ]));
157
141
WriteLn;
158
142
159
143
FGenerator:= TGenerator.Create(inputFilename, outputFilename, lineCount);
@@ -163,7 +147,7 @@ procedure TOneBRCGenerator.DoRun;
163
147
except
164
148
on E: Exception do
165
149
begin
166
- WriteLn(' ERROR: ' , E.Message);
150
+ WriteLn(Format(rsErrorMessage, [ E.Message ]) );
167
151
end ;
168
152
end ;
169
153
finally
@@ -185,27 +169,11 @@ destructor TOneBRCGenerator.Destroy;
185
169
inherited Destroy;
186
170
end ;
187
171
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
-
204
172
var
205
173
Application: TOneBRCGenerator;
206
174
begin
207
175
Application:=TOneBRCGenerator.Create(nil );
208
- Application.Title:=' One Billion Row Challenge Generator ' ;
176
+ Application.Title:= rsAppTitle ;
209
177
Application.Run;
210
178
Application.Free;
211
179
end .
0 commit comments