* gcc.c (getenv_spec_function): New function.
[official-gcc.git] / gcc / ada / switch.adb
blob7692f589f989f46c98fe9cf3cc74e0087b865c2f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S W I T C H --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Osint;
29 package body Switch is
31 ----------------
32 -- Bad_Switch --
33 ----------------
35 procedure Bad_Switch (Switch : Character) is
36 begin
37 Osint.Fail ("invalid switch: ", (1 => Switch));
38 end Bad_Switch;
40 procedure Bad_Switch (Switch : String) is
41 begin
42 Osint.Fail ("invalid switch: ", Switch);
43 end Bad_Switch;
45 -------------------------
46 -- Is_Front_End_Switch --
47 -------------------------
49 function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
50 Ptr : constant Positive := Switch_Chars'First;
51 begin
52 return Is_Switch (Switch_Chars)
53 and then
54 (Switch_Chars (Ptr + 1) = 'I'
55 or else (Switch_Chars'Length >= 5
56 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
57 or else (Switch_Chars'Length >= 5
58 and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS"));
59 end Is_Front_End_Switch;
61 ---------------
62 -- Is_Switch --
63 ---------------
65 function Is_Switch (Switch_Chars : String) return Boolean is
66 begin
67 return Switch_Chars'Length > 1
68 and then Switch_Chars (Switch_Chars'First) = '-';
69 end Is_Switch;
71 --------------
72 -- Scan_Nat --
73 --------------
75 procedure Scan_Nat
76 (Switch_Chars : String;
77 Max : Integer;
78 Ptr : in out Integer;
79 Result : out Nat;
80 Switch : Character)
82 begin
83 Result := 0;
85 if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
86 Osint.Fail ("missing numeric value for switch: ", (1 => Switch));
88 else
89 while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
90 Result := Result * 10 +
91 Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
92 Ptr := Ptr + 1;
94 if Result > Switch_Max_Value then
95 Osint.Fail
96 ("numeric value out of range for switch: ", (1 => Switch));
97 end if;
98 end loop;
99 end if;
100 end Scan_Nat;
102 --------------
103 -- Scan_Pos --
104 --------------
106 procedure Scan_Pos
107 (Switch_Chars : String;
108 Max : Integer;
109 Ptr : in out Integer;
110 Result : out Pos;
111 Switch : Character)
113 Temp : Nat;
115 begin
116 Scan_Nat (Switch_Chars, Max, Ptr, Temp, Switch);
118 if Temp = 0 then
119 Osint.Fail ("numeric value out of range for switch: ", (1 => Switch));
120 end if;
122 Result := Temp;
123 end Scan_Pos;
125 end Switch;