@@ -101,24 +101,12 @@ package body Gnatcheck.Options is
101101 (First_Pass : Boolean := False; Args : Argument_List_Access := null )
102102 is
103103 Unknown_Opt_Parse_Args : XString_Vector;
104- Args_After_Opt_Parse : Argument_List_Access ;
105- Parser : Opt_Parser ;
104+ Exp_It : Expansion_Iterator ;
105+ Explicit_Sources : String_Vector ;
106106
107- function To_Arg_List (Args : XString_Vector) return Argument_List_Access;
108107 function To_XString_Array
109108 (Args : Argument_List_Access) return XString_Array;
110109
111- function To_Arg_List (Args : XString_Vector) return Argument_List_Access
112- is
113- Ret : constant Argument_List_Access :=
114- new String_List (1 .. Args.Last_Index);
115- begin
116- for I in Ret'Range loop
117- Ret (I) := new String'(Args (I).To_String);
118- end loop ;
119- return Ret;
120- end To_Arg_List ;
121-
122110 function To_XString_Array
123111 (Args : Argument_List_Access) return XString_Array
124112 is
@@ -138,8 +126,6 @@ package body Gnatcheck.Options is
138126 Compose (Compose (Prefix, " share" ), " lkql" );
139127
140128 Args_From_Project : constant Boolean := Args /= null ;
141- Initial_Char : Character;
142- Success : Boolean;
143129
144130 -- Start of processing for Scan_Arguments
145131
@@ -183,14 +169,12 @@ package body Gnatcheck.Options is
183169 end ;
184170 end if ;
185171
186- if Arg.Parser.Parse
187- ((if Args /= null then To_XString_Array (Args) else No_Arguments),
188- Unknown_Arguments => Unknown_Opt_Parse_Args)
172+ if not Arg.Parser.Parse
173+ ((if Args /= null
174+ then To_XString_Array (Args)
175+ else No_Arguments),
176+ Unknown_Arguments => Unknown_Opt_Parse_Args)
189177 then
190- Args_After_Opt_Parse := To_Arg_List (Unknown_Opt_Parse_Args);
191- Initialize_Option_Scan
192- (Parser, Args_After_Opt_Parse, Section_Delimiters => " cargs rules" );
193- else
194178 raise Parameter_Error;
195179 end if ;
196180
@@ -213,54 +197,56 @@ package body Gnatcheck.Options is
213197 Allow (Arg.List_Rules.This);
214198 end if ;
215199
216- loop
217- Initial_Char := Getopt (" " , Parser => Parser);
218-
219- case Initial_Char is
220- when ASCII.NUL =>
221- Success := False;
222-
223- loop
224- declare
225- Arg : constant String :=
226- Get_Argument (Do_Expansion => True, Parser => Parser);
227-
228- begin
229- exit when Arg = " " ;
230- Success := True;
231-
232- if Options.Arg.Transitive_Closure.Get then
233- Store_Main_Unit (Arg, Args_From_Project or First_Pass);
234- else
235- Store_Sources_To_Process
236- (Arg, Args_From_Project or First_Pass);
237-
238- if not Args_From_Project then
239- Argument_File_Specified := True;
240- end if ;
241- end if ;
242- end ;
243- end loop ;
244-
245- exit when not Success;
246-
247- when others =>
248- Error
249- (" unrecognized switch: " & Full_Switch (Parser => Parser));
250- raise Parameter_Error;
251- end case ;
200+ -- Now that we processed all switches, remaining arguments should be
201+ -- source files to analyze.
202+ -- We first have to check that there is no additional argument and
203+ -- expand possible glob patterns.
204+ for Unknown_Arg of Unknown_Opt_Parse_Args loop
205+ -- We consider that arguments starting by "-" are remaining unknown
206+ -- arguments.
207+ if Unknown_Arg.Starts_With (" -" ) then
208+ Error (" unrecognized switch: " & To_String (Unknown_Arg));
209+ raise Parameter_Error;
210+
211+ -- We now know that the current argument should be handled like an
212+ -- Ada source file name OR a glob pattern.
213+ -- We only handle explicit sources during the first pass to avoid
214+ -- duplication.
215+ elsif Args_From_Project or First_Pass then
216+ declare
217+ Is_Glob : constant Boolean :=
218+ Unknown_Arg.Find (' *' ) /= 0
219+ or else Unknown_Arg.Find (' ?' ) /= 0
220+ or else Unknown_Arg.Find (' [' ) /= 0 ;
221+ begin
222+ if Is_Glob then
223+ Start_Expansion (Exp_It, To_String (Unknown_Arg));
224+ loop
225+ declare
226+ Expanded_Arg : constant String := Expansion (Exp_It);
227+ begin
228+ exit when Expanded_Arg = " " ;
229+ Explicit_Sources.Append (Expanded_Arg);
230+ end ;
231+ end loop ;
232+ else
233+ Explicit_Sources.Append (To_String (Unknown_Arg));
234+ end if ;
235+ end ;
236+ end if ;
252237 end loop ;
253238
254- exception
255- when Invalid_Switch =>
256- Error (" invalid switch: " & Full_Switch (Parser => Parser));
257- raise Parameter_Error;
258-
259- when Invalid_Parameter =>
260- Error
261- (" missing Parameter (Parser => Parser) for: -"
262- & Full_Switch (Parser => Parser));
263- raise Parameter_Error;
239+ -- We can now store sources to process
240+ for Arg of Explicit_Sources loop
241+ if Options.Arg.Transitive_Closure.Get then
242+ Store_Main_Unit (Arg);
243+ else
244+ Store_Sources_To_Process (Arg);
245+ if not Args_From_Project then
246+ Argument_File_Specified := True;
247+ end if ;
248+ end if ;
249+ end loop ;
264250 end Scan_Arguments ;
265251
266252 -- -------------------------------
0 commit comments