3a86a6c7091246253698f4df0a4b5e8371a7b64d
[bpt/coccinelle.git] / tools / licensify.ml
1 let lines =
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 comment_lines =
26 List.map (function x -> if x <> "" then " * "^x else " *") lines
27
28 let cpp_lines = "/*" :: comment_lines @ [" */"]
29
30 let ml_lines = "(*" :: comment_lines @ [" *)"]
31
32 let make_lines = (List.map (function x -> if x <> "" then "# "^x else "#") lines)
33 let c_lines = (List.map (function x -> if x <> "" then "// "^x else "//") lines)
34
35 let do_one file =
36 let lines =
37 if Filename.check_suffix file ".cocci" then c_lines else
38 if Filename.check_suffix file ".mly" then cpp_lines else
39 if Filename.check_suffix file ".ml" then ml_lines else
40 if Filename.check_suffix file ".mli" then ml_lines else
41 if Filename.check_suffix file ".mll" then ml_lines else
42 if Filename.check_suffix file ".pl" then make_lines else
43 if Filename.basename file = "Makefile" then make_lines else
44 failwith (Printf.sprintf "unknown file type: %s" file) in
45 let _ = Sys.command (Printf.sprintf "cp %s /tmp/tmpfl" file) in
46 let o = open_out file in
47 List.iter (function l -> Printf.fprintf o "%s\n" l) lines;
48 Printf.fprintf o "\n";
49 Printf.fprintf o "\n";
50 close_out o;
51 let _ = Sys.command (Printf.sprintf "cat /tmp/tmpfl >> %s" file) in
52 ()
53
54 (* pad's modif *)
55 let (+>) o f = f o
56 let cat file =
57 let chan = open_in file in
58 let rec cat_aux acc () =
59 (* cant do input_line chan::aux() cos ocaml eval from right to left ! *)
60 let (b, l) = try (true, input_line chan) with End_of_file -> (false, "") in
61 if b
62 then cat_aux (l::acc) ()
63 else acc
64 in
65 cat_aux [] () +> List.rev +> (fun x -> close_in chan; x)
66
67
68 let rec process dir =
69 let files =
70 try
71 List.map (function fl -> dir^"/"^fl)
72 (Array.to_list(Sys.readdir dir))
73 with Sys_error _ -> [] in
74 List.iter (function file ->
75 try
76 let xs = cat file in
77 if List.exists (fun s ->
78 s = "* This file is part of Coccinelle."
79 ||
80 s = "# This file is part of Coccinelle."
81 ||
82 s = "// This file is part of Coccinelle."
83 ||
84 Str.string_match (Str.regexp_string "Copyright") s 0
85 ) xs
86 then print_string ("already processed: " ^ file ^ "\n")
87 else begin
88 do_one file;
89 print_string ("processed: " ^ file ^ "\n");
90 end
91 with _ ->
92 print_string ("skipped: " ^ file ^ "\n");
93 ()
94 ) files;
95 (* pad: no recursive call in directory List.iter process files *)
96 ()
97
98 let _ = process "."