+ in
+ let assert_file_exists path =
+ assert_ Sys.file_exists path (sprintf "File does not exist: %S" path)
+ in
+ let assert_file_is_dir path =
+ assert_ Sys.is_directory path (sprintf "File is not a directory: %S" path)
+ in
+ let input = ref Stdin in
+ let output = ref Stdout in
+ let ignore = ref None in
+ let sample = ref 256 in
+ let spec =
+ [ ( "-out"
+ , Arg.String (fun path ->
+ assert_file_exists path;
+ assert_file_is_dir path;
+ output := Directory path
+ )
+ , " Output to this directory instead of stdout."
+ )
+ ; ( "-ignore"
+ , Arg.String (fun regexp -> ignore := Some (Str.regexp regexp))
+ , " Ignore file paths which match this regexp pattern (see Str module)."
+ )
+ ; ( "-sample"
+ , Arg.Set_int sample
+ , (sprintf " Byte size of file samples to use. Default: %d" !sample)
+ )
+ ]
+ in
+ Arg.parse
+ (Arg.align spec)
+ (fun path ->
+ assert_file_exists path;
+ assert_file_is_dir path;
+ match !input with
+ | Stdin ->
+ input := Directories [path]
+ | Directories paths ->
+ input := Directories (path :: paths)
+ )
+ "";
+ assert_
+ (fun x -> x > 0)
+ !sample
+ (sprintf "Sample size cannot be negative: %d" !sample);
+ { input = !input
+ ; output = !output
+ ; ignore = !ignore
+ ; sample = !sample
+ }
+
+let () =
+ main (get_opt ())