OSDN Git Service

2009-04-09 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / switch.adb
index e185d70..f318de7 100644 (file)
@@ -148,6 +148,24 @@ package body Switch is
         and then Switch_Chars (Switch_Chars'First) = '-';
    end Is_Switch;
 
+   -----------------
+   -- Nat_Present --
+   -----------------
+
+   function Nat_Present
+     (Switch_Chars : String;
+      Max          : Integer;
+      Ptr          : Integer) return Boolean
+   is
+   begin
+      return (Ptr <= Max
+                and then Switch_Chars (Ptr) in '0' .. '9')
+        or else
+             (Ptr < Max
+                and then Switch_Chars (Ptr) = '='
+                and then Switch_Chars (Ptr + 1) in '0' .. '9');
+   end Nat_Present;
+
    --------------
    -- Scan_Nat --
    --------------
@@ -162,20 +180,24 @@ package body Switch is
    begin
       Result := 0;
 
-      if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
+      if not Nat_Present (Switch_Chars, Max, Ptr) then
          Osint.Fail ("missing numeric value for switch: " & Switch);
+      end if;
 
-      else
-         while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
-            Result := Result * 10 +
-              Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
-            Ptr := Ptr + 1;
-
-            if Result > Switch_Max_Value then
-               Osint.Fail ("numeric value out of range for switch: " & Switch);
-            end if;
-         end loop;
+      if Switch_Chars (Ptr) = '=' then
+         Ptr := Ptr + 1;
       end if;
+
+      while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
+         Result :=
+           Result * 10 +
+             Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
+         Ptr := Ptr + 1;
+
+         if Result > Switch_Max_Value then
+            Osint.Fail ("numeric value out of range for switch: " & Switch);
+         end if;
+      end loop;
    end Scan_Nat;
 
    --------------