]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/otherlibs/dynlink/extract_crc.ml
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / otherlibs / dynlink / extract_crc.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                           Objective Caml                            *)
4 (*                                                                     *)
5 (*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         *)
6 (*                                                                     *)
7 (*  Copyright 1996 Institut National de Recherche en Informatique et   *)
8 (*  en Automatique.  All rights reserved.  This file is distributed    *)
9 (*  under the terms of the GNU Library General Public License, with    *)
10 (*  the special exception on linking described in file ../../LICENSE.  *)
11 (*                                                                     *)
12 (***********************************************************************)
13
14 (* $Id: extract_crc.ml 6195 2004-04-09 13:26:41Z xleroy $ *)
15
16 (* Print the digests of unit interfaces *)
17
18 let load_path = ref []
19 let first = ref true
20
21 let print_crc unit =
22   try
23     let crc = Dynlink.digest_interface unit (!load_path @ ["."]) in
24     if !first then first := false else print_string ";\n";
25     print_string "  \""; print_string (String.capitalize unit);
26     print_string "\",\n    \"";
27     for i = 0 to String.length crc - 1 do
28       Printf.printf "\\%03d" (Char.code crc.[i])
29     done;
30     print_string "\""
31   with exn ->
32     prerr_string "Error while reading the interface for ";
33     prerr_endline unit;
34     begin match exn with
35       Sys_error msg -> prerr_endline msg
36     | Dynlink.Error(Dynlink.File_not_found name) ->
37         prerr_string "Cannot find file "; prerr_endline name
38     | Dynlink.Error _ -> prerr_endline "Ill-formed .cmi file"
39     | _ -> raise exn
40     end;
41     exit 2
42
43 let usage = "Usage: extract_crc [-I <dir>] <files>"
44
45 let main () =
46   print_string "let crc_unit_list = [\n";
47   Arg.parse
48     ["-I", Arg.String(fun dir -> load_path := !load_path @ [dir]),
49            "<dir>  Add <dir> to the list of include directories"]
50     print_crc usage;
51   print_string "\n]\n"
52
53 let _ = main(); exit 0
54
55