|
@@ -53,21 +53,32 @@ let ignored =
|
|
|
|> String.split ~on:' '
|
|
|
|> List.filter_map ~f:(function
|
|
|
| "" | " " | " " | " " | " " -> None
|
|
|
- | path -> Some ("-e " ^ path ^ " "))
|
|
|
- |> String.concat
|
|
|
+ | path -> Some path)
|
|
|
;;
|
|
|
|
|
|
-(* List ml files, basic regexp, should be enough *)
|
|
|
-let list_mlfiles path =
|
|
|
- (* 1st grep: select ocaml files,
|
|
|
- * 2nd grep: remove symlinks and ignored files *)
|
|
|
- sprintf "tree -if %s | grep -e '.*\\.ml$' | grep -v -e '.* -> .*' %s"
|
|
|
- path ignored
|
|
|
- |> (fun cmd -> print_endline cmd; cmd)
|
|
|
- |> Unix.open_process_in
|
|
|
- |> In_channel.input_all
|
|
|
- |> String.split ~on:'\n'
|
|
|
- |> List.filter ~f:(function "" -> false | _ -> true)
|
|
|
+(* List ml files *)
|
|
|
+let list_mlfiles ?(follow_symlinks=true) path =
|
|
|
+ let is_dotml file =
|
|
|
+ String.split ~on:'.' file
|
|
|
+ |> List.last
|
|
|
+ |> function
|
|
|
+ | None -> false
|
|
|
+ | Some ext -> ext = "ml"
|
|
|
+ in
|
|
|
+ let is_ignored file =
|
|
|
+ List.find ignored (fun to_ignore -> to_ignore = file)
|
|
|
+ |> Option.is_some
|
|
|
+ in
|
|
|
+ let rec ls_rec s =
|
|
|
+ (* If follow_symlinks is set to false then any symlink seems do not to be a
|
|
|
+ * file *)
|
|
|
+ if Sys.is_file_exn ~follow_symlinks s
|
|
|
+ then [s]
|
|
|
+ else Sys.ls_dir s |> List.map ~f:(fun sub -> ls_rec (s ^/ sub))
|
|
|
+ |> List.concat
|
|
|
+ in
|
|
|
+ List.filter (ls_rec path)
|
|
|
+ ~f:(fun file -> not (is_ignored file) && is_dotml file)
|
|
|
;;
|
|
|
|
|
|
(* Call ocp-indent for indentation *)
|