-- --
------------------------------------------------------------------------------
-with Ada.Characters.Handling; use Ada.Characters.Handling;
+with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings.Unbounded;
-with Ada.Text_IO; use Ada.Text_IO;
+with Ada.Text_IO; use Ada.Text_IO;
with Ada.Unchecked_Deallocation;
+
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.OS_Lib; use GNAT.OS_Lib;
-- Add a new element to Line. If Before is True, the item is inserted at
-- the beginning, else it is appended.
- procedure Add (Config : in out Command_Line_Configuration;
- Switch : Switch_Definition);
- procedure Add (Def : in out Alias_Definitions_List;
- Alias : Alias_Definition);
+ procedure Add
+ (Config : in out Command_Line_Configuration;
+ Switch : Switch_Definition);
+ procedure Add
+ (Def : in out Alias_Definitions_List;
+ Alias : Alias_Definition);
-- Add a new element to Def.
procedure Initialize_Switch_Def
if Current = 1 then
return String'(1 .. 0 => ' ');
- else
- -- Otherwise continue with the directory at the previous level
+ -- Otherwise continue with the directory at the previous level
+
+ else
Current := Current - 1;
It.Current_Depth := Current;
end if;
elsif Is_Directory
(It.Dir_Name (1 .. It.Levels (Current).Name_Last) & S (1 .. Last))
- and then S (1 .. Last) /= "."
- and then S (1 .. Last) /= ".."
+ and then S (1 .. Last) /= "."
+ and then S (1 .. Last) /= ".."
then
-- We can go to the next level only if we have not reached the
-- maximum depth,
---------------------
function Current_Section
- (Parser : Opt_Parser := Command_Line_Parser) return String is
+ (Parser : Opt_Parser := Command_Line_Parser) return String
+ is
begin
if Parser.Current_Section = 1 then
return "";
Parser.Current_Argument := 1;
while Parser.Current_Argument <= Parser.Arg_Count
and then Parser.Section (Parser.Current_Argument) /=
- Parser.Current_Section
+ Parser.Current_Section
loop
Parser.Current_Argument := Parser.Current_Argument + 1;
end loop;
elsif Parser.Section (Parser.Current_Argument) = 0 then
while Parser.Current_Argument <= Parser.Arg_Count
and then Parser.Section (Parser.Current_Argument) /=
- Parser.Current_Section
+ Parser.Current_Section
loop
Parser.Current_Argument := Parser.Current_Argument + 1;
end loop;
Switch_Last : out Integer)
is
begin
+ if Switch = "" then
+ Parameter_Type := Parameter_None;
+ Switch_Last := Switch'Last;
+ return;
+ end if;
+
case Switch (Switch'Last) is
when ':' =>
Parameter_Type := Parameter_With_Optional_Space;
(Parser.The_Switch,
Arg_Num => Parser.Current_Argument,
First => Parser.Current_Index,
- Last => Arg'Last);
+ Last => End_Index);
Parser.Current_Index := End_Index + 1;
raise Invalid_Switch;
-- If the switch is of the form <switch>=xxx
if End_Index < Arg'Last then
-
if Arg (End_Index + 1) = '='
and then End_Index + 1 < Arg'Last
then
end if;
when Parameter_No_Space =>
-
if End_Index < Arg'Last then
Set_Parameter
(Parser.The_Parameter,
end if;
when Parameter_Optional =>
-
if End_Index < Arg'Last then
Set_Parameter
(Parser.The_Parameter,
Dummy := Goto_Next_Argument_In_Section (Parser);
when Parameter_None =>
-
if Concatenate or else End_Index = Arg'Last then
Parser.Current_Index := End_Index + 1;
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
(Switch_Definitions, Switch_Definitions_List);
Tmp : Switch_Definitions_List;
+
begin
if Config = null then
Config := new Command_Line_Configuration_Record;
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
(Alias_Definitions, Alias_Definitions_List);
Tmp : Alias_Definitions_List := Def;
+
begin
if Tmp = null then
Def := new Alias_Definitions (1 .. 1);
Help : String := "";
Section : String := "")
is
- P1, P2 : Switch_Parameter_Type := Parameter_None;
+ P1, P2 : Switch_Parameter_Type := Parameter_None;
Last1, Last2 : Integer;
+
begin
if Switch /= "" then
Def.Switch := new String'(Switch);
Help : String := "";
Section : String := "")
is
- Def : Switch_Definition;
+ Def : Switch_Definition;
begin
if Switch /= "" or else Long_Switch /= "" then
Initialize_Switch_Def (Def, Switch, Long_Switch, Help, Section);
function Get_Switches
(Config : Command_Line_Configuration;
- Section : String := "";
- Switch_Char : Character := '-') return String
+ Switch_Char : Character := '-';
+ Section : String := "") return String
is
Ret : Ada.Strings.Unbounded.Unbounded_String;
use Ada.Strings.Unbounded;
function Add_Switch (S : String; Index : Integer) return Boolean;
-- Add a switch to Ret
+ ----------------
+ -- Add_Switch --
+ ----------------
+
function Add_Switch (S : String; Index : Integer) return Boolean is
pragma Unreferenced (Index);
begin
Tmp : Boolean;
pragma Unreferenced (Tmp);
+
+ -- Start of processing for Get_Switches
+
begin
Foreach_Switch (Config, Add_Switch'Access, Section => Section);
-- Adding relevant aliases
+
if Config.Aliases /= null then
for A in Config.Aliases'Range loop
if Config.Aliases (A).Section.all = Section then
------------------------
function Section_Delimiters
- (Config : Command_Line_Configuration) return String
+ (Config : Command_Line_Configuration) return String
is
use Ada.Strings.Unbounded;
Result : Unbounded_String;
+
begin
if Config /= null and then Config.Sections /= null then
for S in Config.Sections'Range loop
-----------------------
function Get_Configuration
- (Cmd : Command_Line) return Command_Line_Configuration is
+ (Cmd : Command_Line) return Command_Line_Configuration
+ is
begin
return Cmd.Config;
end Get_Configuration;
if not Is_Section then
if Section = null then
-
- -- Work around some weird cases: some switches may
- -- expect parameters, but have the same value as
- -- longer switches: -gnaty3 (-gnaty, parameter=3) and
- -- -gnatya (-gnatya, no parameter).
-
- -- So we are calling add_switch here with parameter
- -- attached. This will be anyway correctly handled by
- -- Add_Switch if -gnaty3 is actually provided.
-
- if Separator (Parser) = ASCII.NUL then
- Add_Switch (Cmd, Sw & Parameter (Parser), "");
- else
- Add_Switch (Cmd, Sw, Parameter (Parser));
- end if;
+ Add_Switch (Cmd, Sw, Parameter (Parser));
else
- if Separator (Parser) = ASCII.NUL then
- Add_Switch
- (Cmd, Sw & Parameter (Parser), "", Section.all);
- else
- Add_Switch
- (Cmd, Sw, Parameter (Parser), Section.all);
- end if;
+ Add_Switch
+ (Cmd, Sw, Parameter (Parser), Section.all);
end if;
end if;
end;
function Looking_At
(Type_Str : String;
Index : Natural;
- Substring : String) return Boolean is
+ Substring : String) return Boolean
+ is
begin
return Index + Substring'Length - 1 <= Type_Str'Last
and then Type_Str (Index .. Index + Substring'Length - 1) = Substring;
function Analyze_Simple_Switch
(Switch : String; Index : Integer) return Boolean;
+ ---------------------------
+ -- Analyze_Simple_Switch --
+ ---------------------------
+
function Analyze_Simple_Switch
(Switch : String; Index : Integer) return Boolean
is
return True;
end Analyze_Simple_Switch;
+ -- Start of processing for Group_Analysis
+
begin
Idx := Group'First;
while Idx <= Group'Last loop
function Is_In_Config
(Config_Switch : String; Index : Integer) return Boolean
is
- Last : Natural;
- P : Switch_Parameter_Type;
+ Last : Natural;
+ P : Switch_Parameter_Type;
+
begin
Decompose_Switch (Config_Switch, P, Last);
return False;
end case;
end if;
+
return True;
end Is_In_Config;
Last : Natural;
Param : Natural;
P : Switch_Parameter_Type;
+
begin
-- This function is called when we believe the parameter was
-- specified as part of the switch, instead of separately. Thus we
-- look in the config to find all possible switches.
Decompose_Switch (Config_Switch, P, Last);
+
if Looking_At
(Switch, Switch'First, Config_Switch (Config_Switch'First .. Last))
then
- Param := Switch'First + Last; -- First char of parameter
+ -- Set first char of Param, and last char of Switch
+
+ Param := Switch'First + Last;
Last := Switch'First + Last - Config_Switch'First;
- -- last char of Switch
case P is
+
+ -- None is already handled in Is_In_Config
+
when Parameter_None =>
- null; -- Already handled in Is_In_Config
+ null;
+
when Parameter_With_Space_Or_Equal =>
if Switch (Param) = ' '
or else Switch (Param) = '='
end if;
when Parameter_With_Optional_Space =>
- if Switch (Param) = ' ' then
+ if Param <= Switch'Last and then Switch (Param) = ' ' then
Param := Param + 1;
end if;
return True;
end Starts_With;
+ -- Start of processing for For_Each_Simple_Switch
+
begin
-- First determine if the switch corresponds to one belonging to the
-- configuration. If so, run callback and exit.
Foreach_Switch (Config, Is_In_Config'Access, Section);
+
if Found_In_Config then
return;
end if;
Success : Boolean;
pragma Unreferenced (Success);
begin
- Add_Switch
- (Cmd, Switch, Parameter, Section, Add_Before, Success);
+ Add_Switch (Cmd, Switch, Parameter, Section, Add_Before, Success);
end Add_Switch;
----------------
Success : out Boolean)
is
procedure Add_Simple_Switch
- (Simple, Separator, Param : String; Index : Integer);
+ (Simple : String;
+ Separator : String;
+ Param : String;
+ Index : Integer);
-- Add a new switch that has had all its aliases expanded, and switches
-- ungrouped. We know there are no more aliases in Switches.
-----------------------
procedure Add_Simple_Switch
- (Simple, Separator, Param : String; Index : Integer)
+ (Simple : String;
+ Separator : String;
+ Param : String;
+ Index : Integer)
is
pragma Unreferenced (Index);
+
begin
if Cmd.Expanded = null then
Cmd.Expanded := new Argument_List'(1 .. 1 => new String'(Simple));
if Param /= "" then
- Cmd.Params := new Argument_List'
- (1 .. 1 => new String'(Separator & Param));
-
+ Cmd.Params :=
+ new Argument_List'(1 .. 1 => new String'(Separator & Param));
else
Cmd.Params := new Argument_List'(1 .. 1 => null);
end if;
if Section = "" then
Cmd.Sections := new Argument_List'(1 .. 1 => null);
-
else
- Cmd.Sections := new Argument_List'
- (1 .. 1 => new String'(Section));
+ Cmd.Sections :=
+ new Argument_List'(1 .. 1 => new String'(Section));
end if;
else
(Cmd.Params,
new String'(Separator & Param),
Add_Before);
-
else
Add
(Cmd.Params,
procedure Add_Simple_Switches is
new For_Each_Simple_Switch (Add_Simple_Switch);
- -- Start of processing for Add_Switch
+ -- Local Variables
Section_Valid : Boolean := False;
+
+ -- Start of processing for Add_Switch
+
begin
if Section /= "" and then Cmd.Config /= null then
for S in Cmd.Config.Sections'Range loop
-- Start of processing for Remove_Switch
begin
- Remove_Simple_Switches (Cmd.Config, Switch, Parameter);
+ Remove_Simple_Switches (Cmd.Config, Section, Switch, Parameter);
Free (Cmd.Coalesce);
end Remove_Switch;
Free (Result (C));
- else
- -- We changed section: we put the grouped switches to the
- -- first place, on continue with the new section.
+ -- We changed section: we put the grouped switches to the first
+ -- place, on continue with the new section.
+ else
Result (First) :=
new String'
(Cmd.Config.Prefixes (P).all &
(Switch, Separator, Param : String; Index : Integer)
is
pragma Unreferenced (Separator, Index);
+
begin
if Found then
for E in Result'Range loop
procedure Remove_Cb (Switch, Separator, Param : String; Index : Integer)
is
pragma Unreferenced (Separator, Index);
+
begin
for E in Result'Range loop
if Result (E) /= null
and then
(Params (E) = null
- or else Params (E) (Params (E)'First + 1
- .. Params (E)'Last) = Param)
+ or else Params (E) (Params (E)'First + 1
+ .. Params (E)'Last) = Param)
and then Result (E).all = Switch
then
if First > E then
First := E;
end if;
+
Free (Result (E));
Free (Params (E));
return;
procedure Display_Help (Config : Command_Line_Configuration) is
function Switch_Name
- (Def : Switch_Definition; Section : String) return String;
+ (Def : Switch_Definition;
+ Section : String) return String;
-- Return the "-short, --long=ARG" string for Def.
- -- Returns "" if the switch is not in the section
+ -- Returns "" if the switch is not in the section.
function Param_Name
- (P : Switch_Parameter_Type; Name : String := "ARG") return String;
+ (P : Switch_Parameter_Type;
+ Name : String := "ARG") return String;
-- Return the display for a switch parameter
procedure Display_Section_Help (Section : String);
-- Display the help for a specific section ("" is the default section)
- function Param_Name
- (P : Switch_Parameter_Type; Name : String := "ARG") return String is
- begin
- case P is
- when Parameter_None =>
- return "";
-
- when Parameter_With_Optional_Space =>
- return " " & To_Upper (Name);
-
- when Parameter_With_Space_Or_Equal =>
- return "=" & To_Upper (Name);
-
- when Parameter_No_Space =>
- return To_Upper (Name);
-
- when Parameter_Optional =>
- return '[' & To_Upper (Name) & ']';
- end case;
- end Param_Name;
-
- function Switch_Name
- (Def : Switch_Definition; Section : String) return String
- is
- use Ada.Strings.Unbounded;
- Result : Unbounded_String;
- P1, P2 : Switch_Parameter_Type;
- Last1, Last2 : Integer := 0;
- begin
- if (Section = "" and then Def.Section = null)
- or else (Def.Section /= null and then Def.Section.all = Section)
- then
- if Def.Switch /= null
- and then Def.Switch.all = "*"
- then
- return "[any switch]";
- end if;
-
- if Def.Switch /= null then
- Decompose_Switch (Def.Switch.all, P1, Last1);
- Append (Result, Def.Switch (Def.Switch'First .. Last1));
-
- if Def.Long_Switch /= null then
- Decompose_Switch (Def.Long_Switch.all, P2, Last2);
- Append (Result, ", "
- & Def.Long_Switch (Def.Long_Switch'First .. Last2));
- Append (Result, Param_Name (P2, "ARG"));
-
- else
- Append (Result, Param_Name (P1, "ARG"));
- end if;
-
- else -- Long_Switch necessarily not null
- Decompose_Switch (Def.Long_Switch.all, P2, Last2);
- Append (Result,
- Def.Long_Switch (Def.Long_Switch'First .. Last2));
- Append (Result, Param_Name (P2, "ARG"));
- end if;
- end if;
-
- return To_String (Result);
- end Switch_Name;
+ --------------------------
+ -- Display_Section_Help --
+ --------------------------
procedure Display_Section_Help (Section : String) is
Max_Len : Natural := 0;
end if;
end Display_Section_Help;
+ ----------------
+ -- Param_Name --
+ ----------------
+
+ function Param_Name
+ (P : Switch_Parameter_Type;
+ Name : String := "ARG") return String
+ is
+ begin
+ case P is
+ when Parameter_None =>
+ return "";
+
+ when Parameter_With_Optional_Space =>
+ return " " & To_Upper (Name);
+
+ when Parameter_With_Space_Or_Equal =>
+ return "=" & To_Upper (Name);
+
+ when Parameter_No_Space =>
+ return To_Upper (Name);
+
+ when Parameter_Optional =>
+ return '[' & To_Upper (Name) & ']';
+ end case;
+ end Param_Name;
+
+ -----------------
+ -- Switch_Name --
+ -----------------
+
+ function Switch_Name
+ (Def : Switch_Definition;
+ Section : String) return String
+ is
+ use Ada.Strings.Unbounded;
+ Result : Unbounded_String;
+ P1, P2 : Switch_Parameter_Type;
+ Last1, Last2 : Integer := 0;
+
+ begin
+ if (Section = "" and then Def.Section = null)
+ or else (Def.Section /= null and then Def.Section.all = Section)
+ then
+ if Def.Switch /= null
+ and then Def.Switch.all = "*"
+ then
+ return "[any switch]";
+ end if;
+
+ if Def.Switch /= null then
+ Decompose_Switch (Def.Switch.all, P1, Last1);
+ Append (Result, Def.Switch (Def.Switch'First .. Last1));
+
+ if Def.Long_Switch /= null then
+ Decompose_Switch (Def.Long_Switch.all, P2, Last2);
+ Append (Result, ", "
+ & Def.Long_Switch (Def.Long_Switch'First .. Last2));
+ Append (Result, Param_Name (P2, "ARG"));
+
+ else
+ Append (Result, Param_Name (P1, "ARG"));
+ end if;
+
+ else -- Long_Switch necessarily not null
+ Decompose_Switch (Def.Long_Switch.all, P2, Last2);
+ Append (Result,
+ Def.Long_Switch (Def.Long_Switch'First .. Last2));
+ Append (Result, Param_Name (P2, "ARG"));
+ end if;
+ end if;
+
+ return To_String (Result);
+ end Switch_Name;
+
+ -- Start of processing for Display_Help
+
begin
if Config = null then
return;
end if;
Display_Section_Help ("");
+
if Config.Sections /= null and then Config.Switches /= null then
for S in Config.Sections'Range loop
Display_Section_Help (Config.Sections (S).all);
Section_Name : not null access constant String := Empty_Name'Access;
procedure Simple_Callback
- (Simple_Switch, Separator, Parameter : String; Index : Integer);
+ (Simple_Switch : String;
+ Separator : String;
+ Parameter : String;
+ Index : Integer);
+ -- Needs comments ???
+
procedure Do_Callback (Switch, Parameter : String; Index : Integer);
+ -----------------
+ -- Do_Callback --
+ -----------------
+
procedure Do_Callback (Switch, Parameter : String; Index : Integer) is
begin
-- Do automatic handling when possible
end if;
end Do_Callback;
+ procedure For_Each_Simple
+ is new For_Each_Simple_Switch (Simple_Callback);
+
+ ---------------------
+ -- Simple_Callback --
+ ---------------------
+
procedure Simple_Callback
- (Simple_Switch, Separator, Parameter : String; Index : Integer)
+ (Simple_Switch : String;
+ Separator : String;
+ Parameter : String;
+ Index : Integer)
is
pragma Unreferenced (Separator);
begin
Index => Index);
end Simple_Callback;
- procedure For_Each_Simple
- is new For_Each_Simple_Switch (Simple_Callback);
+ -- Start of processing for Getopt
begin
-- Initialize sections
Section_Delimiters => Section_Delimiters (Config));
Getopt_Switches := new String'
- (Get_Switches (Config, Section_Name.all, Parser.Switch_Character)
+ (Get_Switches (Config, Parser.Switch_Character, Section_Name.all)
& " h -help");
-- Initialize output values for automatically handled switches
Free (Getopt_Switches);
Getopt_Switches := new String'
(Get_Switches
- (Config, Section_Name.all, Parser.Switch_Character));
+ (Config, Parser.Switch_Character, Section_Name.all));
end if;
end loop;
Free (Getopt_Switches);
-- Message inspired by "ls" on Unix
+
Put_Line (Standard_Error,
Base_Name (Ada.Command_Line.Command_Name)
& ": unrecognized option '"
is
Iter : Command_Line_Iterator;
Count : Natural := 0;
+
begin
Start (Line, Iter, Expanded => Expanded);
while Has_More (Iter) loop
-- High level package for command line parsing and manipulation
---------------------------------------
--- Simple parsing of the command line
---------------------------------------
+----------------------------------------
+-- Simple Parsing of the Command Line --
+----------------------------------------
-- This package provides an interface for parsing command line arguments,
-- when they are either read from Ada.Command_Line or read from a string list.
-- when Invalid_Parameter => Put_Line ("No parameter for " & Full_Switch);
-- end;
--------------
--- Sections
--------------
+--------------
+-- Sections --
+--------------
-- A more complicated example would involve the use of sections for the
-- switches, as for instance in gnatmake. The same command line is used to
-- end loop;
-- end;
-------------------------------
--- Parsing a list of strings
-------------------------------
+-------------------------------
+-- Parsing a List of Strings --
+-------------------------------
-- The examples above show how to parse the command line when the arguments
-- are read directly from Ada.Command_Line. However, these arguments can also
-- Free (Parser);
-- end;
-----------------------------------------------
--- High level command line configuration
-----------------------------------------------
+-------------------------------------------
+-- High-Level Command Line Configuration --
+-------------------------------------------
-- As shown above, the code is still relatively low-level. For instance, there
-- is no way to indicate which switches are related (thus if "-l" and "--long"
-- Optimization and Verbose have been properly initialized, either to the
-- default value or to the value found on the command line.
-----------------------------------------------
--- Creating and manipulating the command line
-----------------------------------------------
+------------------------------------------------
+-- Creating and Manipulating the Command Line --
+------------------------------------------------
-- This package provides mechanisms to create and modify command lines by
-- adding or removing arguments from them. The resulting command line is kept
-- and will not be grouped with other parts of the command line.
with Ada.Command_Line;
+
with GNAT.Directory_Operations;
with GNAT.OS_Lib;
with GNAT.Regexp;
-----------------
-- Configuring --
-----------------
+
-- The following subprograms are used to manipulate a command line
-- represented as a string (for instance "-g -O2"), as well as parsing
-- the switches from such a string. They provide high-level configurations
-- to define aliases (a switch is equivalent to one or more other switches)
-- or grouping of switches ("-gnatyac" is equivalent to "-gnatya" and
-- "-gnatyc").
+
-- See the top of this file for examples on how to use these subprograms
type Command_Line_Configuration is private;
-- Indicates a new switch section. All switches belonging to the same
-- section are ordered together, preceded by the section. They are placed
-- at the end of the command line (as in "gnatmake somefile.adb -cargs -g")
- -- The section name should not include the leading '-'.
- -- So for instance in the case of gnatmake we would use:
+ --
+ -- The section name should not include the leading '-'. So for instance in
+ -- the case of gnatmake we would use:
+ --
-- Define_Section (Config, "cargs");
-- Define_Section (Config, "bargs");
-- be expanded as Expanded. For instance, for the GNAT compiler switches,
-- we would define "-gnatwa" as an alias for "-gnatwcfijkmopruvz", ie some
-- default warnings to be activated.
+ --
-- This expansion is only done within the specified section, which must
-- have been defined first through a call to [Define_Section].
procedure Define_Prefix
- (Config : in out Command_Line_Configuration;
- Prefix : String);
+ (Config : in out Command_Line_Configuration;
+ Prefix : String);
-- Indicates that all switches starting with the given prefix should be
-- grouped. For instance, for the GNAT compiler we would define "-gnatw" as
-- a prefix, so that "-gnatwu -gnatwv" can be grouped into "-gnatwuv" It is
function Get_Switches
(Config : Command_Line_Configuration;
- Section : String := "";
- Switch_Char : Character := '-') return String;
+ Switch_Char : Character := '-';
+ Section : String := "") return String;
-- Get the switches list as expected by Getopt, for a specific section of
-- the command line. This list is built using all switches defined
-- previously via Define_Switch above.
function Section_Delimiters
- (Config : Command_Line_Configuration) return String;
+ (Config : Command_Line_Configuration) return String;
-- Return a string suitable for use in Initialize_Option_Scan
procedure Free (Config : in out Command_Line_Configuration);
------------------------------
-- Generating command lines --
------------------------------
+
-- Once the command line configuration has been created, you can build your
-- own command line. This will be done in general because you need to spawn
-- external tools from your application.
+
-- Although it could be done by concatenating strings, the following
-- subprograms will properly take care of grouping switches when possible,
-- so as to keep the command line as short as possible. They also provide a
-- way to remove a switch from an existing command line.
+
-- For instance:
-- declare
-- Config : Command_Line_Configuration;
Args : out GNAT.OS_Lib.Argument_List_Access;
Expanded : Boolean := False;
Switch_Char : Character := '-');
- -- This is a wrapper using the Command_Line_Iterator.
- -- It provides a simple way to get all switches (grouped as much as
- -- possible), and possibly create an Opt_Parser.
- -- [Args] must be freed by the caller.
- -- [Expanded] has the same meaning as in [Start].
+ -- This is a wrapper using the Command_Line_Iterator. It provides a simple
+ -- way to get all switches (grouped as much as possible), and possibly
+ -- create an Opt_Parser.
+ --
+ -- Args must be freed by the caller.
+ -- Expanded has the same meaning as in Start.
private
end record;
Command_Line_Parser_Data : aliased Opt_Parser_Data
- (Ada.Command_Line.Argument_Count);
+ (Ada.Command_Line.Argument_Count);
-- The internal data used when parsing the command line
type Opt_Parser is access all Opt_Parser_Data;
-- [Switch] includes the leading '-'
type Alias_Definition is record
- Alias : GNAT.OS_Lib.String_Access;
- Expansion : GNAT.OS_Lib.String_Access;
- Section : GNAT.OS_Lib.String_Access;
+ Alias : GNAT.OS_Lib.String_Access;
+ Expansion : GNAT.OS_Lib.String_Access;
+ Section : GNAT.OS_Lib.String_Access;
end record;
type Alias_Definitions is array (Natural range <>) of Alias_Definition;
type Alias_Definitions_List is access all Alias_Definitions;
type Command_Line_Configuration_Record is record
- Prefixes : GNAT.OS_Lib.Argument_List_Access;
+ Prefixes : GNAT.OS_Lib.Argument_List_Access;
-- The list of prefixes
- Sections : GNAT.OS_Lib.Argument_List_Access;
+ Sections : GNAT.OS_Lib.Argument_List_Access;
-- The list of sections
- Aliases : Alias_Definitions_List;
- Usage : GNAT.OS_Lib.String_Access;
- Help : GNAT.OS_Lib.String_Access;
- Switches : Switch_Definitions_List;
+ Aliases : Alias_Definitions_List;
+ Usage : GNAT.OS_Lib.String_Access;
+ Help : GNAT.OS_Lib.String_Access;
+ Switches : Switch_Definitions_List;
-- List of expected switches (Used when expanding switch groups)
end record;
type Command_Line_Configuration is access Command_Line_Configuration_Record;