This patch modifies the behavior of Getopt in GNAT.Command_Line to not call
the Callback function in argument on switches that have been dealt with
automatically.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-09-02  Johannes Kanig  <ka...@adacore.com>

        * g-comlin.adb (Getopt): Return when switch is dealt with automatically,
        instead of calling the callback function

Index: g-comlin.adb
===================================================================
--- g-comlin.adb        (revision 178381)
+++ g-comlin.adb        (working copy)
@@ -3290,11 +3290,14 @@
                           with "Expected integer parameter for '"
                             & Switch & "'";
                   end;
+                  return;
 
                when Switch_String =>
                   Free (Config.Switches (Index).String_Output.all);
                   Config.Switches (Index).String_Output.all :=
                     new String'(Parameter);
+                  return;
+
             end case;
          end if;
 
Index: g-comlin.ads
===================================================================
--- g-comlin.ads        (revision 178381)
+++ g-comlin.ads        (working copy)
@@ -707,7 +707,8 @@
       Callback : Switch_Handler := null;
       Parser   : Opt_Parser := Command_Line_Parser);
    --  Similar to the standard Getopt function.
-   --  For each switch found on the command line, this calls Callback.
+   --  For each switch found on the command line, this calls Callback, if the
+   --  switch is not handled automatically.
    --
    --  The list of valid switches are the ones from the configuration. The
    --  switches that were declared through Define_Switch with an Output

Reply via email to