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