OSDN Git Service

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