2 ["Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen";
3 "Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller";
4 "This file is part of Coccinelle.";
6 "Coccinelle 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, according to version 2 of the License.";
10 "Coccinelle is distributed in the hope that it will be useful,";
11 "but WITHOUT ANY WARRANTY; without even the implied warranty of";
12 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the";
13 "GNU General Public License for more details.";
15 "You should have received a copy of the GNU General Public License";
16 "along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.";
18 "The authors reserve the right to distribute this or future versions of";
19 "Coccinelle under other licenses."
22 let c_lines = "/*" :: (List.map
(function x
-> "* "^x
) lines) @ ["*/"]
24 let ml_lines = "(*" :: (List.map
(function x
-> "* "^x
) lines) @ ["*)"]
26 let make_lines = (List.map
(function x
-> "# "^x
) lines)
30 if Filename.check_suffix file
".mly" then c_lines else
31 if Filename.check_suffix file
".ml" then ml_lines else
32 if Filename.check_suffix file
".mll" then ml_lines else
33 if Filename.basename file
= "Makefile" then make_lines else
34 failwith
(Printf.sprintf
"unknown file type: %s" file
) in
35 let _ = Sys.command
(Printf.sprintf
"cp %s /tmp/tmpfl" file
) in
36 let o = open_out file
in
37 List.iter
(function l
-> Printf.fprintf
o "%s\n" l
) lines;
38 Printf.fprintf
o "\n";
39 Printf.fprintf
o "\n";
41 let _ = Sys.command
(Printf.sprintf
"cat /tmp/tmpfl >> %s" file
) in
47 let chan = open_in file
in
48 let rec cat_aux acc
() =
49 (* cant do input_line chan::aux() cos ocaml eval from right to left ! *)
50 let (b
, l
) = try (true, input_line
chan) with End_of_file
-> (false, "") in
52 then cat_aux (l
::acc
) ()
55 cat_aux [] () +> List.rev
+> (fun x
-> close_in
chan; x
)
61 List.map
(function fl
-> dir^
"/"^fl
)
62 (Array.to_list
(Sys.readdir dir
))
63 with Sys_error
_ -> [] in
64 List.iter
(function file
->
67 if List.exists
(fun s
->
68 s
= "* This file is part of Coccinelle."
70 s
= "# This file is part of Coccinelle."
72 then print_string
("already processed: " ^ file ^
"\n")
75 print_string
("processed: " ^ file ^
"\n");
78 print_string
("skipped: " ^ file ^
"\n");
81 (* pad: no recursive call in directory List.iter process files *)