This patches fixes the use of custom parsers when trying to expand command line arguments like "*.adb".
When run from the test directory, the following program should output "next source >>> test_cmd_line1.adb". with Ada.Text_IO; use Ada.Text_IO; with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.OS_Lib; use GNAT.OS_Lib; procedure Test_Cmd_Line1 is Arg_Parser : Opt_Parser := Command_Line_Parser; Switches : String_List_Access := new String_List'(1 => new String'("*.adb")); begin Initialize_Option_Scan (Parser => Arg_Parser, Command_Line => Switches, Stop_At_First_Non_Switch => True, Section_Delimiters => "cargs"); Parse_Params : loop case GNAT.Command_Line.Getopt ("", Parser => Arg_Parser) is when ASCII.NUL => loop Put_Line ("next source >>>" & Get_Argument (Do_Expansion => True, Parser => Arg_Parser)); exit Parse_Params when Next_Source.all = ""; end loop; when others => Put_Line (Full_Switch (Arg_Parser)); end case; end loop Parse_Params; end Test_Cmd_Line1; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-06-13 Emmanuel Briot <br...@adacore.com> * g-comlin.adb (Get_Argument): fix expansion of command line arguments (e.g. "*.adb") when using a custom parser. The parser was not passed to the recursive call, and thus we were trying to do the expansion on the default command line parser.
Index: g-comlin.adb =================================================================== --- g-comlin.adb (revision 211615) +++ g-comlin.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1999-2013, Free Software Foundation, Inc. -- +-- Copyright (C) 1999-2014, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -402,7 +402,6 @@ end if; if Parser.Current_Argument > Parser.Arg_Count then - -- If this is the first time this function is called if Parser.Current_Index = 1 then @@ -449,21 +448,16 @@ declare Arg : constant String := Argument (Parser, Parser.Current_Argument - 1); - Index : Positive; - begin - Index := Arg'First; - while Index <= Arg'Last loop + for Index in Arg'Range loop if Arg (Index) = '*' or else Arg (Index) = '?' or else Arg (Index) = '[' then Parser.In_Expansion := True; Start_Expansion (Parser.Expansion_It, Arg); - return Get_Argument (Do_Expansion); + return Get_Argument (Do_Expansion, Parser); end if; - - Index := Index + 1; end loop; end; end if;