]> gcc.gnu.org Git - gcc.git/blame - gcc/ada/switch.adb
1aexcept.adb, [...]: Merge header, formatting and other trivial changes from ACT.
[gcc.git] / gcc / ada / switch.adb
CommitLineData
996ae0b0
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- S W I T C H --
6-- --
7-- B o d y --
8-- --
996ae0b0
RK
9-- Copyright (C) 1992-2001, 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. --
71ff80dc 23-- Extensive contributions were provided by Ada Core Technologies Inc. --
996ae0b0
RK
24-- --
25------------------------------------------------------------------------------
26
996ae0b0
RK
27package body Switch is
28
996ae0b0
RK
29 -------------------------
30 -- Is_Front_End_Switch --
31 -------------------------
32
33 function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
07fc65c4
GB
34 Ptr : constant Positive := Switch_Chars'First;
35
996ae0b0
RK
36 begin
37 return Is_Switch (Switch_Chars)
38 and then
07fc65c4
GB
39 (Switch_Chars (Ptr + 1) = 'I'
40 or else (Switch_Chars'Length >= 5
41 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
42 or else (Switch_Chars'Length >= 5
43 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "fRTS"));
996ae0b0
RK
44 end Is_Front_End_Switch;
45
46 ---------------
47 -- Is_Switch --
48 ---------------
49
50 function Is_Switch (Switch_Chars : String) return Boolean is
51 begin
52 return Switch_Chars'Length > 1
07fc65c4 53 and then Switch_Chars (Switch_Chars'First) = '-';
996ae0b0
RK
54 end Is_Switch;
55
996ae0b0 56 ------------------------
996ae0b0
RK
57 --------------
58 -- Scan_Nat --
59 --------------
60
61 procedure Scan_Nat
62 (Switch_Chars : String;
63 Max : Integer;
64 Ptr : in out Integer;
07fc65c4
GB
65 Result : out Nat)
66 is
996ae0b0
RK
67 begin
68 Result := 0;
07fc65c4 69
996ae0b0
RK
70 if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
71 raise Missing_Switch_Value;
72 end if;
73
74 while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
75 Result := Result * 10 +
76 Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
77 Ptr := Ptr + 1;
78
79 if Result > Switch_Max_Value then
80 raise Bad_Switch_Value;
81 end if;
82 end loop;
83 end Scan_Nat;
84
85 --------------
86 -- Scan_Pos --
87 --------------
88
89 procedure Scan_Pos
90 (Switch_Chars : String;
91 Max : Integer;
92 Ptr : in out Integer;
93 Result : out Pos) is
94
95 begin
96 Scan_Nat (Switch_Chars, Max, Ptr, Result);
07fc65c4 97
996ae0b0
RK
98 if Result = 0 then
99 raise Bad_Switch_Value;
100 end if;
101 end Scan_Pos;
102
103end Switch;
This page took 0.41572 seconds and 5 git commands to generate.