1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859(* This file is part of Markup.ml, released under the BSD 2-clause license. See
doc/LICENSE for details, or visit https://github.com/aantron/markup.ml. *)openMarkup__CommonmoduleKstream=Markup__Kstream(* Lwt.Infix not available for Lwt 2.4.6 (Ocaml 4.00). *)let(>>=)=Lwt.(>>=)letchannelc=letended=reffalsein(fun()->if!endedthenLwt.return_noneelseLwt_io.read_char_optc>>=function|Some_asv->Lwt.returnv|None->ended:=true;Lwt.return_none)|>Markup_lwt.streamletfile=letopen_filename=(fun()->Lwt_io.open_file~mode:Lwt_io.inputname)|>Markup_lwt.to_cpsinletcloseck=((fun()->Lwt_io.closec)|>Markup_lwt.to_cps)(fun_->k())(fun_->k())infunname->letclosed=reffalseinletclose_fn=ref(fun()->closed:=true;Lwt.return_unit)inletconstructorthrowk=open_filenamethrow(func->if!closedthenthrow(Lwt_io.Channel_closed"input")elsebeginclose_fn:=(fun()->Lwt_io.closec);lets=channelc|>Markup.kstreamin(funthrowek->Kstream.nexts(funexn->closec(fun()->throwexn))(fun()->closece)k)|>Kstream.make|>kend)inlets=Kstream.constructconstructor|>Markup.of_kstreaminletclose()=!close_fn()ins,closeletto_channelcs=s|>Markup_lwt.iter(Lwt_io.write_charc)letto_filenames=Lwt_io.with_file~mode:Lwt_io.outputname(func->to_channelcs)