1 ------------------------------------------------------------------------------
4 -- Copyright (C) 2006-2008, 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
;
26 package body Languages
is
29 use Ada
.Characters
.Handling
;
31 Lang_Set
: array (1 .. 50) of Lang_Access
;
34 function Get_From_Name
(Name
: in String) return Lang
'Class;
35 -- Return a language given its name
37 ---------------------------------
38 -- Add_Style_Checker_Parameter --
39 ---------------------------------
41 procedure Add_Style_Checker_Parameter
43 Parameter
: in String) is
46 raise Checks
.Syntax_Error
;
49 L
.C
.Index
:= L
.C
.Index
+ 1;
51 if L
.C
.Index
> L
.C
.Checker_Params
'Last then
52 raise Checks
.Syntax_Error
;
54 L
.C
.Checker_Params
(L
.C
.Index
) := new String'(Parameter);
57 end Add_Style_Checker_Parameter;
63 function Comment (L : in Lang) return String is
64 pragma Unreferenced (L);
69 ---------------------------
70 -- End_Multiline_Comment --
71 ---------------------------
73 function End_Multiline_Comment (L : in Lang) return String is
74 pragma Unreferenced (L);
77 end End_Multiline_Comment;
83 function Get (Filename : in String) return Lang'Class is
84 Ext : aliased constant String := Directories.Extension (Filename);
85 Base : aliased constant String := Directories.Base_Name (Filename);
86 Check : access constant String;
94 for K in 1 .. Index loop
95 if Is_Extension (Lang_Set (K).all, Check.all) then
96 return Lang_Set (K).all;
100 return Get_From_Name ("unknown");
103 -------------------------
104 -- Get_Comment_Dot_EOL --
105 -------------------------
107 function Get_Comment_Dot_EOL (L : in Lang) return Boolean is
109 return L.C.Comment_Dot_EOL;
110 end Get_Comment_Dot_EOL;
112 ---------------------------
113 -- Get_Copyright_Pattern --
114 ---------------------------
116 function Get_Copyright_Pattern (L : in Lang) return String is
118 return To_String (L.C.Copyright_Pattern);
119 end Get_Copyright_Pattern;
121 ---------------------------
122 -- Get_Copyright_Present --
123 ---------------------------
125 function Get_Copyright_Present (L : in Lang) return Boolean is
127 return L.C.Copyright_Present;
128 end Get_Copyright_Present;
130 ------------------------
131 -- Get_Copyright_Year --
132 ------------------------
134 function Get_Copyright_Year (L : in Lang) return Boolean is
136 return L.C.Copyright_Year;
137 end Get_Copyright_Year;
139 ------------------------------
140 -- Get_Duplicate_Blank_Line --
141 ------------------------------
143 function Get_Duplicate_Blank_Line (L : in Lang) return Checks.Mode is
145 return L.C.Duplicate_Blank_Line;
146 end Get_Duplicate_Blank_Line;
152 function Get_From_Name (Name : in String) return Lang_Access is
153 L_Name : constant String := To_Lower (Name);
155 for K in 1 .. Index loop
156 if To_Lower (To_String (Lang_Set (K).Name)) = L_Name then
161 return Get_From_Name ("unknown");
164 function Get_From_Name (Name : in String) return Lang'Class is
166 return Get_From_Name (Name).all;
169 ---------------------
170 -- Get_Header_Size --
171 ---------------------
173 function Get_Header_Size (L : in Lang) return Natural is
175 return L.C.Header_Size;
178 ---------------------
179 -- Get_Line_Ending --
180 ---------------------
182 function Get_Line_Ending
183 (L : in Lang) return Checks.Line_Ending_Style is
185 return L.C.Line_Ending;
188 -------------------------
189 -- Get_Line_Length_Max --
190 -------------------------
192 function Get_Line_Length_Max (L : in Lang) return Positive is
194 return L.C.Line_Length_Max;
195 end Get_Line_Length_Max;
197 -----------------------
198 -- Get_Space_Comment --
199 -----------------------
201 function Get_Space_Comment (L : in Lang) return Natural is
203 return L.C.Space_Comment;
204 end Get_Space_Comment;
206 ----------------------------------
207 -- Get_Style_Checker_Parameters --
208 ----------------------------------
210 function Get_Style_Checker_Parameters
211 (L : in Lang) return GNAT.OS_Lib.Argument_List is
213 return L.C.Checker_Params (1 .. L.C.Index);
214 end Get_Style_Checker_Parameters;
216 ----------------------
217 -- Get_Syntax_Check --
218 ----------------------
220 function Get_Syntax_Check (L : in Lang) return Boolean is
222 return L.C.Check_Syntax;
223 end Get_Syntax_Check;
225 -------------------------
226 -- Get_Trailing_Spaces --
227 -------------------------
229 function Get_Trailing_Spaces (L : in Lang) return Checks.Mode is
231 return L.C.Trailing_Spaces;
232 end Get_Trailing_Spaces;
238 function Is_Extension (L : in Lang; Ext : in String) return Boolean is
239 pragma Unreferenced (L, Ext);
250 for K in 1 .. Index loop
252 L_Name : constant String := Name (Lang_Set (K).all);
254 if L_Name /= "unknown" then
255 Text_IO.Put_Line (" " & L_Name);
265 function Name (L : in Lang) return String is
267 return To_String (L.Name);
274 procedure Register (L : in Lang'Class; Name : in String) is
277 Lang_Set (Index) := new Lang'Class'(L
);
278 Lang_Set
(Index
).Name
:= To_Unbounded_String
(Name
);
281 ----------------------
282 -- Run_Syntax_Check --
283 ----------------------
285 function Run_Syntax_Check
286 (L
: in Lang
; Filename
: in String) return Boolean is
287 pragma Unreferenced
(L
, Filename
);
290 end Run_Syntax_Check
;
292 -------------------------
293 -- Set_Comment_Dot_EOL --
294 -------------------------
296 procedure Set_Comment_Dot_EOL
298 Mode
: in Boolean) is
301 for K
in 1 .. Index
loop
302 Set_Comment_Dot_EOL
(Lang_Set
(K
), Mode
);
306 L
.C
.Comment_Dot_EOL
:= Mode
;
308 end Set_Comment_Dot_EOL
;
310 ---------------------------
311 -- Set_Copyright_Pattern --
312 ---------------------------
314 procedure Set_Copyright_Pattern
316 Pattern
: in String) is
319 for K
in 1 .. Index
loop
320 Set_Copyright_Pattern
(Lang_Set
(K
), Pattern
);
324 L
.C
.Copyright_Pattern
:= To_Unbounded_String
(Pattern
);
326 end Set_Copyright_Pattern
;
328 ---------------------------
329 -- Set_Copyright_Present --
330 ---------------------------
332 procedure Set_Copyright_Present
334 Mode
: in Boolean) is
337 for K
in 1 .. Index
loop
338 Set_Copyright_Present
(Lang_Set
(K
), Mode
);
342 L
.C
.Copyright_Present
:= Mode
;
344 end Set_Copyright_Present
;
346 ------------------------
347 -- Set_Copyright_Year --
348 ------------------------
350 procedure Set_Copyright_Year
352 Mode
: in Boolean) is
355 for K
in 1 .. Index
loop
356 Set_Copyright_Year
(Lang_Set
(K
), Mode
);
360 L
.C
.Copyright_Year
:= Mode
;
362 end Set_Copyright_Year
;
364 ------------------------------
365 -- Set_Duplicate_Blank_Line --
366 ------------------------------
368 procedure Set_Duplicate_Blank_Line
370 Mode
: in Checks
.Mode
) is
373 for K
in 1 .. Index
loop
374 Set_Duplicate_Blank_Line
(Lang_Set
(K
), Mode
);
378 L
.C
.Duplicate_Blank_Line
:= Mode
;
380 end Set_Duplicate_Blank_Line
;
382 ---------------------
383 -- Set_Header_Size --
384 ---------------------
386 procedure Set_Header_Size
388 Size
: in Natural) is
391 for K
in 1 .. Index
loop
392 Set_Header_Size
(Lang_Set
(K
), Size
);
396 L
.C
.Header_Size
:= Size
;
400 ---------------------
401 -- Set_Line_Ending --
402 ---------------------
404 procedure Set_Line_Ending
406 Ending
: in Checks
.Line_Ending_Style
) is
409 for K
in 1 .. Index
loop
410 Set_Line_Ending
(Lang_Set
(K
), Ending
);
414 L
.C
.Line_Ending
:= Ending
;
418 -------------------------
419 -- Set_Line_Length_Max --
420 -------------------------
422 procedure Set_Line_Length_Max
424 Length
: in Positive) is
427 for K
in 1 .. Index
loop
428 Set_Line_Length_Max
(Lang_Set
(K
), Length
);
432 L
.C
.Line_Length_Max
:= Length
;
434 end Set_Line_Length_Max
;
436 -----------------------
437 -- Set_Space_Comment --
438 -----------------------
440 procedure Set_Space_Comment
442 Number
: in Natural) is
445 for K
in 1 .. Index
loop
446 Set_Space_Comment
(Lang_Set
(K
), Number
);
450 L
.C
.Space_Comment
:= Number
;
452 end Set_Space_Comment
;
454 ----------------------
455 -- Set_Syntax_Check --
456 ----------------------
458 procedure Set_Syntax_Check
460 Mode
: in Boolean) is
463 for K
in 1 .. Index
loop
464 Set_Syntax_Check
(Lang_Set
(K
), Mode
);
468 L
.C
.Check_Syntax
:= Mode
;
470 end Set_Syntax_Check
;
472 -------------------------
473 -- Set_Trailing_Spaces --
474 -------------------------
476 procedure Set_Trailing_Spaces
478 Mode
: in Checks
.Mode
) is
481 for K
in 1 .. Index
loop
482 Set_Trailing_Spaces
(Lang_Set
(K
), Mode
);
486 L
.C
.Trailing_Spaces
:= Mode
;
488 end Set_Trailing_Spaces
;
490 -----------------------------
491 -- Start_Multiline_Comment --
492 -----------------------------
494 function Start_Multiline_Comment
(L
: in Lang
) return String is
495 pragma Unreferenced
(L
);
498 end Start_Multiline_Comment
;