@@ -69,8 +69,7 @@ function TOneBRCGenerator.ParseConsoleParams: boolean;
6969var
7070 I, J, invalid, valid: Integer;
7171 tmpLineCount: String;
72- paramflag: boolean;
73- templist: TStringList;
72+ ParamOK: Boolean;
7473begin
7574 Result := false;
7675 // initialize the params list
@@ -98,121 +97,125 @@ begin
9897 // parsing
9998 // ************************************
10099 // check for invalid input
101- templist := TStringList.Create;
102- try
103- templist.Text := FParams.Text;
104- if templist.Count > 0 then
100+ if FParams.Count > 0 then
101+ begin
102+ for I := 0 to FParams.Count - 1 do
105103 begin
106- for I := 0 to pred(Length(cShortOptions)) do
104+ ParamOK := False;
105+ for J := 0 to Pred(Length(cShortOptions)) do
107106 begin
108- J := templist.IndexOfName(cShortOptions[I]);
109- if J > -1 then
110- templist.Delete(J);
107+ if (FParams[I] = cShortOptions[J]) then
108+ begin
109+ ParamOK := True;
110+ Break;
111+ end ;
111112 end ;
112113
113- for I := 0 to pred(Length(cLongOptions)) do
114- begin
115- J := templist.IndexOfName(cLongOptions[I]);
116- if J > -1 then
117- templist.Delete(J);
118- end ;
114+ if not ParamOK then
115+ for J := 0 to Pred(Length(cLongOptions)) do
116+ begin
117+ if (FParams[I] = cLongOptions[J]) then
118+ begin
119+ ParamOK := True;
120+ Break;
121+ end ;
122+ end ;
119123
120- if templist.Count > 0 then
121- begin
122- WriteLn(Format(rsErrorMessage, [templist.Text]));
123- Result := false;
124- exit;
125- end ;
124+ if not ParamOK then
125+ Break;
126+ end ;
126127
127- end
128- else
128+ if not ParamOK then
129129 begin
130+ WriteLn(Format(rsErrorMessage, [FParams.Text]));
130131 Result := false;
131132 exit;
132133 end ;
134+ end
135+ else
136+ begin
137+ Result := false;
138+ exit;
139+ end ;
133140
134- // ************************************
135- // check for valid inputs
136- // check help
137- if (FParams.Find(cShortOptHelp, J) or FParams.Find(cLongOptHelp, J)) then
138- begin
139- WriteHelp;
140- inc(invalid);
141- end ;
141+ // ************************************
142+ // check for valid inputs
143+ // check help
144+ if (FParams.Find(cShortOptHelp, J) or FParams.Find(cLongOptHelp, J)) then
145+ begin
146+ WriteHelp;
147+ inc(invalid);
148+ end ;
142149
143- // check version
144- if (FParams.Find(cShortOptVersion, J) or FParams.Find(cLongOptVersion, J)) then
145- begin
146- WriteLn(Format(rsGeneratorVersion, [cVersion]));
147- inc(invalid);
148- end ;
150+ // check version
151+ if (FParams.Find(cShortOptVersion, J) or FParams.Find(cLongOptVersion, J)) then
152+ begin
153+ WriteLn(Format(rsGeneratorVersion, [cVersion]));
154+ inc(invalid);
155+ end ;
149156
150- // check inputfilename
151- J := -1 ;
152- J := FParams.IndexOfName(cShortOptInput);
153- if J = -1 then
154- J := FParams.IndexOfName(cLongOptInput);
155- if J = -1 then
156- begin
157- WriteLn(Format(rsErrorMessage, [rsMissingInputFlag]));
158- inc(invalid);
159- end
160- else
161- begin
162- inputFilename := FParams.ValueFromIndex[J];
163- inc(valid);
164- end ;
157+ // check inputfilename
158+ J := -1 ;
159+ J := FParams.IndexOfName(cShortOptInput);
160+ if J = -1 then
161+ J := FParams.IndexOfName(cLongOptInput);
162+ if J = -1 then
163+ begin
164+ WriteLn(Format(rsErrorMessage, [rsMissingInputFlag]));
165+ inc(invalid);
166+ end
167+ else
168+ begin
169+ inputFilename := FParams.ValueFromIndex[J];
170+ inc(valid);
171+ end ;
172+
173+ // check outputfilename
174+ J := -1 ;
175+ J := FParams.IndexOfName(cShortOptOutput);
176+ if J = -1 then
177+ J := FParams.IndexOfName(cLongOptOutput);
178+ if J = -1 then
179+ begin
180+ WriteLn(Format(rsErrorMessage, [rsMissingOutputFlag]));
181+ inc(invalid);
182+ end
183+ else
184+ begin
185+ outputFilename := FParams.ValueFromIndex[J];
186+ inc(valid);
187+ end ;
188+
189+ // check linecount
190+ J := -1 ;
191+ J := FParams.IndexOfName(cShortOptNumber);
192+ if J = -1 then
193+ J := FParams.IndexOfName(cLongOptNumber);
194+ if J = -1 then
195+ begin
196+ WriteLn(Format(rsErrorMessage, [rsMissingLineCountFlag]));
197+ inc(invalid);
198+ end
199+ else
200+ begin
201+ tmpLineCount := FParams.ValueFromIndex[J].Replace(' _' , ' ' , [rfReplaceAll]);
165202
166- // check outputfilename
167- J := -1 ;
168- J := FParams.IndexOfName(cShortOptOutput);
169- if J = -1 then
170- J := FParams.IndexOfName(cLongOptOutput);
171- if J = -1 then
203+ if not TryStrToInt(tmpLineCount, lineCount) then
172204 begin
173- WriteLn(Format(rsErrorMessage , [rsMissingOutputFlag ]));
205+ WriteLn(Format(rsInvalidInteger , [tmpLineCount ]));
174206 inc(invalid);
175- end
176- else
177- begin
178- outputFilename := FParams.ValueFromIndex[J];
179- inc(valid);
180207 end ;
181208
182- // check linecount
183- J := -1 ;
184- J := FParams.IndexOfName(cShortOptNumber);
185- if J = -1 then
186- J := FParams.IndexOfName(cLongOptNumber);
187- if J = -1 then
209+ if not (lineCount > 0 ) then
188210 begin
189- WriteLn(Format(rsErrorMessage, [rsMissingLineCountFlag ]));
211+ WriteLn(Format(rsErrorMessage, [rsInvalidLineNumber ]));
190212 inc(invalid);
191- end
192- else
193- begin
194- tmpLineCount := FParams.ValueFromIndex[J].Replace(' _' , ' ' , [rfReplaceAll]);
195-
196- if not TryStrToInt(tmpLineCount, lineCount) then
197- begin
198- WriteLn(Format(rsInvalidInteger, [tmpLineCount]));
199- inc(invalid);
200- end ;
201-
202- if not (lineCount > 0 ) then
203- begin
204- WriteLn(Format(rsErrorMessage, [rsInvalidLineNumber]));
205- inc(invalid);
206- end ;
207- inc(valid);
208213 end ;
209-
210- // check if everything was provided
211- Result := valid = 3 ;
212- finally
213- templist.Free;
214+ inc(valid);
214215 end ;
215216
217+ // check if everything was provided
218+ Result := valid = 3 ;
216219end ;
217220
218221var
0 commit comments