1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
29 package body Stylesw is
31 -------------------------------
32 -- Reset_Style_Check_Options --
33 -------------------------------
35 procedure Reset_Style_Check_Options is
37 Style_Check_Indentation := 0;
38 Style_Check_Attribute_Casing := False;
39 Style_Check_Blanks_At_End := False;
40 Style_Check_Comments := False;
41 Style_Check_DOS_Line_Terminator := False;
42 Style_Check_End_Labels := False;
43 Style_Check_Form_Feeds := False;
44 Style_Check_Horizontal_Tabs := False;
45 Style_Check_If_Then_Layout := False;
46 Style_Check_Keyword_Casing := False;
47 Style_Check_Layout := False;
48 Style_Check_Max_Line_Length := False;
49 Style_Check_Max_Nesting_Level := False;
50 Style_Check_Order_Subprograms := False;
51 Style_Check_Pragma_Casing := False;
52 Style_Check_References := False;
53 Style_Check_Specs := False;
54 Style_Check_Standard := False;
55 Style_Check_Tokens := False;
56 Style_Check_Xtra_Parens := False;
57 end Reset_Style_Check_Options;
59 ------------------------------
60 -- Save_Style_Check_Options --
61 ------------------------------
63 procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
66 procedure Add (C : Character; S : Boolean);
67 -- Add given character C to string if switch S is true
69 procedure Add_Nat (N : Nat);
70 -- Add given natural number to string
76 procedure Add (C : Character; S : Boolean) is
88 procedure Add_Nat (N : Nat) is
95 Options (P) := Character'Val (Character'Pos ('0') + N mod 10);
98 -- Start of processing for Save_Style_Check_Options
101 for K in Options'Range loop
105 Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
106 Style_Check_Indentation /= 0);
108 Add ('a', Style_Check_Attribute_Casing);
109 Add ('b', Style_Check_Blanks_At_End);
110 Add ('c', Style_Check_Comments);
111 Add ('d', Style_Check_DOS_Line_Terminator);
112 Add ('e', Style_Check_End_Labels);
113 Add ('f', Style_Check_Form_Feeds);
114 Add ('h', Style_Check_Horizontal_Tabs);
115 Add ('i', Style_Check_If_Then_Layout);
116 Add ('k', Style_Check_Keyword_Casing);
117 Add ('l', Style_Check_Layout);
118 Add ('n', Style_Check_Standard);
119 Add ('o', Style_Check_Order_Subprograms);
120 Add ('p', Style_Check_Pragma_Casing);
121 Add ('r', Style_Check_References);
122 Add ('s', Style_Check_Specs);
123 Add ('t', Style_Check_Tokens);
124 Add ('x', Style_Check_Xtra_Parens);
126 if Style_Check_Max_Line_Length then
129 Add_Nat (Style_Max_Line_Length);
132 if Style_Check_Max_Nesting_Level then
135 Add_Nat (Style_Max_Nesting_Level);
138 pragma Assert (P <= Options'Last);
140 while P < Options'Last loop
144 end Save_Style_Check_Options;
146 -------------------------------------
147 -- Set_Default_Style_Check_Options --
148 -------------------------------------
150 procedure Set_Default_Style_Check_Options is
152 Reset_Style_Check_Options;
153 Set_Style_Check_Options ("3abcefhiklmnprst");
154 end Set_Default_Style_Check_Options;
156 -----------------------------
157 -- Set_Style_Check_Options --
158 -----------------------------
160 -- Version used when no error checking is required
162 procedure Set_Style_Check_Options (Options : String) is
166 Set_Style_Check_Options (Options, OK, EC);
167 end Set_Style_Check_Options;
169 -- Normal version with error checking
171 procedure Set_Style_Check_Options
174 Err_Col : out Natural)
181 while J <= Options'Last loop
187 Style_Check_Indentation
188 := Character'Pos (C) - Character'Pos ('0');
191 Style_Check_Attribute_Casing := True;
194 Style_Check_Blanks_At_End := True;
197 Style_Check_Comments := True;
200 Style_Check_DOS_Line_Terminator := True;
203 Style_Check_End_Labels := True;
206 Style_Check_Form_Feeds := True;
209 Style_Check_Horizontal_Tabs := True;
212 Style_Check_If_Then_Layout := True;
215 Style_Check_Keyword_Casing := True;
218 Style_Check_Layout := True;
221 Style_Max_Nesting_Level := 0;
224 or else Options (J) not in '0' .. '9'
232 Style_Max_Nesting_Level :=
233 Style_Max_Nesting_Level * 10 +
234 Character'Pos (Options (J)) - Character'Pos ('0');
236 if Style_Max_Nesting_Level > 999 then
243 exit when J > Options'Last
244 or else Options (J) not in '0' .. '9';
247 Style_Check_Max_Nesting_Level := Style_Max_Nesting_Level /= 0;
250 Style_Check_Max_Line_Length := True;
251 Style_Max_Line_Length := 79;
254 Style_Check_Standard := True;
257 Reset_Style_Check_Options;
260 Style_Max_Line_Length := 0;
263 or else Options (J) not in '0' .. '9'
271 Style_Max_Line_Length :=
272 Style_Max_Line_Length * 10 +
273 Character'Pos (Options (J)) - Character'Pos ('0');
275 if Style_Max_Line_Length > Int (Column_Number'Last) then
282 exit when J > Options'Last
283 or else Options (J) not in '0' .. '9';
286 Style_Check_Max_Line_Length := Style_Max_Line_Length /= 0;
289 Style_Check_Order_Subprograms := True;
292 Style_Check_Pragma_Casing := True;
295 Style_Check_References := True;
298 Style_Check_Specs := True;
301 Style_Check_Tokens := True;
304 Style_Check_Xtra_Parens := True;
318 Err_Col := Options'Last + 1;
319 end Set_Style_Check_Options;