1
----------------------------------------------------------------------
2
-- Adactl_Options - Package body --
4
-- This software is (c) The European Organisation for the Safety --
5
-- of Air Navigation (EUROCONTROL) and Adalog 2004-2005. The Ada --
6
-- Controller is free software; you can redistribute it and/or --
7
-- modify it under terms of the GNU General Public License as --
8
-- published by the Free Software Foundation; either version 2, or --
9
-- (at your option) any later version. This unit is distributed --
10
-- in the hope that it will be useful, but WITHOUT ANY WARRANTY; --
11
-- without even the implied warranty of MERCHANTABILITY or FITNESS --
12
-- FOR A PARTICULAR PURPOSE. See the GNU General Public License --
13
-- for more details. You should have received a copy of the GNU --
14
-- General Public License distributed with this program; see file --
15
-- COPYING. If not, write to the Free Software Foundation, 59 --
16
-- Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
18
-- As a special exception, if other files instantiate generics --
19
-- from the units of this program, or if you link this unit with --
20
-- other files to produce an executable, this unit does not by --
21
-- itself cause the resulting executable to be covered by the GNU --
22
-- General Public License. This exception does not however --
23
-- invalidate any other reasons why the executable file might be --
24
-- covered by the GNU Public License. --
26
-- This software is distributed in the hope that it will be --
27
-- useful, but WITHOUT ANY WARRANTY; without even the implied --
28
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR --
30
----------------------------------------------------------------------
3
34
Ada.Characters.Handling,
4
35
Ada.Strings.Wide_Fixed,
5
36
Ada.Strings.Wide_Maps,
6
37
Ada.Strings.Wide_Unbounded,
52
80
pragma No_Return (Option_Error);
59
use Utilities, Framework.Rules_Manager;
86
procedure Help_Options is
87
use Utilities, Framework.Reports;
61
89
User_Message ("Usage: adactl [-deirsuvw] [-f <rules file>] [-l <rules list>] [-o <output file>]");
62
90
User_Message (" [-p <project file>] <unit>[+|-<unit>]|[@]<file> ... [-- <ASIS options>]");
63
91
User_Message (" adactl -h [<rule id>... | all]");
64
User_Message (" adactl -I [-deirsuvw] [-o <output file>]");
92
User_Message (" adactl -I [-deirsuvw] [-f <rules file>] [-l <rules list>] [-o <output file>]");
65
93
User_Message (" [-p <project file>] <unit>[+|-<unit>]|[@]<file> ... [-- <ASIS options>]");
66
94
User_Message (" adactl -D [-rsw] [-o <output file>]");
67
95
User_Message (" [-p <project file>] <unit>[+|-<unit>]|[@]<file> ... [-- <ASIS options>]");
96
User_Message (" adactl -C [-dv] [-f <rules file>] [-l <rules list>]");
99
User_Message ("Special modes:");
100
User_Message (" -h prints this help message");
101
User_Message (" -h rule prints rule help");
102
User_Message (" -h all prints all rules help");
103
User_Message (" -I interactive mode");
104
User_Message (" -D generate dependencies");
105
User_Message (" -C check rules syntax only");
70
106
User_Message ("Options:");
71
User_Message (" -d enable debug mode");
72
User_Message (" -e treat warnnings (Search) as errors (Check)");
73
User_Message (" -f file use a file for the specification of rules");
74
User_Message (" -h prints this help message");
75
User_Message (" -h rule prints rule help");
76
User_Message (" -h all prints all rules help");
77
User_Message (" -i ignore local deactivations");
78
User_Message (" -l rules process with this rules");
79
User_Message (" -o file specify an output file");
80
User_Message (" -p file specify an emacs ada-mode project file (.adp)");
81
User_Message (" -r recursive");
82
User_Message (" -s process specifications only");
83
User_Message (" -u treat all parameters as Ada units");
84
User_Message (" -v enable verbose mode");
85
User_Message (" -w overwrite output file (works with -o)");
86
User_Message (" -x exit when internal error");
87
User_Message ("Rules:");
90
User_Message ("ADACTL v. " & Version);
91
User_Message ("Copyright (C) 2004-2005 Eurocontrol/Adalog.");
92
User_Message ("This software is covered by the GNU Modified General Public License.");
107
User_Message (" -d enable debug mode");
108
User_Message (" -e treat warnings (Search) as errors (Check)");
109
User_Message (" -E print only errors (Check)");
110
User_Message (" -f file use a file for the specification of rules");
111
User_Message (" -F format choose output format (GNAT, GNAT_SHORT, CSV, CSV_SHORT, CSVX, CSVX_SHORT)");
112
User_Message (" -i ignore local deactivations");
113
User_Message (" -l rules process with these rules");
114
User_Message (" -o file specify an output file");
115
User_Message (" -p file specify an emacs ada-mode project file (.adp)");
116
User_Message (" -r recursive");
117
User_Message (" -s process specifications only");
118
User_Message (" -S statistics level (0 .."
119
& Integer'Wide_Image (Stats_Levels'Pos (Stats_Levels'Last))
121
User_Message (" -t file specify a trace file");
122
User_Message (" -u treat all parameters as Ada units");
123
User_Message (" -v enable verbose mode");
124
User_Message (" -w overwrite output file (works with -o)");
125
User_Message (" -x exit when internal error");
95
128
--------------------
96
129
-- Gnat_Unit_Name --
97
130
--------------------
99
132
function Gnat_Unit_Name (S : in Wide_String) return Wide_String is
100
use Ada.Characters.Handling;
102
134
use Ada.Strings.Wide_Maps;
103
135
use Ada.Strings.Wide_Fixed;
131
163
procedure Add_Unit (S : in Wide_String) is
132
use Utilities, Ada.Strings.Wide_Fixed, Ada.Strings.Wide_Unbounded;
164
use Utilities, Ada.Strings, Ada.Strings.Wide_Fixed, Ada.Strings.Wide_Unbounded;
134
166
Ext : constant Wide_String := To_Upper (Tail (S, 4));
168
procedure Add_Parents (Unit : Wide_String) is
169
-- Add parents of the given unit *before* the unit, in order to make sure
170
-- that a parent unit is always processed before its children.
171
Point_Pos : constant Natural := Index (Unit, ".", Going => Backward);
173
if Point_Pos = 0 then
177
if Point_Pos = Unit'First then
178
-- Name starts with '.'
179
-- Can happen if the user gives "../name" instead of "../name.adb"
180
Option_Error ("Illegal syntax for a unit (not file) name");
183
Add_Parents (Unit (Unit'First .. Point_Pos - 1));
184
Append (Unit_List, "+" & Unit (Unit'First .. Point_Pos - 1));
187
if S(S'First) = '@' then
189
Append (Unit_List, S);
136
193
if not Unit_Option and (Ext = ".ADS" or Ext = ".ADB") then
137
194
-- Take it as a file name
138
195
if Ext = ".ADB" then
139
196
Body_Found := True;
142
if Unit_List = Null_Unbounded_Wide_String then
143
Unit_List := To_Unbounded_Wide_String (Gnat_Unit_Name (S));
145
Append (Unit_List, "+" & Gnat_Unit_Name (S));
199
Unit : constant Wide_String := Gnat_Unit_Name (S);
202
Append (Unit_List, "+" & Unit);
150
207
Body_Found := True;
151
if Unit_List = Null_Unbounded_Wide_String then
152
Unit_List := To_Unbounded_Wide_String (S);
153
elsif S(1) = '+' or S(1) = '-' then
154
Append (Unit_List, S);
156
Append (Unit_List, "+" & S);
210
Add_Parents (S (S'First+1..S'Last));
211
Append (Unit_List, S);
213
Append (Unit_List, S);
216
Append (Unit_List, "+" & S);
163
223
---------------------
165
225
procedure Analyse_Options is
166
use Ada.Wide_Text_Io, Ada.Characters.Handling, Ada.Strings.Wide_Fixed,
167
Ada.Strings, Ada.Strings.Wide_Unbounded;
168
use Utilities, Analyzer, Framework.Rules_Manager;
226
use Ada.Characters.Handling, Ada.Strings, Ada.Strings.Wide_Fixed, Ada.Strings.Wide_Unbounded;
227
use Utilities, Analyzer;
173
232
if Is_Present (Option => 'h') then
176
234
if Parameter_Count = 0 then
179
for I in 1.. Parameter_Count loop
181
Val : constant Wide_String := To_Wide_String (Parameter (I));
183
if To_Upper (Val) = "ALL" then
184
Framework.Rules_Manager.Help_All;
186
Framework.Rules_Manager.Help (Val);
238
for I in Natural range 1.. Parameter_Count loop
239
Options_Commands := Options_Commands & "help " & To_Wide_String (Parameter (I)) & ';';
245
elsif Is_Present (Option => 'C') then -- Must be first for -C to override any other option (except help)
194
248
elsif Is_Present (Option => 'D') then
195
249
Action := Dependents;
211
265
Utilities.Verbose_Option := Is_Present (Option => 'v');
212
266
Overwrite_Option := Is_Present (Option => 'w');
268
if Is_Present (Option => 'S') then
270
Temp_Value : Integer;
271
use Framework.Reports;
273
Temp_Value := Value ('S',
274
Default => Stats_Levels'Pos (Stats_Levels'Last),
275
Explicit_Required => False);
276
if Temp_Value not in 0 .. Stats_Levels'Pos (Stats_Levels'Last) then
277
Option_Error ("Value for S option must be in range 0 .."
278
& Integer'Image (Stats_Levels'Pos (Stats_Levels'Last)));
280
Options_Commands := Options_Commands
281
& "set statistics" & Integer'Wide_Image (Temp_Value) & ';';
214
285
if Is_Present (Option => 'o') then
215
286
-- modify current output
216
287
Options_Commands := Options_Commands
217
288
& "set output " & To_Wide_String (Value (Option => 'o', Explicit_Required => True)) & ';';
291
if Is_Present (Option => 't') then
292
-- modify current trace
293
Options_Commands := Options_Commands
294
& "set trace " & To_Wide_String (Value (Option => 't', Explicit_Required => True)) & ';';
220
297
Framework.Reports.Warning_As_Error_Option := Is_Present (Option => 'e');
298
Framework.Reports.Skip_Warning_Option := Is_Present (Option => 'E');
222
300
-- Process options
223
301
Recursive_Option := Is_Present (Option => 'r');
226
304
Spec_Option := Is_Present (Option => 's');
227
305
Exit_Option := Is_Present (Option => 'x');
229
if Parameter_Count = 0 then
307
if Action /= Check and Parameter_Count = 0 then
230
308
Option_Error ("At least one unit/file required");
233
if Is_Present (Option => 'D') then
311
if Action = Dependents then
234
312
if Is_Present (Option => 'l') or Is_Present (Option => 'f') then
235
313
Option_Error ("No rule can be specified with -D option");
236
314
elsif Is_Present (Option => 'I') then
237
315
Option_Error ("-D and -I options cannot be specified together");
239
elsif not Is_Present (Option => 'l')
317
elsif Action /= Interactive_Process
318
and not Is_Present (Option => 'l')
240
319
and not Is_Present (Option => 'f')
241
and not Is_Present (Option => 'I')
243
321
Option_Error("No rules specified");
324
if Is_Present (Option => 'F') then
326
Options_Commands := Options_Commands
327
& "set format " & To_Wide_String (Value (Option => 'F', Explicit_Required => True)) & ';';
246
330
if Is_Present (Option => 'l') then
247
331
-- add rules uses from command line
248
332
Options_Commands := Options_Commands
260
344
& "source " & To_Wide_String (Value (Option => 'f', Explicit_Required => True)) & ';';
263
for I in 1 .. Parameter_Count loop
264
Add_Unit (To_Wide_String (Parameter (I)));
266
Spec_Option := Spec_Option or not Body_Found;
347
if Action /= Check then
348
for I in Natural range 1 .. Parameter_Count loop
349
Add_Unit (To_Wide_String (Parameter (I)));
351
Spec_Option := Spec_Option or not Body_Found;
269
355
when Occur : Analyzer.Options_Error =>
270
356
Option_Error (Occur);
271
357
when Overwrite_Error =>
272
Option_Error ("File " & Value (Option => 'o')
273
& " already exists, use ""-w"" to overwrite");
358
Option_Error ("File " & Value (Option => 'o') & " already exists, use ""-w"" to overwrite");
275
359
end Analyse_Options;
277
361
------------------