1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Osint; use Osint;
28 with Output; use Output;
30 package body Switch is
36 procedure Bad_Switch (Switch : Character) is
38 Osint.Fail ("invalid switch: ", (1 => Switch));
41 procedure Bad_Switch (Switch : String) is
43 Osint.Fail ("invalid switch: ", Switch);
46 ----------------------------
47 -- Check_Version_And_Help --
48 ----------------------------
50 procedure Check_Version_And_Help
52 Initial_Year : String;
53 Usage : Procedure_Ptr;
54 Version_String : String := Gnatvsn.Gnat_Version_String)
56 Version_Switch_Present : Boolean := False;
57 Help_Switch_Present : Boolean := False;
61 -- First check for --version or --help
64 while Next_Arg < Arg_Count loop
66 Next_Argv : String (1 .. Len_Arg (Next_Arg));
68 Fill_Arg (Next_Argv'Address, Next_Arg);
70 if Next_Argv = Version_Switch then
71 Version_Switch_Present := True;
73 elsif Next_Argv = Help_Switch then
74 Help_Switch_Present := True;
77 Next_Arg := Next_Arg + 1;
81 -- If --version was used, display version and exit
83 if Version_Switch_Present then
85 Display_Version (Tool_Name, Initial_Year, Version_String);
86 Write_Str (Gnatvsn.Gnat_Free_Software);
89 Exit_Program (E_Success);
92 -- If --help was used, display help and exit
94 if Help_Switch_Present then
98 Write_Line ("Report bugs to report@adacore.com");
99 Exit_Program (E_Success);
101 end Check_Version_And_Help;
103 ---------------------
104 -- Display_Version --
105 ---------------------
107 procedure Display_Version
109 Initial_Year : String;
110 Version_String : String := Gnatvsn.Gnat_Version_String)
113 Write_Str (Tool_Name);
115 Write_Str (Version_String);
118 Write_Str ("Copyright (C) ");
119 Write_Str (Initial_Year);
121 Write_Str (Gnatvsn.Current_Year);
123 Write_Str (Gnatvsn.Copyright_Holder);
127 -------------------------
128 -- Is_Front_End_Switch --
129 -------------------------
131 function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
132 Ptr : constant Positive := Switch_Chars'First;
134 return Is_Switch (Switch_Chars)
136 (Switch_Chars (Ptr + 1) = 'I'
137 or else (Switch_Chars'Length >= 5
138 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
139 or else (Switch_Chars'Length >= 5
140 and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS"));
141 end Is_Front_End_Switch;
147 function Is_Switch (Switch_Chars : String) return Boolean is
149 return Switch_Chars'Length > 1
150 and then Switch_Chars (Switch_Chars'First) = '-';
158 (Switch_Chars : String;
160 Ptr : in out Integer;
167 if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
168 Osint.Fail ("missing numeric value for switch: ", (1 => Switch));
171 while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
172 Result := Result * 10 +
173 Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
176 if Result > Switch_Max_Value then
178 ("numeric value out of range for switch: ", (1 => Switch));
189 (Switch_Chars : String;
191 Ptr : in out Integer;
198 Scan_Nat (Switch_Chars, Max, Ptr, Temp, Switch);
201 Osint.Fail ("numeric value out of range for switch: ", (1 => Switch));