Release coccinelle-0.1
[bpt/coccinelle.git] / tools / licensify.ml
CommitLineData
34e49164
C
1let lines =
2["Copyright 2005-2008, 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.";
5"";
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.";
9"";
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.";
14"";
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/>.";
17"";
18"The authors reserve the right to distribute this or future versions of";
19"Coccinelle under other licenses."
20]
21
22let c_lines = "/*" :: (List.map (function x -> "* "^x) lines) @ ["*/"]
23
24let ml_lines = "(*" :: (List.map (function x -> "* "^x) lines) @ ["*)"]
25
26let make_lines = (List.map (function x -> "# "^x) lines)
27
28let do_one file =
29 let 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";
40 close_out o;
41 let _ = Sys.command (Printf.sprintf "cat /tmp/tmpfl >> %s" file) in
42 ()
43
44(* pad's modif *)
45let (+>) o f = f o
46let cat file =
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
51 if b
52 then cat_aux (l::acc) ()
53 else acc
54 in
55 cat_aux [] () +> List.rev +> (fun x -> close_in chan; x)
56
57
58let rec process dir =
59 let files =
60 try
61 List.map (function fl -> dir^"/"^fl)
62 (Array.to_list(Sys.readdir dir))
63 with Sys_error _ -> [] in
64 List.iter (function file ->
65 try
66 let xs = cat file in
67 if List.exists (fun s ->
68 s = "* This file is part of Coccinelle."
69 ||
70 s = "# This file is part of Coccinelle."
71 ) xs
72 then print_string ("already processed: " ^ file ^ "\n")
73 else begin
74 do_one file;
75 print_string ("processed: " ^ file ^ "\n");
76 end
77 with _ ->
78 print_string ("skipped: " ^ file ^ "\n");
79 ()
80 ) files;
81 (* pad: no recursive call in directory List.iter process files *)
82 ()
83
84let _ = process "."