4 let l = input_line i
in
5 if Str.string_match
(Str.regexp
"diff -u -p ") l 0
6 then (List.rev
!lines,Some
l)
7 else (lines := l::!lines; loop ()) in
8 try loop() with End_of_file
-> (List.rev
!lines,None
)
10 let get_file l = (* l is a diff line *)
11 match Str.split
(Str.regexp
" ") l with
12 [_diff
;_u
;_p
;old
;_new
] -> old
13 | _
-> failwith
"bad diff line"
15 let get_files prefix
=
16 let files = Array.to_list
(Sys.readdir
(Sys.getcwd
())) in
18 let rel_re = Str.regexp
"\\(.*\\)\\.[0-9]+\\.out" in
19 if Str.string_match
rel_re name
0 then
20 let pref = Str.matched_group
1 name
in
25 List.filter
relevant files
29 let elements = ref [] in
30 (match read_to_diff i with
31 (_
,Some first_line
) ->
33 let (cur
,more
) = read_to_diff i in
34 elements := (get_file diff
,diff
::cur
) :: !elements;
36 Some next_line
-> loop next_line
39 | _
-> ()); (* file is empty *)
43 let process_all_files files out
=
45 List.sort compare
(List.concat
(List.map
process_file files)) in
47 [] -> (* only python output *)
48 let fl = String.concat
" " (List.sort compare
files) in
49 let _ = Sys.command
(Printf.sprintf
"cat %s > %s" fl out
) in
52 let o = open_out out
in
56 (function x
-> Printf.fprintf
o "%s\n" x
)
61 let arg = List.hd
(List.tl
(Array.to_list
Sys.argv
)) in
62 Printf.printf
"arg %s\n" arg;
63 let arg = Filename.chop_extension
arg in
64 let files = get_files arg in
65 process_all_files files (arg^
".out");
68 (List.map
(function x
-> "tmp."^x
) (List.sort compare
files)) in
69 let _ = Sys.command
(Printf.sprintf
"cat %s > %s.tmp" tmp_files arg) in
72 let _ = Sys.command
(Printf.sprintf
"/bin/rm %s" file
) in
73 let _ = Sys.command
(Printf.sprintf
"/bin/rm tmp.%s" file
) in ())