aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Anisimkov <anisimko@adacore.com>2019-12-12 10:01:41 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-12-12 10:01:41 +0000
commita1449c89b7272739d0ec32ad7ca4c53460337633 (patch)
tree5defd9ca4435649cdeebdd8cfdf67bf5d1dd3dd0
parentc38d4670d72427a12035a93cc3c6174f17825443 (diff)
downloadgcc-a1449c89b7272739d0ec32ad7ca4c53460337633.zip
gcc-a1449c89b7272739d0ec32ad7ca4c53460337633.tar.gz
gcc-a1449c89b7272739d0ec32ad7ca4c53460337633.tar.bz2
[Ada] Improve end of command line arguments detection
2019-12-12 Dmitriy Anisimkov <anisimko@adacore.com> gcc/ada/ * libgnat/g-comlin.ads (Get_Argument): New routine similar to original Get_Argument but with one more out parameter End_Of_Arguments. (Get_Arguments): Comment improved. * libgnat/g-comlin.adb (Get_Argument): Implementation taken from original Get_Argument and improved. (Get_Argument): Calls new routine Get_Argument with additional parameter. From-SVN: r279277
-rw-r--r--gcc/ada/ChangeLog11
-rw-r--r--gcc/ada/libgnat/g-comlin.adb29
-rw-r--r--gcc/ada/libgnat/g-comlin.ads15
3 files changed, 46 insertions, 9 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index e454613..8756dd7 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,14 @@
+2019-12-12 Dmitriy Anisimkov <anisimko@adacore.com>
+
+ * libgnat/g-comlin.ads (Get_Argument): New routine similar to
+ original Get_Argument but with one more out parameter
+ End_Of_Arguments.
+ (Get_Arguments): Comment improved.
+ * libgnat/g-comlin.adb (Get_Argument): Implementation taken from
+ original Get_Argument and improved.
+ (Get_Argument): Calls new routine Get_Argument with additional
+ parameter.
+
2019-12-03 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/utils.c (potential_alignment_gap): Delete.
diff --git a/gcc/ada/libgnat/g-comlin.adb b/gcc/ada/libgnat/g-comlin.adb
index e3fac5b..ec057a9 100644
--- a/gcc/ada/libgnat/g-comlin.adb
+++ b/gcc/ada/libgnat/g-comlin.adb
@@ -385,10 +385,25 @@ package body GNAT.Command_Line is
------------------
function Get_Argument
- (Do_Expansion : Boolean := False;
+ (Do_Expansion : Boolean := False;
Parser : Opt_Parser := Command_Line_Parser) return String
is
+ End_Of_Args : Boolean;
begin
+ return Get_Argument (Do_Expansion, Parser, End_Of_Args);
+ end Get_Argument;
+
+ ------------------
+ -- Get_Argument --
+ ------------------
+
+ function Get_Argument
+ (Do_Expansion : Boolean := False;
+ Parser : Opt_Parser := Command_Line_Parser;
+ End_Of_Arguments : out Boolean) return String is
+ begin
+ End_Of_Arguments := False;
+
if Parser.In_Expansion then
declare
S : constant String := Expansion (Parser.Expansion_It);
@@ -415,6 +430,7 @@ package body GNAT.Command_Line is
end loop;
else
+ End_Of_Arguments := True;
return String'(1 .. 0 => ' ');
end if;
@@ -436,9 +452,11 @@ package body GNAT.Command_Line is
end loop;
if Parser.Current_Argument > Parser.Arg_Count then
+ End_Of_Arguments := True;
return String'(1 .. 0 => ' ');
+
elsif Parser.Section (Parser.Current_Argument) = 0 then
- return Get_Argument (Do_Expansion);
+ return Get_Argument (Do_Expansion, Parser, End_Of_Arguments);
end if;
Parser.Current_Argument := Parser.Current_Argument + 1;
@@ -451,13 +469,10 @@ package body GNAT.Command_Line is
Argument (Parser, Parser.Current_Argument - 1);
begin
for Index in Arg'Range loop
- if Arg (Index) = '*'
- or else Arg (Index) = '?'
- or else Arg (Index) = '['
- then
+ if Arg (Index) in '*' | '?' | '[' then
Parser.In_Expansion := True;
Start_Expansion (Parser.Expansion_It, Arg);
- return Get_Argument (Do_Expansion, Parser);
+ return Get_Argument (Do_Expansion, Parser, End_Of_Arguments);
end if;
end loop;
end;
diff --git a/gcc/ada/libgnat/g-comlin.ads b/gcc/ada/libgnat/g-comlin.ads
index 188b035..34feee7 100644
--- a/gcc/ada/libgnat/g-comlin.ads
+++ b/gcc/ada/libgnat/g-comlin.ads
@@ -462,8 +462,9 @@ package GNAT.Command_Line is
function Get_Argument
(Do_Expansion : Boolean := False;
Parser : Opt_Parser := Command_Line_Parser) return String;
- -- Returns the next element on the command line that is not a switch. This
- -- function should not be called before Getopt has returned ASCII.NUL.
+ -- Returns the next element on the command line that is not a switch. This
+ -- function should be called either after Getopt has returned ASCII.NUL or
+ -- after Getopt procedure call.
--
-- If Do_Expansion is True, then the parameter on the command line will
-- be considered as a filename with wildcards, and will be expanded. The
@@ -472,6 +473,16 @@ package GNAT.Command_Line is
-- When there are no more arguments on the command line, this function
-- returns an empty string.
+ function Get_Argument
+ (Do_Expansion : Boolean := False;
+ Parser : Opt_Parser := Command_Line_Parser;
+ End_Of_Arguments : out Boolean) return String;
+ -- The same as above but able to distinguish empty element in argument list
+ -- from end of arguments.
+ -- End_Of_Arguments is True if the end of the command line has been reached
+ -- (i.e. all available arguments have been returned by previous calls to
+ -- Get_Argument).
+
function Parameter
(Parser : Opt_Parser := Command_Line_Parser) return String;
-- Returns parameter associated with the last switch returned by Getopt.