Release coccinelle-0.2.5-rc1
[bpt/coccinelle.git] / tools / licensify.ml
1 (*
2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
7 *
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
11 *
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
22 *)
23
24
25 let lines =
26 ["Copyright 2010, INRIA, University of Copenhagen";
27 "Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix";
28 "Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen";
29 "Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix";
30 "This file is part of Coccinelle.";
31 "";
32 "Coccinelle is free software: you can redistribute it and/or modify";
33 "it under the terms of the GNU General Public License as published by";
34 "the Free Software Foundation, according to version 2 of the License.";
35 "";
36 "Coccinelle is distributed in the hope that it will be useful,";
37 "but WITHOUT ANY WARRANTY; without even the implied warranty of";
38 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the";
39 "GNU General Public License for more details.";
40 "";
41 "You should have received a copy of the GNU General Public License";
42 "along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.";
43 "";
44 "The authors reserve the right to distribute this or future versions of";
45 "Coccinelle under other licenses."
46 ]
47
48
49 let comment_lines =
50 List.map (function x -> if x <> "" then " * "^x else " *") lines
51
52 let cpp_lines = "/*" :: comment_lines @ [" */"]
53
54 let ml_lines = "(*" :: comment_lines @ [" *)"]
55
56 let make_lines = (List.map (function x -> if x <> "" then "# "^x else "#") lines)
57 let c_lines = (List.map (function x -> if x <> "" then "// "^x else "//") lines)
58
59 let do_one file =
60 let lines =
61 if Filename.check_suffix file ".cocci" then c_lines else
62 if Filename.check_suffix file ".mly" then cpp_lines else
63 if Filename.check_suffix file ".ml" then ml_lines else
64 if Filename.check_suffix file ".mli" then ml_lines else
65 if Filename.check_suffix file ".mll" then ml_lines else
66 if Filename.check_suffix file ".pl" then make_lines else
67 if Filename.basename file = "Makefile" then make_lines else
68 failwith (Printf.sprintf "unknown file type: %s" file) in
69 let _ = Sys.command (Printf.sprintf "cp %s /tmp/tmpfl" file) in
70 let o = open_out file in
71 List.iter (function l -> Printf.fprintf o "%s\n" l) lines;
72 Printf.fprintf o "\n";
73 Printf.fprintf o "\n";
74 close_out o;
75 let _ = Sys.command (Printf.sprintf "cat /tmp/tmpfl >> %s" file) in
76 ()
77
78 (* pad's modif *)
79 let (+>) o f = f o
80 let cat file =
81 let chan = open_in file in
82 let rec cat_aux acc () =
83 (* cant do input_line chan::aux() cos ocaml eval from right to left ! *)
84 let (b, l) = try (true, input_line chan) with End_of_file -> (false, "") in
85 if b
86 then cat_aux (l::acc) ()
87 else acc
88 in
89 cat_aux [] () +> List.rev +> (fun x -> close_in chan; x)
90
91
92 let rec process dir =
93 let files =
94 try
95 List.map (function fl -> dir^"/"^fl)
96 (Array.to_list(Sys.readdir dir))
97 with Sys_error _ -> [] in
98 List.iter (function file ->
99 try
100 let xs = cat file in
101 if List.exists (fun s ->
102 s = "* This file is part of Coccinelle."
103 ||
104 s = "# This file is part of Coccinelle."
105 ||
106 s = "// This file is part of Coccinelle."
107 ||
108 Str.string_match (Str.regexp_string "Copyright") s 0
109 ) xs
110 then print_string ("already processed: " ^ file ^ "\n")
111 else begin
112 do_one file;
113 print_string ("processed: " ^ file ^ "\n");
114 end
115 with _ ->
116 print_string ("skipped: " ^ file ^ "\n");
117 ()
118 ) files;
119 (* pad: no recursive call in directory List.iter process files *)
120 ()
121
122 let _ = process "."