-let make_input_stream = function
- | Stdin ->
- In_channel.lines stdin
- | Directories paths ->
- let paths = StrSet.elements (StrSet.of_list paths) in
- Stream.concat (List.map paths ~f:Directory_tree.find_files)
+type opt =
+ { input : input
+ ; output : output
+ ; ignore : Str.regexp option
+ ; sample : int
+ }
+
+type count =
+ { considered : int ref
+ ; empty : int ref
+ ; ignored : int ref
+ ; unique_size : int ref
+ ; unique_sample : int ref
+ ; hashed : int ref
+ }
+
+let make_input_stream input ignore count =
+ let input =
+ match input with
+ | Stdin ->
+ File.lookup (In_channel.lines stdin)
+ | Directories paths ->
+ let paths = StrSet.elements (StrSet.of_list paths) in
+ Stream.concat (List.map paths ~f:File.find)
+ in
+ Stream.filter input ~f:(fun {File.path; size} ->
+ incr count.considered;
+ let empty = size = 0 in
+ let ignored =
+ match ignore with
+ | Some regexp when (Str.string_match regexp path 0) ->
+ true
+ | Some _ | None ->
+ false
+ in
+ if empty then incr count.empty;
+ if ignored then incr count.ignored;
+ (not empty) && (not ignored)
+ )