1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798(**************************************************************************)(* *)(* Copyright (C) Johannes Kanig, Stephane Lescuyer *)(* Jean-Christophe Filliatre, Romain Bardou and Francois Bobot *)(* *)(* This software is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Library General Public *)(* License version 2.1, with the special exception on linking *)(* described in file LICENSE. *)(* *)(* This software is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)(* *)(**************************************************************************)openMlpostopenMlpost_desc_optionsletcall_cmd=Misc.call_cmdlet()=letuser_opts=Queue.create()inletuser_opt=("--",Arg.Rest(funs->Queue.addsuser_opts),"The option given to the program")inArg.parse(Arg.align(user_opt::spec))(fun_->raise(Arg.Bad"No anonymous option among the mlpost options, begin by -- for the \
user options"))"A program compiled with mlpost";(* Replace the mlpost argument by the user one *)fori=1toArray.lengthSys.argv-1doifQueue.is_emptyuser_optsthenSys.argv.(i)<-""elseSys.argv.(i)<-Queue.popuser_optsdone;(* And reset the current of Arg *)Arg.current:=0;letprelude=match!latex_filewith|None->None|Somef->lets=Metapost_tool.read_prelude_from_tex_filefinDefaults.set_preludes;Somesinletverbose=!verboseinDefaults.set_filename_prefix!filename_prefix;Defaults.set_required_files!required_files;Defaults.set_verbosityverbose;Defaults.set_t1disasm!t1disasm;letbn=Filename.concat(Sys.getcwd())(Filename.basenameSys.argv.(0))inletdo_at_exit()=if!dumpablethenMetapost.dumpable()elseif!cairothenifnot(!xpdf||!interactive)thenif!pngthenCairost.dump_png()elseif!svgthenCairost.dump_svg()elseif!pdfthenCairost.dump_pdf()elseCairost.dump_ps()elseCairost.dump_pdfs"_mlpost"else(if!mp&¬(!xpdf||!interactive)thenMetapost.dump_mp?preludebnelseif!png&¬(!xpdf||!interactive)thenMetapost.dump_png?prelude~verbose~clean:(not!dont_clean)bnelseif!mpsthenMps.dump()elseif!pgfthenPgf.dump()elseMetapost.dump?prelude~verbose~clean:(not!dont_clean)bn;if!xpdf||!interactivethen(Metapost.dump_tex?prelude"_mlpost";(trySys.remove"_mlpost.aux"with_->());ignore(call_cmd~verbose"pdflatex _mlpost.tex")));if!xpdfthenifcall_cmd~verbose"fuser _mlpost.pdf"=0thenignore(call_cmd~verbose"xpdf -remote mlpost -reload")elseignore(call_cmd~verbose"setsid xpdf -remote mlpost _mlpost.pdf &")in(* When an exit is fired inside do_at_exit
the function seems to be run again *)letdone_once=reffalseinat_exit(fun()->ifnot!done_oncethen(done_once:=true;do_at_exit()))