Release coccinelle-0.2.4
[bpt/coccinelle.git] / tools / licensify.ml
CommitLineData
9bc82bae
C
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
c491d8ee
C
25(*
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
34e49164 49let lines =
90aeb998
C
50["Copyright 2010, INRIA, University of Copenhagen";
51"Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix";
52"Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen";
951c7801 53"Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix";
34e49164
C
54"This file is part of Coccinelle.";
55"";
56"Coccinelle is free software: you can redistribute it and/or modify";
57"it under the terms of the GNU General Public License as published by";
58"the Free Software Foundation, according to version 2 of the License.";
59"";
60"Coccinelle is distributed in the hope that it will be useful,";
61"but WITHOUT ANY WARRANTY; without even the implied warranty of";
62"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the";
63"GNU General Public License for more details.";
64"";
65"You should have received a copy of the GNU General Public License";
66"along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.";
67"";
68"The authors reserve the right to distribute this or future versions of";
69"Coccinelle under other licenses."
70]
71
34e49164 72
951c7801
C
73let comment_lines =
74 List.map (function x -> if x <> "" then " * "^x else " *") lines
75
76let cpp_lines = "/*" :: comment_lines @ [" */"]
34e49164 77
951c7801
C
78let ml_lines = "(*" :: comment_lines @ [" *)"]
79
80let make_lines = (List.map (function x -> if x <> "" then "# "^x else "#") lines)
81let c_lines = (List.map (function x -> if x <> "" then "// "^x else "//") lines)
34e49164
C
82
83let do_one file =
84 let lines =
951c7801
C
85 if Filename.check_suffix file ".cocci" then c_lines else
86 if Filename.check_suffix file ".mly" then cpp_lines else
87 if Filename.check_suffix file ".ml" then ml_lines else
88 if Filename.check_suffix file ".mli" then ml_lines else
89 if Filename.check_suffix file ".mll" then ml_lines else
90 if Filename.check_suffix file ".pl" then make_lines else
34e49164
C
91 if Filename.basename file = "Makefile" then make_lines else
92 failwith (Printf.sprintf "unknown file type: %s" file) in
93 let _ = Sys.command (Printf.sprintf "cp %s /tmp/tmpfl" file) in
94 let o = open_out file in
95 List.iter (function l -> Printf.fprintf o "%s\n" l) lines;
96 Printf.fprintf o "\n";
97 Printf.fprintf o "\n";
98 close_out o;
99 let _ = Sys.command (Printf.sprintf "cat /tmp/tmpfl >> %s" file) in
100 ()
101
102(* pad's modif *)
103let (+>) o f = f o
951c7801 104let cat file =
34e49164 105 let chan = open_in file in
951c7801 106 let rec cat_aux acc () =
34e49164
C
107 (* cant do input_line chan::aux() cos ocaml eval from right to left ! *)
108 let (b, l) = try (true, input_line chan) with End_of_file -> (false, "") in
951c7801 109 if b
34e49164 110 then cat_aux (l::acc) ()
951c7801 111 else acc
34e49164
C
112 in
113 cat_aux [] () +> List.rev +> (fun x -> close_in chan; x)
114
115
116let rec process dir =
117 let files =
118 try
119 List.map (function fl -> dir^"/"^fl)
120 (Array.to_list(Sys.readdir dir))
121 with Sys_error _ -> [] in
951c7801
C
122 List.iter (function file ->
123 try
124 let xs = cat file in
125 if List.exists (fun s ->
34e49164 126 s = "* This file is part of Coccinelle."
951c7801 127 ||
34e49164 128 s = "# This file is part of Coccinelle."
951c7801
C
129 ||
130 s = "// This file is part of Coccinelle."
131 ||
132 Str.string_match (Str.regexp_string "Copyright") s 0
133 ) xs
34e49164
C
134 then print_string ("already processed: " ^ file ^ "\n")
135 else begin
136 do_one file;
137 print_string ("processed: " ^ file ^ "\n");
138 end
951c7801 139 with _ ->
34e49164
C
140 print_string ("skipped: " ^ file ^ "\n");
141 ()
142 ) files;
143 (* pad: no recursive call in directory List.iter process files *)
144 ()
145
146let _ = process "."