Skip to content

Instantly share code, notes, and snippets.

@jubnzv
Created November 2, 2021 08:34
Show Gist options
  • Save jubnzv/c2c8b2edd4d739a28f32107905235795 to your computer and use it in GitHub Desktop.
Save jubnzv/c2c8b2edd4d739a28f32107905235795 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ocaml
let startswith s1 s2 =
let len1 = String.length s1 and len2 = String.length s2 in
if len1 < len2 then false
else
let sub = String.sub s1 0 len2 in
String.equal sub s2
let check filepath =
let f = open_in filepath in
let rec loop () =
try
let next = input_line f in
if String.length next > 80 && startswith next "(*" then
Printf.printf "%s:\n '%s'\n" filepath next;
loop ()
with End_of_file ->
close_in f;
()
in loop ()
let endswith s1 s2 =
let len1 = String.length s1 and len2 = String.length s2 in
if len1 < len2 then false
else
let sub = String.sub s1 (len1 - len2) len2 in
String.equal sub s2
let rec walk = function
| f::fs when (Sys.file_exists f && Sys.is_directory f) -> begin
Sys.readdir f
|> Array.to_list
|> List.map (Filename.concat f)
|> List.iter
(fun fp -> begin
if Sys.is_directory fp then
walk [fp]
else if endswith fp ".ml" then
check fp
else ()
end)
end
| f::fs -> walk fs
| _ -> ()
let () =
walk ["./src/content/"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment