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