OSDN Git Service

Delete all lines containing "$Revision:".
[pf3gnuchains/gcc-fork.git] / gcc / ada / switch.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               S W I T C H                                --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1992-2001, Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 package body Switch is
29
30    -------------------------
31    -- Is_Front_End_Switch --
32    -------------------------
33
34    function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
35       Ptr : constant Positive := Switch_Chars'First;
36
37    begin
38       return Is_Switch (Switch_Chars)
39         and then
40         (Switch_Chars (Ptr + 1) = 'I'
41          or else (Switch_Chars'Length >= 5
42                   and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
43          or else (Switch_Chars'Length >= 5
44                   and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "fRTS"));
45    end Is_Front_End_Switch;
46
47    ---------------
48    -- Is_Switch --
49    ---------------
50
51    function Is_Switch (Switch_Chars : String) return Boolean is
52    begin
53       return Switch_Chars'Length > 1
54         and then Switch_Chars (Switch_Chars'First) = '-';
55    end Is_Switch;
56
57    ------------------------
58    --------------
59    -- Scan_Nat --
60    --------------
61
62    procedure Scan_Nat
63      (Switch_Chars : String;
64       Max          : Integer;
65       Ptr          : in out Integer;
66       Result       : out Nat)
67    is
68    begin
69       Result := 0;
70
71       if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
72          raise Missing_Switch_Value;
73       end if;
74
75       while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
76          Result := Result * 10 +
77            Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
78          Ptr := Ptr + 1;
79
80          if Result > Switch_Max_Value then
81             raise Bad_Switch_Value;
82          end if;
83       end loop;
84    end Scan_Nat;
85
86    --------------
87    -- Scan_Pos --
88    --------------
89
90    procedure Scan_Pos
91      (Switch_Chars : String;
92       Max          : Integer;
93       Ptr          : in out Integer;
94       Result       : out Pos) is
95
96    begin
97       Scan_Nat (Switch_Chars, Max, Ptr, Result);
98
99       if Result = 0 then
100          raise Bad_Switch_Value;
101       end if;
102    end Scan_Pos;
103
104 end Switch;