OSDN Git Service

* config/arm/crti.asm: Give _init and _fini function type.
[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 --          Copyright (C) 1992-2004, 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
26
27 package body Switch is
28
29    -------------------------
30    -- Is_Front_End_Switch --
31    -------------------------
32
33    function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
34       Ptr : constant Positive := Switch_Chars'First;
35    begin
36       return Is_Switch (Switch_Chars)
37         and then
38           (Switch_Chars (Ptr + 1) = 'I'
39             or else (Switch_Chars'Length >= 5
40                       and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
41             or else (Switch_Chars'Length >= 5
42                       and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS"));
43    end Is_Front_End_Switch;
44
45    ---------------
46    -- Is_Switch --
47    ---------------
48
49    function Is_Switch (Switch_Chars : String) return Boolean is
50    begin
51       return Switch_Chars'Length > 1
52         and then Switch_Chars (Switch_Chars'First) = '-';
53    end Is_Switch;
54
55    ------------------------
56    --------------
57    -- Scan_Nat --
58    --------------
59
60    procedure Scan_Nat
61      (Switch_Chars : String;
62       Max          : Integer;
63       Ptr          : in out Integer;
64       Result       : out Nat)
65    is
66    begin
67       Result := 0;
68
69       if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
70          raise Missing_Switch_Value;
71       end if;
72
73       while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
74          Result := Result * 10 +
75            Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
76          Ptr := Ptr + 1;
77
78          if Result > Switch_Max_Value then
79             raise Bad_Switch_Value;
80          end if;
81       end loop;
82    end Scan_Nat;
83
84    --------------
85    -- Scan_Pos --
86    --------------
87
88    procedure Scan_Pos
89      (Switch_Chars : String;
90       Max          : Integer;
91       Ptr          : in out Integer;
92       Result       : out Pos)
93    is
94       Temp : Nat;
95
96    begin
97       Scan_Nat (Switch_Chars, Max, Ptr, Temp);
98
99       if Temp = 0 then
100          raise Bad_Switch_Value;
101       end if;
102
103       Result := Temp;
104    end Scan_Pos;
105
106 end Switch;