Remove negative weight hack
[dormin.git] / index / index.ml
blob855e371122cd1e6e74f99e803c405ce6cba04037
1 let getindex path =
2 try
3 let ic = open_in_bin path in
4 let index = input_value ic in
5 close_in ic;
6 index
7 with _ ->
8 []
9 ;;
11 let main indexpath container =
12 let index = getindex indexpath in
13 let hash = Hashtbl.create 100 in
14 let rec loop () =
15 match try Some (input_line stdin) with End_of_file -> None with
16 | None -> ()
17 | Some line ->
18 let offset, size, path =
19 Scanf.sscanf line "%x %d %s"
20 (fun offset size path -> (offset, size, path))
22 let name = Filename.basename path in
23 if not (Hashtbl.mem hash name)
24 then
25 Hashtbl.add hash name (offset, size)
27 loop ()
29 loop ();
30 let oc = open_out_bin indexpath in
31 output_value oc ((container, hash) :: index);
32 close_out oc;
35 let _ = main Sys.argv.(1) Sys.argv.(2);;