1structure holdeptool =
2struct
3
4fun die () = OS.Process.exit OS.Process.failure
5fun ok () = OS.Process.exit OS.Process.success
6fun warn s = TextIO.output(TextIO.stdErr, s ^ "\n")
7fun usage k =
8    (warn ("Usage:\n  " ^ CommandLine.name() ^ " [-h | [file]]");
9     k())
10fun diewith s = (warn s; die())
11
12fun main() = let
13  open Holdep_tokens
14  val stdin = (TextIO.stdIn, "<stdin>", (fn () => ()))
15  fun file f = let
16    val strm = TextIO.openIn f
17  in
18    (strm, f, (fn () => TextIO.closeIn strm))
19  end
20  val results =
21      case CommandLine.arguments() of
22          [] => (stream_deps ("<stdin>", TextIO.stdIn)
23                 handle LEX_ERROR s => diewith("Lexical error: " ^ s)
24                      | e => diewith ("Exception: "^General.exnMessage e))
25        | ["-h"] => usage ok
26        | [fname] => (reader_deps (fname, #read (QFRead.fileToReader fname))
27                      handle LEX_ERROR s => diewith("Lexical error: " ^ s)
28                           | e => diewith ("Exception: "^General.exnMessage e))
29        | _ => usage die
30
31in
32  Binarymap.app (fn (s,_) => print (s ^ "\n")) results
33end
34
35end (* struct *)
36