2 * Copyright (c) 2017, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
14 files
: string * string;
24 let parse_options () =
25 let similarity = ref false in
26 let purpose = "Hhas differencing tool" in
28 Printf.sprintf
"%s\nUsage: %s file1 file2\n" purpose Sys.argv
.(0)
33 , " Only displays the similarity percentage on STDOUT"
36 let options = Arg.align ~limit
:25 options in
38 Arg.parse
options (fun file
-> files := file
::!files) usage;
42 ; similarity = !similarity
46 let parse_file program_parser filename
=
47 let channel = open_in filename
in (* TODO: error handling *)
49 let lexer = Lexing.from_channel
channel in
51 try program_parser
lexer
52 with Parsing.Parse_error
-> (
53 Printf.eprintf
"Parsing of file failed\n";
54 raise
Parsing.Parse_error
61 let program_parser = program
Hhas_lexer.read
in
62 let prog1 = parse_file program_parser (fst
options.files) in
63 let prog2 = parse_file program_parser (snd
options.files) in
64 let _ = Rhl.adata1_ref
:= Hhas_program.adata
prog1 in
65 let _ = Rhl.adata2_ref
:= Hhas_program.adata
prog2 in
67 let (d
,(s
,e
)) = program_comparer
.comparer
prog1 prog2 in
68 let similarity = (100.0 *. (1.0 -. float_of_int d
/. float_of_int
(s
+1))) in
70 then Printf.printf
"%.2f" similarity
72 "distance = %d\nsize = %d\nsimilarity =%.2f%%\nedits=\n%s" d s
similarity e
;
73 print_endline defaultstring
) (* make sure the colors are back to normal *)
75 (* command line driver *)
80 (* On windows, setting 'binary mode' avoids to output CRLF on
81 stdout. The 'text mode' would not hurt the user in general, but
82 it breaks the testsuite where the output is compared to the
83 expected one (i.e. in given file without CRLF). *)
84 set_binary_mode_out stdout
true;
85 let options = parse_options () in
86 Unix.handle_unix_error
run options