nicka-html / main.ml

open Ops
;

value in_dir = "in-html"
  and out_dir = "out-html"
;

value get_token =
(*
  Replacer_lexx.main_in_buffered
*)
  Replacer_lexx.main_in_bychar
;

value iter_over_fold fold (func : 'a -> unit) =
  fun collection ->
    fold (fun () item -> let () = func item in ()) () collection 
;

value iter_files_of_dir func dir = Array.iter func & Sys.readdir dir
;

value make_out_fn in_fn =
  Filename.concat out_dir in_fn
;

value replace ~cfrom ~cto =
  let lb = Lexing.from_channel cfrom in
  loop ()
  where rec loop () =
    match get_token lb with
    [ None -> ()
    | Some result ->
        ( output_string cto result
        ; loop ()
        )
    ]
;

value main () = iter_files_of_dir
  (fun in_fn ->
     Filew.with_file_in_bin
       (fun in_ch ->
          Filew.with_file_out_bin
            (fun out_ch ->
               ignore & replace ~cfrom:in_ch ~cto:out_ch
            )
            (make_out_fn in_fn)
       )
       (Filename.concat in_dir in_fn)
  )
  in_dir
;

value () =
  try main ()
  with [ e -> (output_string stderr (Printexc.to_string e); exit 2) ]
;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.