3 (* This script is a wrapper for ocamldoc.
5 This is a simple workaround for the defaults ocamldoc rules of
8 (* We assume that the command line arguments are given in the
11 ocamldoc [options] FILE.(ml|mli)
13 where FILE is either an implementation or an interface.
15 This script rewrites this command line into something of
18 ocamldoc [options] -intf FILE.mli -impl FILE.ml
20 provided that FILE.mli and FILE.ml exist (otherwise, one of these
21 two options is dropped out).
27 let nb = Array.length Sys.argv
28 let args = List.tl (Array.to_list Sys.argv)
29 let file = Filename.chop_extension (Sys.argv.(nb - 1))
30 let file_is = Filename.check_suffix Sys.argv.(nb - 1)
31 let impl = file ^ ".ml"
32 let opt what f = if Sys.file_exists f then what ^ " " ^ f else ""
36 | [] -> "ocamlfind ocamldoc"
38 if file_is ".ml" || file_is ".mli" then
39 let options = rev (tl (rev args)) in
40 Printf.sprintf "ocamlfind ocamldoc %s %s %s"
41 (opt "-impl" (file ^ ".ml"))
42 (opt "-intf" (file ^ ".mli"))
43 (String.concat " " options)
45 Printf.sprintf "ocamlfind ocamldoc %s"
46 (String.concat " " args)
49 exit (Sys.command cmd)