Commit 1bae4562 by Robert Dewar Committed by Arnaud Charlet

g-comlin.adb: Minor code reorganization Minor reformatting

2008-08-08  Robert Dewar  <dewar@adacore.com>

	* g-comlin.adb: Minor code reorganization
	Minor reformatting

From-SVN: r138866
parent 0f336c35
...@@ -1143,6 +1143,7 @@ package body GNAT.Command_Line is ...@@ -1143,6 +1143,7 @@ package body GNAT.Command_Line is
is is
Ret : Ada.Strings.Unbounded.Unbounded_String; Ret : Ada.Strings.Unbounded.Unbounded_String;
use type Ada.Strings.Unbounded.Unbounded_String; use type Ada.Strings.Unbounded.Unbounded_String;
begin begin
if Config = null or else Config.Switches = null then if Config = null or else Config.Switches = null then
return ""; return "";
...@@ -1150,9 +1151,10 @@ package body GNAT.Command_Line is ...@@ -1150,9 +1151,10 @@ package body GNAT.Command_Line is
for J in Config.Switches'Range loop for J in Config.Switches'Range loop
if Config.Switches (J) (Config.Switches (J)'First) = Switch_Char then if Config.Switches (J) (Config.Switches (J)'First) = Switch_Char then
Ret := Ret & " " & Ret :=
Config.Switches (J) Ret & " " &
(Config.Switches (J)'First + 1 .. Config.Switches (J)'Last); Config.Switches (J)
(Config.Switches (J)'First + 1 .. Config.Switches (J)'Last);
else else
Ret := Ret & " " & Config.Switches (J).all; Ret := Ret & " " & Config.Switches (J).all;
end if; end if;
...@@ -1259,13 +1261,16 @@ package body GNAT.Command_Line is ...@@ -1259,13 +1261,16 @@ package body GNAT.Command_Line is
if not Is_Section then if not Is_Section then
if Section = null then if Section = null then
-- Workaround some weird cases: some switches may -- Workaround some weird cases: some switches may
-- expect parameters, but have the same value as -- expect parameters, but have the same value as
-- longer switches: -gnaty3 (-gnaty, parameter=3) and -- longer switches: -gnaty3 (-gnaty, parameter=3) and
-- -gnatya (-gnatya, no parameter). -- -gnatya (-gnatya, no parameter).
-- So we are calling add_switch here with parameter -- So we are calling add_switch here with parameter
-- attached. This will be anyway correctly handled by -- attached. This will be anyway correctly handled by
-- Add_Switch if -gnaty3 is actually furnished. -- Add_Switch if -gnaty3 is actually furnished.
if Separator (Parser) = ASCII.NUL then if Separator (Parser) = ASCII.NUL then
Add_Switch Add_Switch
(Cmd, Sw & Parameter (Parser), ""); (Cmd, Sw & Parameter (Parser), "");
...@@ -1295,6 +1300,7 @@ package body GNAT.Command_Line is ...@@ -1295,6 +1300,7 @@ package body GNAT.Command_Line is
-- Add it with no parameter, if that's the way the user -- Add it with no parameter, if that's the way the user
-- wants it. -- wants it.
-- Specify the separator in all cases, as the switch might -- Specify the separator in all cases, as the switch might
-- need to be unaliased, and the alias might contain -- need to be unaliased, and the alias might contain
-- switches with parameters. -- switches with parameters.
...@@ -1406,9 +1412,11 @@ package body GNAT.Command_Line is ...@@ -1406,9 +1412,11 @@ package body GNAT.Command_Line is
(Prefix : String; (Prefix : String;
Group : String) return Boolean Group : String) return Boolean
is is
Idx : Natural := Group'First; Idx : Natural;
Found : Boolean; Found : Boolean;
begin begin
Idx := Group'First;
while Idx <= Group'Last loop while Idx <= Group'Last loop
Found := False; Found := False;
...@@ -1424,17 +1432,23 @@ package body GNAT.Command_Line is ...@@ -1424,17 +1432,23 @@ package body GNAT.Command_Line is
begin begin
if Sw'Length >= Prefix'Length if Sw'Length >= Prefix'Length
-- Verify that sw starts with Prefix
and then Looking_At (Sw, Sw'First, Prefix) -- Verify that sw starts with Prefix
-- Verify that the group starts with sw
and then Looking_At (Full, Full'First, Sw) and then Looking_At (Sw, Sw'First, Prefix)
-- Verify that the group starts with sw
and then Looking_At (Full, Full'First, Sw)
then then
Last := Idx + Sw'Length - Prefix'Length - 1; Last := Idx + Sw'Length - Prefix'Length - 1;
Param := Last + 1; Param := Last + 1;
if Can_Have_Parameter (Cmd.Config.Switches (S).all) then if Can_Have_Parameter (Cmd.Config.Switches (S).all) then
-- Include potential parameter to the recursive call. -- Include potential parameter to the recursive call.
-- Only numbers are allowed. -- Only numbers are allowed.
while Last < Group'Last while Last < Group'Last
and then Group (Last + 1) in '0' .. '9' and then Group (Last + 1) in '0' .. '9'
loop loop
...@@ -1456,12 +1470,14 @@ package body GNAT.Command_Line is ...@@ -1456,12 +1470,14 @@ package body GNAT.Command_Line is
-- a parameter is detected in the switch, as this -- a parameter is detected in the switch, as this
-- is a way to correctly identify such a parameter -- is a way to correctly identify such a parameter
-- in aliases. -- in aliases.
return False; return False;
end if; end if;
Found := True; Found := True;
-- Recursive call, using the detected parameter if any -- Recursive call, using the detected parameter if any
if Last >= Param then if Last >= Param then
For_Each_Simple_Switch For_Each_Simple_Switch
(Cmd, (Cmd,
...@@ -1871,16 +1887,19 @@ package body GNAT.Command_Line is ...@@ -1871,16 +1887,19 @@ package body GNAT.Command_Line is
function Compatible_Parameter (Param : String_Access) return Boolean is function Compatible_Parameter (Param : String_Access) return Boolean is
begin begin
-- No parameter OK
if Param = null then if Param = null then
-- No parameter, OK
return True; return True;
-- We need parameters without separators
elsif Param (Param'First) /= ASCII.NUL then elsif Param (Param'First) /= ASCII.NUL then
-- We need parameters without separators...
return False; return False;
-- Parameters must be all digits
else else
-- We need number only parameters.
for J in Param'First + 1 .. Param'Last loop for J in Param'First + 1 .. Param'Last loop
if Param (J) not in '0' .. '9' then if Param (J) not in '0' .. '9' then
return False; return False;
...@@ -1889,13 +1908,16 @@ package body GNAT.Command_Line is ...@@ -1889,13 +1908,16 @@ package body GNAT.Command_Line is
return True; return True;
end if; end if;
end Compatible_Parameter; end Compatible_Parameter;
Group : Ada.Strings.Unbounded.Unbounded_String; -- Local declarations
First : Natural;
Group : Ada.Strings.Unbounded.Unbounded_String;
First : Natural;
use type Ada.Strings.Unbounded.Unbounded_String; use type Ada.Strings.Unbounded.Unbounded_String;
-- Start of processing for Group_Switches
begin begin
if Cmd.Config = null if Cmd.Config = null
or else Cmd.Config.Prefixes = null or else Cmd.Config.Prefixes = null
...@@ -1914,24 +1936,26 @@ package body GNAT.Command_Line is ...@@ -1914,24 +1936,26 @@ package body GNAT.Command_Line is
(Result (C).all, Result (C)'First, Cmd.Config.Prefixes (P).all) (Result (C).all, Result (C)'First, Cmd.Config.Prefixes (P).all)
then then
-- If we are still in the same section, group the switches -- If we are still in the same section, group the switches
if First = 0 if First = 0
or else or else
(Sections (C) = null (Sections (C) = null
and then Sections (First) = null) and then Sections (First) = null)
or else or else
(Sections (C) /= null (Sections (C) /= null
and then Sections (First) /= null and then Sections (First) /= null
and then Sections (C).all = Sections (First).all) and then Sections (C).all = Sections (First).all)
then then
Group := Group :=
Group & Group &
Result (C) Result (C)
(Result (C)'First + Cmd.Config.Prefixes (P)'Length .. (Result (C)'First + Cmd.Config.Prefixes (P)'Length ..
Result (C)'Last); Result (C)'Last);
if Params (C) /= null then if Params (C) /= null then
Group := Group & Group :=
Params (C) (Params (C)'First + 1 .. Params (C)'Last); Group &
Params (C) (Params (C)'First + 1 .. Params (C)'Last);
Free (Params (C)); Free (Params (C));
end if; end if;
...@@ -1940,9 +1964,11 @@ package body GNAT.Command_Line is ...@@ -1940,9 +1964,11 @@ package body GNAT.Command_Line is
end if; end if;
Free (Result (C)); Free (Result (C));
else else
-- We changed section: we put the grouped switches to the -- We changed section: we put the grouped switches to the
-- first place, on continue with the new section. -- first place, on continue with the new section.
Result (First) := Result (First) :=
new String' new String'
(Cmd.Config.Prefixes (P).all & (Cmd.Config.Prefixes (P).all &
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment