let with_outfile output_file fct arg =
let call close f =
((try fct f arg with | exn -> (close (); raise exn));
close ())
in
match output_file with
| None -> call (fun () -> ()) std_formatter
| Some s ->
let oc = open_out s in
let f = formatter_of_out_channel oc
in call (fun () -> close_out oc) f