OSDN Git Service

Add .ocamlinit.
[happyabc/happyabc.git] / link / main.ml
1 open Base
2 open Swflib
3 open Swflib.SwfType
4
5 let input_bytes ch =
6   let xs =
7     ref [] in
8     try
9       while true do
10         xs := (input_byte ch)::!xs
11       done;
12       failwith "must not happen"
13     with _ ->
14       List.rev !xs
15
16 let read path =
17   if Filename.check_suffix path ".abc" then
18     [open_in_with path (Abc.read $ Swflib.BytesIn.of_channel)]
19   else if Filename.check_suffix path ".swf" then
20     (open_in_with path Swf.read).tags
21     +> filter_map (function `DoABC (_,_,abc) -> Some abc | _ -> None)
22   else
23     failwithf "unknow suffix: %s" path ()
24
25 let _ =
26   let paths,t =
27     CmdOpt.parse_argv () in
28   let abc =
29     HList.concat_map read paths
30     +> HList.fold_left1 Link.link
31     +> Compact.compact in
32   let swf =
33     Template.make t abc in
34     open_out_with t#output (fun ch -> Swf.write ch swf)