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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Osint; use Osint;
27 with Output; use Output;
29 package body Switch is
35 procedure Bad_Switch (Switch : Character) is
37 Osint.Fail ("invalid switch: ", (1 => Switch));
40 procedure Bad_Switch (Switch : String) is
42 Osint.Fail ("invalid switch: ", Switch);
45 ------------------------------
46 -- Check_Version_And_Help_G --
47 ------------------------------
49 procedure Check_Version_And_Help_G
51 Initial_Year : String;
52 Version_String : String := Gnatvsn.Gnat_Version_String)
54 Version_Switch_Present : Boolean := False;
55 Help_Switch_Present : Boolean := False;
59 -- First check for --version or --help
62 while Next_Arg < Arg_Count loop
64 Next_Argv : String (1 .. Len_Arg (Next_Arg));
66 Fill_Arg (Next_Argv'Address, Next_Arg);
68 if Next_Argv = Version_Switch then
69 Version_Switch_Present := True;
71 elsif Next_Argv = Help_Switch then
72 Help_Switch_Present := True;
75 Next_Arg := Next_Arg + 1;
79 -- If --version was used, display version and exit
81 if Version_Switch_Present then
83 Display_Version (Tool_Name, Initial_Year, Version_String);
84 Write_Str (Gnatvsn.Gnat_Free_Software);
87 Exit_Program (E_Success);
90 -- If --help was used, display help and exit
92 if Help_Switch_Present then
96 Write_Line ("Report bugs to report@adacore.com");
97 Exit_Program (E_Success);
99 end Check_Version_And_Help_G;
101 ---------------------
102 -- Display_Version --
103 ---------------------
105 procedure Display_Version
107 Initial_Year : String;
108 Version_String : String := Gnatvsn.Gnat_Version_String)
111 Write_Str (Tool_Name);
113 Write_Str (Version_String);
116 Write_Str ("Copyright (C) ");
117 Write_Str (Initial_Year);
119 Write_Str (Gnatvsn.Current_Year);
121 Write_Str (Gnatvsn.Copyright_Holder);
125 -------------------------
126 -- Is_Front_End_Switch --
127 -------------------------
129 function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
130 Ptr : constant Positive := Switch_Chars'First;
132 return Is_Switch (Switch_Chars)
134 (Switch_Chars (Ptr + 1) = 'I'
135 or else (Switch_Chars'Length >= 5
136 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
137 or else (Switch_Chars'Length >= 5
138 and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS"));
139 end Is_Front_End_Switch;
145 function Is_Switch (Switch_Chars : String) return Boolean is
147 return Switch_Chars'Length > 1
148 and then Switch_Chars (Switch_Chars'First) = '-';
156 (Switch_Chars : String;
158 Ptr : in out Integer;
165 if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
166 Osint.Fail ("missing numeric value for switch: ", (1 => Switch));
169 while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
170 Result := Result * 10 +
171 Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
174 if Result > Switch_Max_Value then
176 ("numeric value out of range for switch: ", (1 => Switch));
187 (Switch_Chars : String;
189 Ptr : in out Integer;
196 Scan_Nat (Switch_Chars, Max, Ptr, Temp, Switch);
199 Osint.Fail ("numeric value out of range for switch: ", (1 => Switch));