Index: natools-getopt_long.adb ================================================================== --- natools-getopt_long.adb +++ natools-getopt_long.adb @@ -100,10 +100,43 @@ end Unknown_Option; end Handlers; + + ------------------------------------- + -- Simple configuration parameters -- + ------------------------------------- + + function Posixly_Correct (Config : Configuration) return Boolean is + begin + return Config.Posixly_Correct; + end Posixly_Correct; + + + procedure Posixly_Correct + (Config : in out Configuration; + To : Boolean := True) is + begin + Config.Posixly_Correct := To; + end Posixly_Correct; + + + function Long_Only (Config : Configuration) return Boolean is + begin + return Config.Long_Only; + end Long_Only; + + + procedure Use_Long_Only + (Config : in out Configuration; + Value : Boolean := True) is + begin + Config.Long_Only := Value; + end Use_Long_Only; + + ---------------------------- -- Option list management -- ---------------------------- @@ -473,12 +506,10 @@ ----------------------------- procedure Process (Config : Configuration; Handler : in out Handlers.Callback'Class; - Posixly_Correct : Boolean := True; - Long_Only : Boolean := False; Argument_Count : not null access function return Natural := Ada.Command_Line.Argument_Count'Access; Argument : not null access function (Number : Positive) return String := Ada.Command_Line.Argument'Access) is @@ -565,11 +596,11 @@ Arg : constant String := Argument (Arg_N); begin if Arg'Length <= 1 or else Arg (Arg'First) /= '-' then -- This is a non-flag argument, abort option processing if -- posixly correct. - if Posixly_Correct then + if Config.Posixly_Correct then exit; else Handler.Argument (Arg); Arg_N := Arg_N + 1; end if; @@ -580,11 +611,11 @@ exit; end if; -- Argument starting with "--": long option. Process_Long_Option (Arg (Arg'First + 2 .. Arg'Last)); Arg_N := Arg_N + 1; - elsif Long_Only then + elsif Config.Long_Only then -- Force long option on a single dash prefix. Process_Long_Option (Arg (Arg'First + 1 .. Arg'Last)); Arg_N := Arg_N + 1; else -- Process a list of short options, until one with required Index: natools-getopt_long.ads ================================================================== --- natools-getopt_long.ads +++ natools-getopt_long.ads @@ -126,10 +126,28 @@ type Argument_Requirement is (No_Argument, Required_Argument, Optional_Argument); type Configuration is tagged private; + + -- Simple parameters -- + + function Posixly_Correct (Config : Configuration) return Boolean; + + procedure Posixly_Correct + (Config : in out Configuration; + To : Boolean := True); + + function Long_Only (Config : Configuration) return Boolean; + + procedure Use_Long_Only + (Config : in out Configuration; + Value : Boolean := True); + + + -- Option list management -- + procedure Add_Option (Config : in out Configuration; Long_Name : String; Short_Name : Character; Has_Arg : Argument_Requirement; @@ -163,10 +181,13 @@ procedure Del_Option (Config : in out Configuration; Short_Name : Character); -- Remove from the database an option identified by its short name. + + -- Formatting subprograms -- + function Format_Long_Names (Config : Configuration; Id : Option_Id; Separator : String := ", "; Name_Prefix : String := "--") @@ -239,12 +260,10 @@ -------------------------------------- procedure Process (Config : Configuration; Handler : in out Handlers.Callback'Class; - Posixly_Correct : Boolean := True; - Long_Only : Boolean := False; Argument_Count : not null access function return Natural := Ada.Command_Line.Argument_Count'Access; Argument : not null access function (Number : Positive) return String := Ada.Command_Line.Argument'Access); -- Process system command line argument list, using the provided option @@ -266,8 +285,10 @@ new Ada.Containers.Indefinite_Ordered_Maps (Character, Option); type Configuration is tagged record By_Long_Name : Long_Option_Maps.Map; By_Short_Name : Short_Option_Maps.Map; + Posixly_Correct : Boolean := True; + Long_Only : Boolean := False; end record; end Natools.Getopt_Long; Index: natools-getopt_long_tests.adb ================================================================== --- natools-getopt_long_tests.adb +++ natools-getopt_long_tests.adb @@ -65,15 +65,19 @@ Separator : constant Character := ';'; package Getopt is new Natools.Getopt_Long (Option_Id); - function Getopt_Config return Getopt.Configuration; + function Getopt_Config + (Posixly_Correct, Long_Only : Boolean) + return Getopt.Configuration; -- Create the Getopt.Configuration object used for these tests. - function Getopt_Config return Getopt.Configuration is + function Getopt_Config + (Posixly_Correct, Long_Only : Boolean) + return Getopt.Configuration is begin return OD : Getopt.Configuration do OD.Add_Option ('a', Getopt.No_Argument, Short_No_Arg); OD.Add_Option ('q', Getopt.No_Argument, Short_No_Arg_2); OD.Add_Option ('f', Getopt.Required_Argument, Short_Arg); @@ -83,10 +87,12 @@ OD.Add_Option ("color", Getopt.Optional_Argument, Long_Opt_Arg); OD.Add_Option ("input", Getopt.Required_Argument, Long_Arg); OD.Add_Option ("execute", 'e', Getopt.Required_Argument, Mixed_Arg); OD.Add_Option ("ignore-case", 'i', Getopt.No_Argument, Mixed_No_Arg); OD.Add_Option ("write", 'w', Getopt.Optional_Argument, Mixed_Opt_Arg); + OD.Posixly_Correct (Posixly_Correct); + OD.Use_Long_Only (Long_Only); end return; end Getopt_Config; @@ -286,19 +292,18 @@ Expected_Error : String_Vectors.Vector := String_Vectors.Empty_Vector; Posixly_Correct : Boolean := True; Long_Only : Boolean := False) is use type String_Vectors.Vector; - Config : constant Getopt.Configuration := Getopt_Config; + Config : constant Getopt.Configuration + := Getopt_Config (Posixly_Correct, Long_Only); Handler : Handlers.Basic; begin begin Getopt.Process (Config => Config, Handler => Handler, - Posixly_Correct => Posixly_Correct, - Long_Only => Long_Only, Argument_Count => Argument_Count'Access, Argument => Argument'Access); exception when Error : Getopt.Option_Error => Handler.Flag_Error.Append @@ -387,11 +392,11 @@ Expected_Seen : Flag_Seen_Array; Expected_Argument : Flag_Argument_Array; Expected_Count : Handlers.Error_Count) is use type Handlers.Error_Count; - Config : constant Getopt.Configuration := Getopt_Config; + Config : constant Getopt.Configuration := Getopt_Config (True, False); Handler : Handlers.Recovering; begin Getopt.Process (Config => Config, Handler => Handler,