]>
Commit | Line | Data |
---|---|---|
996ae0b0 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- S W I T C H -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
1d005acc | 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- |
996ae0b0 RK |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
996ae0b0 RK |
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 -- | |
b5c84c3c RD |
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. -- | |
996ae0b0 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
996ae0b0 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
41c8951a VC |
26 | with Osint; use Osint; |
27 | with Output; use Output; | |
d4deddd7 | 28 | |
996ae0b0 RK |
29 | package body Switch is |
30 | ||
d4deddd7 VC |
31 | ---------------- |
32 | -- Bad_Switch -- | |
33 | ---------------- | |
34 | ||
35 | procedure Bad_Switch (Switch : Character) is | |
36 | begin | |
3dd9959c | 37 | Osint.Fail ("invalid switch: " & Switch); |
d4deddd7 VC |
38 | end Bad_Switch; |
39 | ||
61dddae4 RD |
40 | procedure Bad_Switch (Switch : String) is |
41 | begin | |
3dd9959c | 42 | Osint.Fail ("invalid switch: " & Switch); |
61dddae4 RD |
43 | end Bad_Switch; |
44 | ||
6a1cb33a BD |
45 | ------------------------------ |
46 | -- Check_Version_And_Help_G -- | |
47 | ------------------------------ | |
41c8951a | 48 | |
6a1cb33a | 49 | procedure Check_Version_And_Help_G |
41c8951a VC |
50 | (Tool_Name : String; |
51 | Initial_Year : String; | |
41c8951a VC |
52 | Version_String : String := Gnatvsn.Gnat_Version_String) |
53 | is | |
54 | Version_Switch_Present : Boolean := False; | |
55 | Help_Switch_Present : Boolean := False; | |
56 | Next_Arg : Natural; | |
57 | ||
58 | begin | |
59 | -- First check for --version or --help | |
60 | ||
61 | Next_Arg := 1; | |
62 | while Next_Arg < Arg_Count loop | |
63 | declare | |
64 | Next_Argv : String (1 .. Len_Arg (Next_Arg)); | |
65 | begin | |
66 | Fill_Arg (Next_Argv'Address, Next_Arg); | |
67 | ||
68 | if Next_Argv = Version_Switch then | |
69 | Version_Switch_Present := True; | |
70 | ||
71 | elsif Next_Argv = Help_Switch then | |
72 | Help_Switch_Present := True; | |
73 | end if; | |
74 | ||
75 | Next_Arg := Next_Arg + 1; | |
76 | end; | |
77 | end loop; | |
78 | ||
79 | -- If --version was used, display version and exit | |
80 | ||
81 | if Version_Switch_Present then | |
82 | Set_Standard_Output; | |
83 | Display_Version (Tool_Name, Initial_Year, Version_String); | |
84 | Write_Str (Gnatvsn.Gnat_Free_Software); | |
85 | Write_Eol; | |
86 | Write_Eol; | |
87 | Exit_Program (E_Success); | |
88 | end if; | |
89 | ||
90 | -- If --help was used, display help and exit | |
91 | ||
92 | if Help_Switch_Present then | |
93 | Set_Standard_Output; | |
6a1cb33a | 94 | Usage; |
41c8951a VC |
95 | Write_Eol; |
96 | Write_Line ("Report bugs to report@adacore.com"); | |
97 | Exit_Program (E_Success); | |
98 | end if; | |
6a1cb33a | 99 | end Check_Version_And_Help_G; |
41c8951a | 100 | |
439b6dfa AC |
101 | ------------------------------------ |
102 | -- Display_Usage_Version_And_Help -- | |
103 | ------------------------------------ | |
104 | ||
105 | procedure Display_Usage_Version_And_Help is | |
106 | begin | |
107 | Write_Str (" --version Display version and exit"); | |
108 | Write_Eol; | |
109 | ||
110 | Write_Str (" --help Display usage and exit"); | |
111 | Write_Eol; | |
112 | Write_Eol; | |
113 | end Display_Usage_Version_And_Help; | |
114 | ||
41c8951a VC |
115 | --------------------- |
116 | -- Display_Version -- | |
117 | --------------------- | |
118 | ||
119 | procedure Display_Version | |
120 | (Tool_Name : String; | |
121 | Initial_Year : String; | |
122 | Version_String : String := Gnatvsn.Gnat_Version_String) | |
123 | is | |
124 | begin | |
125 | Write_Str (Tool_Name); | |
126 | Write_Char (' '); | |
127 | Write_Str (Version_String); | |
128 | Write_Eol; | |
129 | ||
130 | Write_Str ("Copyright (C) "); | |
131 | Write_Str (Initial_Year); | |
132 | Write_Char ('-'); | |
133 | Write_Str (Gnatvsn.Current_Year); | |
134 | Write_Str (", "); | |
135 | Write_Str (Gnatvsn.Copyright_Holder); | |
136 | Write_Eol; | |
137 | end Display_Version; | |
138 | ||
996ae0b0 RK |
139 | ------------------------- |
140 | -- Is_Front_End_Switch -- | |
141 | ------------------------- | |
142 | ||
143 | function Is_Front_End_Switch (Switch_Chars : String) return Boolean is | |
07fc65c4 | 144 | Ptr : constant Positive := Switch_Chars'First; |
996ae0b0 RK |
145 | begin |
146 | return Is_Switch (Switch_Chars) | |
147 | and then | |
0da2c8ac AC |
148 | (Switch_Chars (Ptr + 1) = 'I' |
149 | or else (Switch_Chars'Length >= 5 | |
150 | and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat") | |
151 | or else (Switch_Chars'Length >= 5 | |
152 | and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS")); | |
996ae0b0 RK |
153 | end Is_Front_End_Switch; |
154 | ||
6e00e546 OH |
155 | ---------------------------- |
156 | -- Is_Internal_GCC_Switch -- | |
157 | ---------------------------- | |
158 | ||
159 | function Is_Internal_GCC_Switch (Switch_Chars : String) return Boolean is | |
160 | First : constant Natural := Switch_Chars'First + 1; | |
161 | Last : constant Natural := Switch_Last (Switch_Chars); | |
162 | begin | |
163 | return Is_Switch (Switch_Chars) | |
164 | and then | |
5132708f | 165 | (Switch_Chars (First .. Last) = "-param" or else |
1dedc12d | 166 | Switch_Chars (First .. Last) = "dumpdir" or else |
5132708f | 167 | Switch_Chars (First .. Last) = "dumpbase" or else |
1dedc12d | 168 | Switch_Chars (First .. Last) = "dumpbase-ext"); |
6e00e546 OH |
169 | end Is_Internal_GCC_Switch; |
170 | ||
996ae0b0 RK |
171 | --------------- |
172 | -- Is_Switch -- | |
173 | --------------- | |
174 | ||
175 | function Is_Switch (Switch_Chars : String) return Boolean is | |
176 | begin | |
177 | return Switch_Chars'Length > 1 | |
07fc65c4 | 178 | and then Switch_Chars (Switch_Chars'First) = '-'; |
996ae0b0 RK |
179 | end Is_Switch; |
180 | ||
6e00e546 | 181 | ----------------- |
8016e567 | 182 | -- Switch_Last -- |
6e00e546 OH |
183 | ----------------- |
184 | ||
185 | function Switch_Last (Switch_Chars : String) return Natural is | |
5132708f | 186 | Last : constant Natural := Switch_Chars'Last; |
6e00e546 OH |
187 | begin |
188 | if Last >= Switch_Chars'First | |
189 | and then Switch_Chars (Last) = ASCII.NUL | |
190 | then | |
5132708f RD |
191 | return Last - 1; |
192 | else | |
193 | return Last; | |
6e00e546 OH |
194 | end if; |
195 | end Switch_Last; | |
196 | ||
f7d7bb51 AC |
197 | ----------------- |
198 | -- Nat_Present -- | |
199 | ----------------- | |
200 | ||
201 | function Nat_Present | |
202 | (Switch_Chars : String; | |
203 | Max : Integer; | |
204 | Ptr : Integer) return Boolean | |
205 | is | |
206 | begin | |
207 | return (Ptr <= Max | |
208 | and then Switch_Chars (Ptr) in '0' .. '9') | |
209 | or else | |
210 | (Ptr < Max | |
211 | and then Switch_Chars (Ptr) = '=' | |
212 | and then Switch_Chars (Ptr + 1) in '0' .. '9'); | |
213 | end Nat_Present; | |
214 | ||
996ae0b0 RK |
215 | -------------- |
216 | -- Scan_Nat -- | |
217 | -------------- | |
218 | ||
219 | procedure Scan_Nat | |
220 | (Switch_Chars : String; | |
221 | Max : Integer; | |
222 | Ptr : in out Integer; | |
d4deddd7 VC |
223 | Result : out Nat; |
224 | Switch : Character) | |
07fc65c4 | 225 | is |
996ae0b0 RK |
226 | begin |
227 | Result := 0; | |
07fc65c4 | 228 | |
f7d7bb51 | 229 | if not Nat_Present (Switch_Chars, Max, Ptr) then |
3dd9959c | 230 | Osint.Fail ("missing numeric value for switch: " & Switch); |
f7d7bb51 | 231 | end if; |
d4deddd7 | 232 | |
f7d7bb51 AC |
233 | if Switch_Chars (Ptr) = '=' then |
234 | Ptr := Ptr + 1; | |
996ae0b0 | 235 | end if; |
f7d7bb51 AC |
236 | |
237 | while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop | |
238 | Result := | |
239 | Result * 10 + | |
240 | Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0'); | |
241 | Ptr := Ptr + 1; | |
242 | ||
243 | if Result > Switch_Max_Value then | |
244 | Osint.Fail ("numeric value out of range for switch: " & Switch); | |
245 | end if; | |
246 | end loop; | |
996ae0b0 RK |
247 | end Scan_Nat; |
248 | ||
249 | -------------- | |
250 | -- Scan_Pos -- | |
251 | -------------- | |
252 | ||
253 | procedure Scan_Pos | |
254 | (Switch_Chars : String; | |
255 | Max : Integer; | |
256 | Ptr : in out Integer; | |
d4deddd7 VC |
257 | Result : out Pos; |
258 | Switch : Character) | |
0da2c8ac | 259 | is |
fbf5a39b AC |
260 | Temp : Nat; |
261 | ||
996ae0b0 | 262 | begin |
d4deddd7 | 263 | Scan_Nat (Switch_Chars, Max, Ptr, Temp, Switch); |
07fc65c4 | 264 | |
fbf5a39b | 265 | if Temp = 0 then |
3dd9959c | 266 | Osint.Fail ("numeric value out of range for switch: " & Switch); |
996ae0b0 | 267 | end if; |
fbf5a39b AC |
268 | |
269 | Result := Temp; | |
996ae0b0 RK |
270 | end Scan_Pos; |
271 | ||
272 | end Switch; |