1 ------------------------------------------------------------------------------
4 -- Copyright (C) 2006-2010, 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;
229 function Get_Tabulation (L : in Lang) return Checks.Mode is
231 return L.C.Tabulation;
234 -------------------------
235 -- Get_Trailing_Spaces --
236 -------------------------
238 function Get_Trailing_Spaces (L : in Lang) return Checks.Mode is
240 return L.C.Trailing_Spaces;
241 end Get_Trailing_Spaces;
247 function Is_Extension (L : in Lang; Ext : in String) return Boolean is
248 pragma Unreferenced (L, Ext);
259 for K in 1 .. Index loop
261 L_Name : constant String := Name (Lang_Set (K).all);
263 if L_Name /= "unknown" then
264 Text_IO.Put_Line (" " & L_Name);
274 function Name (L : in Lang) return String is
276 return To_String (L.Name);
283 procedure Register (L : in Lang'Class; Name : in String) is
286 Lang_Set (Index) := new Lang'Class'(L
);
287 Lang_Set
(Index
).Name
:= To_Unbounded_String
(Name
);
290 ----------------------
291 -- Run_Syntax_Check --
292 ----------------------
294 function Run_Syntax_Check
295 (L
: in Lang
; Filename
: in String) return Boolean is
296 pragma Unreferenced
(L
, Filename
);
299 end Run_Syntax_Check
;
301 -------------------------
302 -- Set_Comment_Dot_EOL --
303 -------------------------
305 procedure Set_Comment_Dot_EOL
307 Mode
: in Boolean) is
310 for K
in 1 .. Index
loop
311 Set_Comment_Dot_EOL
(Lang_Set
(K
), Mode
);
315 L
.C
.Comment_Dot_EOL
:= Mode
;
317 end Set_Comment_Dot_EOL
;
319 ---------------------------
320 -- Set_Copyright_Pattern --
321 ---------------------------
323 procedure Set_Copyright_Pattern
325 Pattern
: in String) is
328 for K
in 1 .. Index
loop
329 Set_Copyright_Pattern
(Lang_Set
(K
), Pattern
);
333 L
.C
.Copyright_Pattern
:= To_Unbounded_String
(Pattern
);
335 end Set_Copyright_Pattern
;
337 ---------------------------
338 -- Set_Copyright_Present --
339 ---------------------------
341 procedure Set_Copyright_Present
343 Mode
: in Boolean) is
346 for K
in 1 .. Index
loop
347 Set_Copyright_Present
(Lang_Set
(K
), Mode
);
351 L
.C
.Copyright_Present
:= Mode
;
353 end Set_Copyright_Present
;
355 ------------------------
356 -- Set_Copyright_Year --
357 ------------------------
359 procedure Set_Copyright_Year
361 Mode
: in Boolean) is
364 for K
in 1 .. Index
loop
365 Set_Copyright_Year
(Lang_Set
(K
), Mode
);
369 L
.C
.Copyright_Year
:= Mode
;
371 end Set_Copyright_Year
;
373 ------------------------------
374 -- Set_Duplicate_Blank_Line --
375 ------------------------------
377 procedure Set_Duplicate_Blank_Line
379 Mode
: in Checks
.Mode
) is
382 for K
in 1 .. Index
loop
383 Set_Duplicate_Blank_Line
(Lang_Set
(K
), Mode
);
387 L
.C
.Duplicate_Blank_Line
:= Mode
;
389 end Set_Duplicate_Blank_Line
;
391 ---------------------
392 -- Set_Header_Size --
393 ---------------------
395 procedure Set_Header_Size
397 Size
: in Natural) is
400 for K
in 1 .. Index
loop
401 Set_Header_Size
(Lang_Set
(K
), Size
);
405 L
.C
.Header_Size
:= Size
;
409 ---------------------
410 -- Set_Line_Ending --
411 ---------------------
413 procedure Set_Line_Ending
415 Ending
: in Checks
.Line_Ending_Style
) is
418 for K
in 1 .. Index
loop
419 Set_Line_Ending
(Lang_Set
(K
), Ending
);
423 L
.C
.Line_Ending
:= Ending
;
427 -------------------------
428 -- Set_Line_Length_Max --
429 -------------------------
431 procedure Set_Line_Length_Max
433 Length
: in Positive) is
436 for K
in 1 .. Index
loop
437 Set_Line_Length_Max
(Lang_Set
(K
), Length
);
441 L
.C
.Line_Length_Max
:= Length
;
443 end Set_Line_Length_Max
;
445 -----------------------
446 -- Set_Space_Comment --
447 -----------------------
449 procedure Set_Space_Comment
451 Number
: in Natural) is
454 for K
in 1 .. Index
loop
455 Set_Space_Comment
(Lang_Set
(K
), Number
);
459 L
.C
.Space_Comment
:= Number
;
461 end Set_Space_Comment
;
463 ----------------------
464 -- Set_Syntax_Check --
465 ----------------------
467 procedure Set_Syntax_Check
469 Mode
: in Boolean) is
472 for K
in 1 .. Index
loop
473 Set_Syntax_Check
(Lang_Set
(K
), Mode
);
477 L
.C
.Check_Syntax
:= Mode
;
479 end Set_Syntax_Check
;
485 procedure Set_Tabulation
487 Mode
: in Checks
.Mode
) is
490 for K
in 1 .. Index
loop
491 Set_Tabulation
(Lang_Set
(K
), Mode
);
495 L
.C
.Tabulation
:= Mode
;
499 -------------------------
500 -- Set_Trailing_Spaces --
501 -------------------------
503 procedure Set_Trailing_Spaces
505 Mode
: in Checks
.Mode
) is
508 for K
in 1 .. Index
loop
509 Set_Trailing_Spaces
(Lang_Set
(K
), Mode
);
513 L
.C
.Trailing_Spaces
:= Mode
;
515 end Set_Trailing_Spaces
;
517 -----------------------------
518 -- Start_Multiline_Comment --
519 -----------------------------
521 function Start_Multiline_Comment
(L
: in Lang
) return String is
522 pragma Unreferenced
(L
);
525 end Start_Multiline_Comment
;