Ptr : Integer := Switch_Chars'First;
C : Character := ' ';
+ function Get_Stack_Size (S : Character) return Int;
+ -- Used for -d and -D to scan stack size including handling k/m.
+ -- S is set to 'd' or 'D' to indicate the switch being scanned.
+
+ --------------------
+ -- Get_Stack_Size --
+ --------------------
+
+ function Get_Stack_Size (S : Character) return Int is
+ Result : Int;
+
+ begin
+ Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
+
+ -- In the following code, we enable overflow checking since the
+ -- multiplication by K or M may cause overflow, which is an error.
+
+ declare
+ pragma Unsuppress (Overflow_Check);
+
+ begin
+ -- Check for additional character 'k' (for kilobytes) or 'm'
+ -- (for Megabytes), but only if we have not reached the end
+ -- of the switch string. Note that if this appears before the
+ -- end of the string we will get an error when we test to make
+ -- sure that the string is exhausted (at the end of the case).
+
+ if Ptr <= Max then
+ if Switch_Chars (Ptr) = 'k' then
+ Result := Result * 1024;
+ Ptr := Ptr + 1;
+
+ elsif Switch_Chars (Ptr) = 'm' then
+ Result := Result * (1024 * 1024);
+ Ptr := Ptr + 1;
+ end if;
+ end if;
+
+ exception
+ when Constraint_Error =>
+ Osint.Fail
+ ("numeric value out of range for switch: ", (1 => S));
+ end;
+
+ return Result;
+ end Get_Stack_Size;
+
+ -- Start of processing for Scan_Binder_Switches
+
begin
-- Skip past the initial character (must be the switch character)
if Ptr = Max then
- Bad_Switch (C);
+ Bad_Switch (Switch_Chars);
else
Ptr := Ptr + 1;
end if;
-- Loop to scan through switches given in switch string
- while Ptr <= Max loop
+ Check_Switch : begin
C := Switch_Chars (Ptr);
case C is
when 'd' =>
- -- Note: for the debug switch, the remaining characters in this
- -- switch field must all be debug flags, since all valid switch
- -- characters are also valid debug characters. This switch is not
- -- documented on purpose because it is only used by the
- -- implementors.
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
- -- Loop to scan out debug flags
+ Ptr := Ptr + 1;
+ C := Switch_Chars (Ptr);
- while Ptr < Max loop
- Ptr := Ptr + 1;
- C := Switch_Chars (Ptr);
- exit when C = ASCII.NUL or else C = '/' or else C = '-';
+ -- Case where character after -d is a digit (default stack size)
- if C in '1' .. '9' or else
- C in 'a' .. 'z' or else
- C in 'A' .. 'Z'
- then
- Set_Debug_Flag (C);
- else
- Bad_Switch (C);
- end if;
- end loop;
+ if C in '0' .. '9' then
+
+ -- In this case, we process the default primary stack size
+
+ Default_Stack_Size := Get_Stack_Size ('d');
+
+ -- Case where character after -d is not digit (debug flags)
+
+ else
+ -- Note: for the debug switch, the remaining characters in this
+ -- switch field must all be debug flags, since all valid switch
+ -- characters are also valid debug characters. This switch is
+ -- not documented on purpose because it is only used by the
+ -- implementors.
+
+ -- Loop to scan out debug flags
+
+ loop
+ C := Switch_Chars (Ptr);
- return;
+ if C in 'a' .. 'z' or else C in 'A' .. 'Z' then
+ Set_Debug_Flag (C);
+ else
+ Bad_Switch (Switch_Chars);
+ end if;
+
+ Ptr := Ptr + 1;
+ exit when Ptr > Max;
+ end loop;
+ end if;
-- Processing for D switch
when 'D' =>
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
+
Ptr := Ptr + 1;
- Scan_Pos
- (Switch_Chars, Max, Ptr, Default_Sec_Stack_Size, C);
+ Default_Sec_Stack_Size := Get_Stack_Size ('D');
-- Processing for e switch
when 'i' =>
if Ptr = Max then
- Bad_Switch (C);
+ Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1;
Identifier_Character_Set := C;
Ptr := Ptr + 1;
else
- Bad_Switch (C);
+ Bad_Switch (Switch_Chars);
end if;
-- Processing for K switch
-- Processing for m switch
when 'm' =>
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
+
Ptr := Ptr + 1;
Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors, C);
-- Processing for T switch
when 'T' =>
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
+
Ptr := Ptr + 1;
Time_Slice_Set := True;
Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
-- Processing for u switch
when 'u' =>
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
+
Ptr := Ptr + 1;
Dynamic_Stack_Measurement := True;
Scan_Nat
-- Processing for w switch
when 'w' =>
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
-- For the binder we only allow suppress/error cases
Warning_Mode := Suppress;
when others =>
- Bad_Switch (C);
+ Bad_Switch (Switch_Chars);
end case;
Ptr := Ptr + 1;
-- Processing for W switch
when 'W' =>
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
+
Ptr := Ptr + 1;
for J in WC_Encoding_Method loop
exit;
elsif J = WC_Encoding_Method'Last then
- Bad_Switch (C);
+ Bad_Switch (Switch_Chars);
end if;
end loop;
-- Processing for X switch
when 'X' =>
+ if Ptr = Max then
+ Bad_Switch (Switch_Chars);
+ end if;
+
Ptr := Ptr + 1;
Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
Ptr := Ptr + 1;
No_Main_Subprogram := True;
- -- Ignore extra switch character
-
- when '/' =>
- Ptr := Ptr + 1;
-
- -- Ignore '-' extra switch caracter, only if it isn't followed by
- -- 'RTS'. If it is, then we must process the 'RTS' switch
+ -- Processing for --RTS
when '-' =>
- if Ptr + 3 <= Max and then
+ if Ptr + 4 <= Max and then
Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
then
- Ptr := Ptr + 1;
+ Ptr := Ptr + 4;
- if Switch_Chars (Ptr + 3) /= '=' or else
- (Switch_Chars (Ptr + 3) = '='
- and then Ptr + 4 > Max)
- then
+ if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
Osint.Fail ("missing path for --RTS");
- else
+ else
-- valid --RTS switch
+
Opt.No_Stdinc := True;
Opt.RTS_Switch := True;
Src_Path_Name : constant String_Ptr :=
Get_RTS_Search_Dir
(Switch_Chars
- (Ptr + 4 .. Switch_Chars'Last),
+ (Ptr + 1 .. Switch_Chars'Last),
Include);
Lib_Path_Name : constant String_Ptr :=
Get_RTS_Search_Dir
(Switch_Chars
- (Ptr + 4 .. Switch_Chars'Last),
+ (Ptr + 1 .. Switch_Chars'Last),
Objects);
begin
RTS_Src_Path_Name := Src_Path_Name;
RTS_Lib_Path_Name := Lib_Path_Name;
- -- We can exit as there cannot be another switch
- -- after --RTS
-
- exit;
+ Ptr := Max + 1;
elsif Src_Path_Name = null
and then Lib_Path_Name = null
end if;
else
- Ptr := Ptr + 1;
+ Bad_Switch (Switch_Chars);
end if;
-- Anything else is an error (illegal switch character)
when others =>
- Bad_Switch (C);
+ Bad_Switch (Switch_Chars);
end case;
- end loop;
+
+ if Ptr <= Max then
+ Bad_Switch (Switch_Chars);
+ end if;
+ end Check_Switch;
end Scan_Binder_Switches;
end Switch.B;