permit multiline comments and strings in macros
[bpt/coccinelle.git] / extra / classic_patch.ml
1 open Common
2
3 type patch = patchitem list
4 and patchitem = File of filename * string (* header line *) * string list
5
6 let parse_patch filename =
7 let xs = Common.cat filename in
8 let xxs = Common.split_list_regexp "^diff" xs in
9 xxs +> List.map (fun (s, body) ->
10 if s =~ "^diff --git a/\\([^ ]*\\) b/\\([^ ]*\\)"
11 then begin
12 let (a,b) = matched2 s in
13 assert(a =$= b);
14 File (a, s, body)
15 end
16 else failwith ("wrong line in git diff:" ^ s)
17 )
18
19
20 let unparse_patch xs outfile =
21 Common.with_open_outfile outfile (fun (pr_no_nl, _chan) ->
22 let pr s = pr_no_nl (s ^ "\n") in
23
24 xs +> List.iter (function (File (file, header, body)) ->
25 pr header;
26 body +> List.iter pr;
27 )
28 )
29
30