1 ------------------------------------------------------------------------------
4 -- Copyright (C) 2006, Pascal Obry --
6 -- This library is free software; you can redistribute it and/or modify --
7 -- it under the terms of the GNU General Public License as published by --
8 -- the Free Software Foundation; either version 2 of the License, or (at --
9 -- your option) any later version. --
11 -- This library is distributed in the hope that it will be useful, but --
12 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
14 -- General Public License for more details. --
16 -- You should have received a copy of the GNU General Public License --
17 -- along with this library; if not, write to the Free Software Foundation, --
18 -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
20 ------------------------------------------------------------------------------
22 with Ada
.Characters
.Handling
;
24 with Ada
.Strings
.Unbounded
;
27 package body Languages
is
30 use Ada
.Strings
.Unbounded
;
31 use Ada
.Characters
.Handling
;
33 Lang_Set
: array (1 .. 50) of Lang_Access
;
36 function Get_From_Name
(Name
: in String) return Lang
'Class;
37 -- Return a language given its name
39 ---------------------------------
40 -- Add_Style_Checker_Parameter --
41 ---------------------------------
43 procedure Add_Style_Checker_Parameter
45 Parameter
: in String) is
48 raise Checks
.Syntax_Error
;
51 L
.C
.Index
:= L
.C
.Index
+ 1;
53 if L
.C
.Index
> L
.C
.Checker_Params
'Last then
54 raise Checks
.Syntax_Error
;
56 L
.C
.Checker_Params
(L
.C
.Index
) := new String'(Parameter);
59 end Add_Style_Checker_Parameter;
65 function Comment (L : in Lang) return String is
70 ----------------------
71 -- Run_Syntax_Check --
72 ----------------------
74 function Run_Syntax_Check
75 (L : in Lang; Filename : in String) return Boolean is
84 function Get (Filename : in String) return Lang'Class is
85 Ext : constant String := Directories.Extension (Filename);
87 for K in 1 .. Index loop
88 if Is_Extension (Lang_Set (K).all, Ext) then
89 return Lang_Set (K).all;
93 return Get_From_Name ("unknown");
96 ---------------------------
97 -- Get_Copyright_Pattern --
98 ---------------------------
100 function Get_Copyright_Pattern (L : in Lang) return String is
102 return To_String (L.C.Copyright_Pattern);
103 end Get_Copyright_Pattern;
109 function Get_From_Name (Name : in String) return Lang_Access is
110 L_Name : constant String := To_Lower (Name);
112 for K in 1 .. Index loop
113 if To_Lower (To_String (Lang_Set (K).Name)) = L_Name then
118 return Get_From_Name ("unknown");
121 function Get_From_Name (Name : in String) return Lang'Class is
123 return Get_From_Name (Name).all;
130 function Is_Extension (L : in Lang; Ext : in String) return Boolean is
141 for K in 1 .. Index loop
143 L_Name : constant String := Name (Lang_Set (K).all);
145 if L_Name /= "unknown" then
146 Text_IO.Put_Line (" " & L_Name);
156 function Name (L : in Lang) return String is
158 return To_String (L.Name);
165 procedure Register (L : in Lang'Class; Name : in String) is
168 Lang_Set (Index) := new Lang'Class'(L
);
169 Lang_Set
(Index
).Name
:= To_Unbounded_String
(Name
);
172 ---------------------------
173 -- Set_Copyright_Pattern --
174 ---------------------------
176 procedure Set_Copyright_Pattern
178 Pattern
: in String) is
181 for K
in 1 .. Index
loop
182 Set_Copyright_Pattern
(Lang_Set
(K
), Pattern
);
186 L
.C
.Copyright_Pattern
:= To_Unbounded_String
(Pattern
);
188 end Set_Copyright_Pattern
;
190 ------------------------------
191 -- Set_Duplicate_Blank_Line --
192 ------------------------------
194 procedure Set_Duplicate_Blank_Line
196 Mode
: in Checks
.Mode
) is
199 for K
in 1 .. Index
loop
200 Set_Duplicate_Blank_Line
(Lang_Set
(K
), Mode
);
204 L
.C
.Duplicate_Blank_Line
:= Mode
;
206 end Set_Duplicate_Blank_Line
;
208 ---------------------
209 -- Set_Line_Ending --
210 ---------------------
212 procedure Set_Line_Ending
214 Ending
: in Checks
.Line_Ending_Style
) is
217 for K
in 1 .. Index
loop
218 Set_Line_Ending
(Lang_Set
(K
), Ending
);
222 L
.C
.Line_Ending
:= Ending
;
226 -------------------------
227 -- Set_Line_Length_Max --
228 -------------------------
230 procedure Set_Line_Length_Max
232 Length
: in Positive) is
235 for K
in 1 .. Index
loop
236 Set_Line_Length_Max
(Lang_Set
(K
), Length
);
240 L
.C
.Line_Length_Max
:= Length
;
242 end Set_Line_Length_Max
;
244 -----------------------
245 -- Set_Space_Comment --
246 -----------------------
248 procedure Set_Space_Comment
250 Number
: in Natural) is
253 for K
in 1 .. Index
loop
254 Set_Space_Comment
(Lang_Set
(K
), Number
);
258 L
.C
.Space_Comment
:= Number
;
260 end Set_Space_Comment
;
262 ---------------------
263 -- Set_Header_Size --
264 ---------------------
266 procedure Set_Header_Size
268 Size
: in Natural) is
271 for K
in 1 .. Index
loop
272 Set_Header_Size
(Lang_Set
(K
), Size
);
276 L
.C
.Header_Size
:= Size
;
280 ---------------------------
281 -- Set_Copyright_Present --
282 ---------------------------
284 procedure Set_Copyright_Present
286 Mode
: in Boolean) is
289 for K
in 1 .. Index
loop
290 Set_Copyright_Present
(Lang_Set
(K
), Mode
);
294 L
.C
.Copyright_Present
:= Mode
;
296 end Set_Copyright_Present
;
298 ------------------------
299 -- Set_Copyright_Year --
300 ------------------------
302 procedure Set_Copyright_Year
304 Mode
: in Boolean) is
307 for K
in 1 .. Index
loop
308 Set_Copyright_Year
(Lang_Set
(K
), Mode
);
312 L
.C
.Copyright_Year
:= Mode
;
314 end Set_Copyright_Year
;
316 ----------------------
317 -- Set_Syntax_Check --
318 ----------------------
320 procedure Set_Syntax_Check
322 Mode
: in Boolean) is
325 for K
in 1 .. Index
loop
326 Set_Syntax_Check
(Lang_Set
(K
), Mode
);
330 L
.C
.Check_Syntax
:= Mode
;
332 end Set_Syntax_Check
;
334 -------------------------
335 -- Set_Trailing_Spaces --
336 -------------------------
338 procedure Set_Trailing_Spaces
340 Mode
: in Checks
.Mode
) is
343 for K
in 1 .. Index
loop
344 Set_Trailing_Spaces
(Lang_Set
(K
), Mode
);
348 L
.C
.Trailing_Spaces
:= Mode
;
350 end Set_Trailing_Spaces
;
352 ---------------------------
353 -- Get_Copyright_Present --
354 ---------------------------
356 function Get_Copyright_Present
(L
: in Lang
) return Boolean is
358 return L
.C
.Copyright_Present
;
359 end Get_Copyright_Present
;
361 ------------------------
362 -- Get_Copyright_Year --
363 ------------------------
365 function Get_Copyright_Year
(L
: in Lang
) return Boolean is
367 return L
.C
.Copyright_Year
;
368 end Get_Copyright_Year
;
370 ------------------------------
371 -- Get_Duplicate_Blank_Line --
372 ------------------------------
374 function Get_Duplicate_Blank_Line
(L
: in Lang
) return Checks
.Mode
is
376 return L
.C
.Duplicate_Blank_Line
;
377 end Get_Duplicate_Blank_Line
;
379 ---------------------
380 -- Get_Header_Size --
381 ---------------------
383 function Get_Header_Size
(L
: in Lang
) return Natural is
385 return L
.C
.Header_Size
;
388 ---------------------
389 -- Get_Line_Ending --
390 ---------------------
392 function Get_Line_Ending
393 (L
: in Lang
) return Checks
.Line_Ending_Style
is
395 return L
.C
.Line_Ending
;
398 -------------------------
399 -- Get_Line_Length_Max --
400 -------------------------
402 function Get_Line_Length_Max
(L
: in Lang
) return Positive is
404 return L
.C
.Line_Length_Max
;
405 end Get_Line_Length_Max
;
407 -----------------------
408 -- Get_Space_Comment --
409 -----------------------
411 function Get_Space_Comment
(L
: in Lang
) return Natural is
413 return L
.C
.Space_Comment
;
414 end Get_Space_Comment
;
416 ----------------------
417 -- Get_Syntax_Check --
418 ----------------------
420 function Get_Syntax_Check
(L
: in Lang
) return Boolean is
422 return L
.C
.Check_Syntax
;
423 end Get_Syntax_Check
;
425 -------------------------
426 -- Get_Trailing_Spaces --
427 -------------------------
429 function Get_Trailing_Spaces
(L
: in Lang
) return Checks
.Mode
is
431 return L
.C
.Trailing_Spaces
;
432 end Get_Trailing_Spaces
;
434 ----------------------------------
435 -- Get_Style_Checker_Parameters --
436 ----------------------------------
438 function Get_Style_Checker_Parameters
439 (L
: in Lang
) return GNAT
.OS_Lib
.Argument_List
is
441 return L
.C
.Checker_Params
(1 .. L
.C
.Index
);
442 end Get_Style_Checker_Parameters
;