12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788(******************************************************************************)(* OASIS: architecture for building OCaml libraries and applications *)(* *)(* Copyright (C) 2011-2016, Sylvain Le Gall *)(* Copyright (C) 2008-2011, OCamlCore SARL *)(* *)(* This library is free software; you can redistribute it and/or modify it *)(* under the terms of the GNU Lesser General Public License as published by *)(* the Free Software Foundation; either version 2.1 of the License, or (at *)(* your option) any later version, with the OCaml static compilation *)(* exception. *)(* *)(* This library 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. See the file COPYING for more *)(* details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this library; if not, write to the Free Software Foundation, *)(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *)(******************************************************************************)(** Handle 'pager' command
*)openBaseMessageopenOASISGettextopenOASISUtilsletpager_cmd=trySome(trySys.getenv"OASIS_PAGER"withNot_found->begintrySys.getenv"PAGER"withNot_found->OASISFileUtil.which~ctxt:!BaseContext.default"pager"end)withNot_found->Noneletopen_out()=letbuf=Buffer.create13inletfmt=Format.formatter_of_bufferbufin(buf,fmt),fmtletclose_out(buf,fmt)=let()=Format.pp_print_flushfmt()inmatchpager_cmdwith|Somecmd->beginletproc=Unix.open_process_outcmdinlet()=Buffer.output_bufferprocbufinmatchUnix.close_process_outprocwith|Unix.WEXITED0->()|Unix.WEXITEDn|Unix.WSIGNALEDn|Unix.WSTOPPEDn->failwithf(f_"Command %S exited with error code %d")cmdnend|None->beginwarning"%s""Environment variable OASIS_PAGER not set.";Buffer.output_bufferstdoutbufend